Best NBi code snippet using NBi.Core.ResultSet.ResultSet
TransformationProviderTest.cs
Source:TransformationProviderTest.cs
1using Moq;2using NBi.Core.Injection;3using NBi.Core.ResultSet;4using NBi.Core.Transformation;5using NBi.Core.Transformation.Transformer.Native;6using NBi.Core.Variable;7using NUnit.Framework;8using System;9using System.Collections.Generic;10using System.Linq;11using System.Text;12using System.Threading.Tasks;13namespace NBi.Testing.Core.Transformation14{15 [TestFixture]16 public class TransformationProviderTest17 {18 [Test]19 public void Transform_SimpleTranformation_CorrectHandlingOfColumnNames()20 {21 var resultSet = new NBi.Core.ResultSet.ResultSet();22 resultSet.Load("aaaa;10");23 resultSet.Columns[0].ColumnName = "MyCol0";24 resultSet.Columns[1].ColumnName = "MyCol1";25 var transformation = Mock.Of<ITransformationInfo>26 (27 t => t.Language == LanguageType.CSharp28 && t.OriginalType == ColumnType.Text29 && t.Code == "value.Substring(0,1)"30 );31 var provider = new TransformationProvider(new ServiceLocator(), Context.None);32 provider.Add(new ColumnOrdinalIdentifier(0), transformation);33 provider.Transform(resultSet);34 Assert.That(resultSet.Columns[0].ColumnName, Is.EqualTo("MyCol0"));35 Assert.That(resultSet.Columns[1].ColumnName, Is.EqualTo("MyCol1"));36 Assert.That(resultSet.Columns.Count, Is.EqualTo(2));37 }38 [Test]39 public void Transform_SimpleTranformation_Correct()40 {41 var resultSet = new NBi.Core.ResultSet.ResultSet();42 resultSet.Load("aaaa;10");43 var transformation = Mock.Of<ITransformationInfo>44 (45 t => t.Language == LanguageType.CSharp46 && t.OriginalType == ColumnType.Text47 && t.Code == "value.Substring(0,1)"48 );49 var provider = new TransformationProvider(new ServiceLocator(), Context.None);50 provider.Add(new ColumnOrdinalIdentifier(0), transformation);51 provider.Transform(resultSet);52 Assert.That(resultSet.Rows[0][0], Is.EqualTo("a"));53 }54 [Test]55 public void Transform_NativeTranformationTrim_Correct()56 {57 var resultSet = new NBi.Core.ResultSet.ResultSet();58 resultSet.Load(" aaaa ;10");59 var transformation = Mock.Of<ITransformationInfo>60 (61 t => t.Language == LanguageType.Native62 && t.OriginalType == ColumnType.Text63 && t.Code == "text-to-trim"64 );65 var provider = new TransformationProvider(new ServiceLocator(), Context.None);66 provider.Add(new ColumnOrdinalIdentifier(0), transformation);67 provider.Transform(resultSet);68 Assert.That(resultSet.Rows[0][0], Is.EqualTo("aaaa"));69 }70 [Test]71 public void Transform_NativeTranformationFirstCharWithContext_Correct()72 {73 var resultSet = new NBi.Core.ResultSet.ResultSet();74 resultSet.Load(new[] { new object[] { "123456789", 6 }, new object[] { "abcdefgh", 2 } });75 var transformation = Mock.Of<ITransformationInfo>76 (77 t => t.Language == LanguageType.Native78 && t.OriginalType == ColumnType.Text79 && t.Code == "text-to-first-chars(#1)"80 );81 var provider = new TransformationProvider(new ServiceLocator(), Context.None);82 provider.Add(new ColumnOrdinalIdentifier(0), transformation);83 provider.Transform(resultSet);84 Assert.That(resultSet.Rows[0][0], Is.EqualTo("123456"));85 Assert.That(resultSet.Rows[1][0], Is.EqualTo("ab"));86 }87 [Test]88 public void Transform_NativeTranformationBlankToNull_Correct()89 {90 var resultSet = new NBi.Core.ResultSet.ResultSet();91 resultSet.Load("\t;10");92 var transformation = Mock.Of<ITransformationInfo>93 (94 t => t.Language == LanguageType.Native95 && t.OriginalType == ColumnType.Text96 && t.Code == "blank-to-null"97 );98 var provider = new TransformationProvider(new ServiceLocator(), Context.None);99 provider.Add(new ColumnOrdinalIdentifier(0), transformation);100 provider.Transform(resultSet);101 Assert.That(resultSet.Rows[0][0], Is.EqualTo("(null)"));102 }103 [Test]104 public void Transform_NativeTranformationUnknown_Exception()105 {106 var resultSet = new NBi.Core.ResultSet.ResultSet();107 resultSet.Load("\t;10");108 var transformation = Mock.Of<ITransformationInfo>109 (110 t => t.Language == LanguageType.Native111 && t.OriginalType == ColumnType.Text112 && t.Code == "unknown"113 );114 var provider = new TransformationProvider(new ServiceLocator(), null);115 Assert.Throws<NotImplementedTransformationException>(() => provider.Add(new ColumnOrdinalIdentifier(0), transformation));116 }117 [Test]118 public void Transform_TypeSwitch_Correct()119 {120 var resultSet = new NBi.Core.ResultSet.ResultSet();121 var obj = new object[] { new DateTime(2016,10,1) };122 resultSet.Load(Enumerable.Repeat(obj,1));123 var transformation = Mock.Of<ITransformationInfo>124 (125 t => t.Language == LanguageType.CSharp126 && t.OriginalType == ColumnType.DateTime127 && t.Code == "value.Month + (value.Year-2000)*12"128 );129 var provider = new TransformationProvider(new ServiceLocator(), Context.None);130 provider.Add(new ColumnOrdinalIdentifier(0), transformation);131 provider.Transform(resultSet);132 Assert.That(resultSet.Rows[0][0], Is.EqualTo(202));133 }134 }...
EqualToXml.cs
Source:EqualToXml.cs
...3using System.Data;4using System.Linq;5using System.Xml.Serialization;6using NBi.Core;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Comparer;9using NBi.Xml.Items;10using NBi.Xml.Items.ResultSet;11using NBi.Xml.Settings;1213namespace NBi.Xml.Constraints14{15 public class EqualToXml : AbstractConstraintXml16 {1718 public EqualToXml()19 {20 parallelizeQueries = false;21 }2223 internal EqualToXml(bool parallelizeQueries)24 {25 this.parallelizeQueries = parallelizeQueries;26 }2728 internal EqualToXml(SettingsXml settings)29 {30 this.Settings = settings;31 }3233 public override DefaultXml Default34 {35 get {return base.Default;} 36 set37 {38 base.Default = value;39 if (Query!=null)40 Query.Default=value;41 }42 }4344 [XmlElement("resultSet")]45 public ResultSetXml ResultSet { get; set; }4647 [XmlElement("query")]48 public QueryXml Query { get; set; }4950 public override BaseItem BaseItem51 {52 get53 {54 if (Query != null)55 return Query;56 if (ResultSet != null)57 return ResultSet;5859 return null;60 }61 }6263 [XmlAttribute("keys")]64 [DefaultValue(ResultSetComparisonSettings.KeysChoice.First)]65 public ResultSetComparisonSettings.KeysChoice KeysDef { get; set; }6667 [XmlAttribute("values")]68 [DefaultValue(ResultSetComparisonSettings.ValuesChoice.AllExpectFirst)]69 public ResultSetComparisonSettings.ValuesChoice ValuesDef { get; set; }7071 protected bool isToleranceSpecified;72 [XmlIgnore()]73 public bool IsToleranceSpecified74 {75 get { return isToleranceSpecified; }76 protected set { isToleranceSpecified = value; }77 }7879 protected string tolerance;80 [XmlAttribute("tolerance")]81 [DefaultValue("")]82 public string Tolerance83 {84 get85 { return tolerance; }8687 set88 {89 tolerance = value;90 isToleranceSpecified = true;91 }92 }9394 [XmlElement("column")]95 public List<NBi.Xml.Items.ResultSet.ColumnDefinitionXml> columnsDef;9697 public IList<IColumnDefinition> ColumnsDef98 {99 get100 {101 if (columnsDef == null)102 columnsDef = new List<NBi.Xml.Items.ResultSet.ColumnDefinitionXml>();103 return columnsDef.Cast<IColumnDefinition>().ToList();104 }105 }106107 [XmlAttribute("persistance")]108 [DefaultValue(PersistanceChoice.Never)]109 public PersistanceChoice Persistance;110111 public ResultSetComparisonSettings GetSettings()112 {113 return new ResultSetComparisonSettings(KeysDef, ValuesDef, ToleranceFactory.BuildNumeric(Tolerance), ColumnsDef);114 }115116 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]117 public virtual IDbCommand GetCommand()118 {119 if (Query==null)120 return null;121122 var conn = new ConnectionFactory().Get(Query.GetConnectionString());123 var cmd = conn.CreateCommand();124 cmd.CommandText = Query.GetQuery();125 126127 return cmd;
...
ExecutionEqualToBuilder.cs
Source:ExecutionEqualToBuilder.cs
...3using System.Diagnostics;4using System.Linq;5using NBi.Core;6using NBi.Core.Query;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Comparer;9using NBi.NUnit.Query;10using NBi.Xml.Constraints;11using NBi.Xml.Items;12using NBi.Xml.Systems;1314namespace NBi.NUnit.Builder15{16 class ExecutionEqualToBuilder : AbstractExecutionBuilder17 {18 protected EqualToXml ConstraintXml {get; set;}1920 public ExecutionEqualToBuilder()21 {2223 }2425 protected override void SpecificSetup(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml)26 {27 if (!(ctrXml is EqualToXml))28 throw new ArgumentException("Constraint must be a 'EqualToXml'");2930 ConstraintXml = (EqualToXml)ctrXml;31 }3233 protected override void SpecificBuild()34 {35 Constraint = InstantiateConstraint();36 }3738 protected global::NUnit.Framework.Constraints.Constraint InstantiateConstraint()39 {40 EqualToConstraint ctr = null;41 42 if (ConstraintXml.GetCommand() != null)43 {44 var commandText = ConstraintXml.GetCommand().CommandText;45 var connectionString = ConstraintXml.GetCommand().Connection.ConnectionString;46 IEnumerable<IQueryParameter> parameters = null;47 IEnumerable<IQueryTemplateVariable> variables = null;48 if (ConstraintXml.Query != null)49 {50 parameters = ConstraintXml.Query.GetParameters();51 variables = ConstraintXml.Query.GetVariables();52 }5354 var commandBuilder = new CommandBuilder();55 var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables);56 ctr = new EqualToConstraint(cmd);57 }58 else if (ConstraintXml.ResultSet != null)59 {60 if (!string.IsNullOrEmpty(ConstraintXml.ResultSet.File))61 {62 Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in external file!");63 ctr = new EqualToConstraint(ConstraintXml.ResultSet.GetFile());64 }65 else if (ConstraintXml.ResultSet.Rows!=null)66 {67 Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in embedded resultSet!");68 ctr = new EqualToConstraint(ConstraintXml.ResultSet.Rows);69 }70 }71 72 if (ctr==null)73 throw new ArgumentException();7475 //Manage settings for comparaison76 ResultSetComparisonSettings settings = new ResultSetComparisonSettings(77 ConstraintXml.KeysDef,78 ConstraintXml.ValuesDef,79 ToleranceFactory.BuildNumeric(ConstraintXml.Tolerance),80 ConstraintXml.ColumnsDef81 );8283 ctr.Using(settings);8485 if (ConstraintXml.ParallelizeQueries)86 ctr = ctr.Parallel();87 else88 ctr = ctr.Sequential();8990 //Manage persistance
...
ResultSet
Using AI Code Generation
1using NBi.Core.ResultSet;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 ResultSet rs = new ResultSet();12 rs.Load("C:\\temp\\resultset.csv");13 Console.WriteLine(rs.Rows[0].Columns[0].Value);14 Console.ReadKey();15 }16 }17}
ResultSet
Using AI Code Generation
1using NBi.Core.ResultSet;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 var rs1 = new ResultSet();12 rs1.Load(@"C:\Users\mike\Desktop\rs1.csv", true, ';');13 var rs2 = new ResultSet();14 rs2.Load(@"C:\Users\mike\Desktop\rs2.csv", true, ';');15 var rs3 = new ResultSet();16 rs3.Load(@"C:\Users\mike\Desktop\rs3.csv", true, ';');17 var rs4 = new ResultSet();18 rs4.Load(@"C:\Users\mike\Desktop\rs4.csv", true, ';');19 var rs5 = new ResultSet();20 rs5.Load(@"C:\Users\mike\Desktop\rs5.csv", true, ';');21 var rs6 = new ResultSet();22 rs6.Load(@"C:\Users\mike\Desktop\rs6.csv", true, ';');23 var rs7 = new ResultSet();24 rs7.Load(@"C:\Users\mike\Desktop\rs7.csv", true, ';');25 var engine = new NBi.Core.ResultSet.ResultSetEngine();26 var result = engine.Compare(rs1, rs2, NBi.Core.ResultSet.ComparerResultSet.EqualityComparer);27 Console.WriteLine(result.Success);28 Console.WriteLine(result.Message);29 Console.ReadLine();30 }31 }32}33using NBi.Core.ResultSet;34using System;35using System.Collections.Generic;36using System.Linq;37using System.Text;38using System.Threading.Tasks;39{40 {41 static void Main(string[] args)42 {43 var rs1 = new ResultSet();44 rs1.Load(@"C:\Users\mike\Desktop\rs1.csv", true, ';');45 var rs2 = new ResultSet();46 rs2.Load(@"C:\Users\mike\Desktop\rs2.csv", true, ';');47 var rs3 = new ResultSet();48 rs3.Load(@"C:\Users\mike\Desktop\rs3.csv", true, ';');49 var rs4 = new ResultSet();50 rs4.Load(@"C:\Users\mike\Desktop\rs4.csv", true, ';
ResultSet
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet;7using NBi.Core.ResultSet.Comparer;8{9 {10 static void Main(string[] args)11 {12 var rs1 = new ResultSet();13 rs1.Columns.Add(new Column("Col1", ColumnType.Numeric));14 rs1.Columns.Add(new Column("Col2", ColumnType.Text));15 rs1.Rows.Add(new Row(new object[] { 1, "a" }));16 rs1.Rows.Add(new Row(new object[] { 2, "b" }));17 rs1.Rows.Add(new Row(new object[] { 3, "c" }));18 rs1.Rows.Add(new Row(new object[] { 4, "d" }));19 var rs2 = new ResultSet();20 rs2.Columns.Add(new Column("Col1", ColumnType.Numeric));21 rs2.Columns.Add(new Column("Col2", ColumnType.Text));22 rs2.Rows.Add(new Row(new object[] { 1, "a" }));23 rs2.Rows.Add(new Row(new object[] { 2, "b" }));24 rs2.Rows.Add(new Row(new object[] { 3, "c" }));25 rs2.Rows.Add(new Row(new object[] { 4, "d" }));26 var comparer = new ResultSetComparer();27 var result = comparer.Compare(rs1, rs2);28 foreach (var row in result)29 {30 Console.WriteLine(row);31 }32 }33 }34}35{36}37{38}39{40}41{
ResultSet
Using AI Code Generation
1using NBi.Core.ResultSet;2using NBi.Core.ResultSet.Comparer;3using NBi.Core.ResultSet.Equivalence;4using NBi.Core.Calculation.Predicate;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 static void Main(string[] args)13 {14 ResultSet rs = new ResultSet();15 rs.Columns.Add(new ColumnDefinition("Id", "Int32"));16 rs.Columns.Add(new ColumnDefinition("Name", "String"));17 rs.Columns.Add(new ColumnDefinition("Age", "Int32"));18 rs.Rows.Add(new Row(new object[] { 1, "John", 30 }));19 rs.Rows.Add(new Row(new object[] { 2, "Peter", 25 }));20 rs.Rows.Add(new Row(new object[] { 3, "Mary", 28 }));21 rs.Rows.Add(new Row(new object[] { 4, "Paul", 25 }));22 rs.Rows.Add(new Row(new object[] { 5, "John", 30 }));23 rs.Rows.Add(new Row(new object[] { 6, "John", 30 }));24 rs.Rows.Add(new Row(new object[] { 7, "John", 30 }));25 rs.Rows.Add(new Row(new object[] { 8, "John", 30 }));26 rs.Rows.Add(new Row(new object[] { 9, "John", 30 }));27 rs.Rows.Add(new Row(new object[] { 10, "John", 30 }));28 rs.Rows.Add(new Row(new object[] { 11, "John", 30 }));29 rs.Rows.Add(new Row(new object[] { 12, "John", 30 }));30 rs.Rows.Add(new Row(new object[] { 13, "John", 30 }));31 rs.Rows.Add(new Row(new object[] { 14, "John", 30 }));32 rs.Rows.Add(new Row(new object[] { 15, "John", 30 }));33 rs.Rows.Add(new Row(new object[] { 16, "John", 30 }));34 rs.Rows.Add(new Row(new object[] { 17, "John", 30 }));35 rs.Rows.Add(new Row(new object[] { 18, "John", 30 }));36 rs.Rows.Add(new Row(new object[]
ResultSet
Using AI Code Generation
1using NBi.Core.ResultSet;2using System;3{4 public static void Main()5 {6 var rs = new ResultSet();7 rs.LoadFromFile("C:\\temp\\result.txt");8 rs.SaveToFile("C:\\temp\\result.xml");9 }10}11using NBi.Core.ResultSet;12using System;13{14 public static void Main()15 {16 var rs = new ResultSet();17 rs.LoadFromFile("C:\\temp\\result.xml");18 rs.SaveToFile("C:\\temp\\result.txt");19 }20}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!