Best NBi code snippet using NBi.Core.ResultSet.Resolver.ObjectsResultSetResolver
LookupReplaceEngineTest.cs
Source:LookupReplaceEngineTest.cs
...18 {19 [Test]20 public void Execute_AllLookupFound_CorrectReplacement()21 {22 var candidate = new ObjectsResultSetResolver(23 new ObjectsResultSetResolverArgs(24 new[] {25 new object[] { 1, "A", 100 },26 new object[] { 2, "B", 101 },27 new object[] { 3, "A", 125 },28 new object[] { 4, "B", 155 }29 }30 )).Execute();31 var reference = new ResultSetService(32 new ObjectsResultSetResolver(33 new ObjectsResultSetResolverArgs(34 new[] {35 new object[] { "A", "alpha" },36 new object[] { "B", "beta" },37 }38 )).Execute, null);39 var engine = new LookupReplaceEngine(40 new LookupReplaceArgs( 41 reference, 42 new ColumnMapping(new ColumnOrdinalIdentifier(1), new ColumnOrdinalIdentifier(0), ColumnType.Text),43 new ColumnOrdinalIdentifier(1)44 ));45 var result = engine.Execute(candidate);46 Assert.That(result.Columns.Count, Is.EqualTo(3));47 Assert.That(result.Rows.Count, Is.EqualTo(4));48 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("alpha"));49 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("beta"));50 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1] as string).Where(x => x != "alpha" && x != "beta"), Is.Empty); 51 }52 [Test]53 public void Execute_AllLookupFoundSwitchingFromTextToNumeric_CorrectReplacement()54 {55 var candidate = new ObjectsResultSetResolver(56 new ObjectsResultSetResolverArgs(57 new[] {58 new object[] { 1, "A", 100 },59 new object[] { 2, "B", 101 },60 new object[] { 3, "A", 125 },61 new object[] { 4, "B", 155 }62 }63 )).Execute();64 var reference = new ResultSetService(65 new ObjectsResultSetResolver(66 new ObjectsResultSetResolverArgs(67 new[] {68 new object[] { "A", 10.2 },69 new object[] { "B", 21.1 },70 }71 )).Execute, null);72 var engine = new LookupReplaceEngine(73 new LookupReplaceArgs(74 reference,75 new ColumnMapping(new ColumnOrdinalIdentifier(1), new ColumnOrdinalIdentifier(0), ColumnType.Text),76 new ColumnOrdinalIdentifier(1)77 ));78 var result = engine.Execute(candidate);79 Assert.That(result.Columns.Count, Is.EqualTo(3));80 Assert.That(result.Rows.Count, Is.EqualTo(4));81 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain(10.2));82 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain(21.1));83 Assert.That(result.Rows.Cast<DataRow>().Select(x => Convert.ToDecimal(x[1])).Where(x => x != 10.2m && x != 21.1m), Is.Empty);84 }85 [Test]86 public void ExecuteWithFailureStretegy_OneLookupMissing_ExceptionThrown()87 {88 var candidate = new ObjectsResultSetResolver(89 new ObjectsResultSetResolverArgs(90 new[] {91 new object[] { 1, "A", 100 },92 new object[] { 2, "B", 101 },93 new object[] { 3, "A", 125 },94 new object[] { 4, "C", 155 }95 }96 )).Execute();97 var reference = new ResultSetService(98 new ObjectsResultSetResolver(99 new ObjectsResultSetResolverArgs(100 new[] {101 new object[] { "A", "alpha" },102 new object[] { "B", "beta" },103 }104 )).Execute, null);105 var engine = new LookupReplaceEngine(106 new LookupReplaceArgs(107 reference,108 new ColumnMapping(new ColumnOrdinalIdentifier(1), new ColumnOrdinalIdentifier(0), ColumnType.Text),109 new ColumnOrdinalIdentifier(1),110 new FailureMissingStrategy()111 ));112 var ex = Assert.Throws<NBiException>(() => engine.Execute(candidate));113 Assert.That(ex.Message, Does.Contain("'C'"));114 }115 [Test]116 public void ExecuteWithDefaultValueStrategy_OneLookupMissing_DefaultValueApplied()117 {118 var candidate = new ObjectsResultSetResolver(119 new ObjectsResultSetResolverArgs(120 new[] {121 new object[] { 1, "A", 100 },122 new object[] { 2, "B", 101 },123 new object[] { 3, "A", 125 },124 new object[] { 4, "C", 155 }125 }126 )).Execute();127 var reference = new ResultSetService(128 new ObjectsResultSetResolver(129 new ObjectsResultSetResolverArgs(130 new[] {131 new object[] { "A", "alpha" },132 new object[] { "B", "beta" },133 }134 )).Execute, null);135 var engine = new LookupReplaceEngine(136 new LookupReplaceArgs(137 reference,138 new ColumnMapping(new ColumnOrdinalIdentifier(1), new ColumnOrdinalIdentifier(0), ColumnType.Text),139 new ColumnOrdinalIdentifier(1),140 new DefaultValueMissingStrategy("omega")141 ));142 var result = engine.Execute(candidate);143 Assert.That(result.Rows.Count, Is.EqualTo(4));144 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("alpha"));145 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("beta"));146 var otherValues = result.Rows.Cast<DataRow>().Select(x => x[1] as string).Where(x => x != "alpha" && x != "beta");147 Assert.That(otherValues, Is.Not.Empty);148 Assert.That(otherValues, Does.Contain("omega"));149 }150 [Test]151 public void ExecuteWithOriginalValueStrategy_OneLookupMissing_OriginalValueApplied()152 {153 var candidate = new ObjectsResultSetResolver(154 new ObjectsResultSetResolverArgs(155 new[] {156 new object[] { 1, "A", 100 },157 new object[] { 2, "B", 101 },158 new object[] { 3, "A", 125 },159 new object[] { 4, "C", 155 }160 }161 )).Execute();162 var reference = new ResultSetService(163 new ObjectsResultSetResolver(164 new ObjectsResultSetResolverArgs(165 new[] {166 new object[] { "A", "alpha" },167 new object[] { "B", "beta" },168 }169 )).Execute, null);170 var engine = new LookupReplaceEngine(171 new LookupReplaceArgs(172 reference,173 new ColumnMapping(new ColumnOrdinalIdentifier(1), new ColumnOrdinalIdentifier(0), ColumnType.Text),174 new ColumnOrdinalIdentifier(1),175 new OriginalValueMissingStrategy()176 ));177 var result = engine.Execute(candidate);178 Assert.That(result.Rows.Count, Is.EqualTo(4));179 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("alpha"));180 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("beta"));181 var otherValues = result.Rows.Cast<DataRow>().Select(x => x[1] as string).Where(x => x != "alpha" && x != "beta");182 Assert.That(otherValues, Is.Not.Empty);183 Assert.That(otherValues, Does.Contain("C"));184 }185 [Test]186 public void ExecuteWithDiscardRowStrategy_OneLookupMissing_LessRowsReturned()187 {188 var candidate = new ObjectsResultSetResolver(189 new ObjectsResultSetResolverArgs(190 new[] {191 new object[] { 1, "A", 100 },192 new object[] { 2, "B", 101 },193 new object[] { 3, "A", 125 },194 new object[] { 4, "C", 155 }195 }196 )).Execute();197 var reference = new ResultSetService(198 new ObjectsResultSetResolver(199 new ObjectsResultSetResolverArgs(200 new[] {201 new object[] { "A", "alpha" },202 new object[] { "B", "beta" },203 }204 )).Execute, null);205 var engine = new LookupReplaceEngine(206 new LookupReplaceArgs(207 reference,208 new ColumnMapping(new ColumnOrdinalIdentifier(1), new ColumnOrdinalIdentifier(0), ColumnType.Text),209 new ColumnOrdinalIdentifier(1),210 new DiscardRowMissingStrategy()211 ));212 var result = engine.Execute(candidate);213 Assert.That(result.Rows.Count, Is.EqualTo(3));...
NCalcExtendEngineTest.cs
Source:NCalcExtendEngineTest.cs
...19 {20 [Test]21 public void Execute_StandardRsColumnOrdinal_CorrectExtension()22 {23 var args = new ObjectsResultSetResolverArgs(new[] { new object[] { "Alpha", 1, 2 }, new object[] { "Beta", 3, 2 }, new object[] { "Gamma", 5, 7 } });24 var resolver = new ObjectsResultSetResolver(args);25 var rs = resolver.Execute();26 var extender = new NCalcExtendEngine(27 new ServiceLocator(),28 new Context(null),29 new ColumnOrdinalIdentifier(3),30 "[#1] * [#2]"31 );32 var newRs = extender.Execute(rs);33 Assert.That(newRs.Columns.Count, Is.EqualTo(4));34 Assert.That(newRs.Rows[0][3], Is.EqualTo(2));35 Assert.That(newRs.Rows[1][3], Is.EqualTo(6));36 Assert.That(newRs.Rows[2][3], Is.EqualTo(35));37 }38 [Test]39 public void Execute_StandardRsColumnName_CorrectExtension()40 {41 var args = new ObjectsResultSetResolverArgs(new[] { new object[] { "Alpha", 1, 2 }, new object[] { "Beta", 3, 2 }, new object[] { "Gamma", 5, 7 } });42 var resolver = new ObjectsResultSetResolver(args);43 var rs = resolver.Execute();44 rs.Columns[0].ColumnName = "a";45 rs.Columns[1].ColumnName = "b";46 rs.Columns[2].ColumnName = "c";47 var extender = new NCalcExtendEngine(48 new ServiceLocator(),49 new Context(null),50 new ColumnNameIdentifier("d"),51 "[b] * [c]"52 );53 var newRs = extender.Execute(rs);54 Assert.That(newRs.Columns.Count, Is.EqualTo(4));55 Assert.That(newRs.Columns[3].ColumnName, Is.EqualTo("d"));56 Assert.That(newRs.Rows[0][3], Is.EqualTo(2));57 Assert.That(newRs.Rows[1][3], Is.EqualTo(6));58 Assert.That(newRs.Rows[2][3], Is.EqualTo(35));59 }60 [Test]61 public void Execute_StandardRsColumnNameAndVariable_CorrectExtension()62 {63 var args = new ObjectsResultSetResolverArgs(new[] { new object[] { "Alpha", 1, 2 }, new object[] { "Beta", 3, 2 }, new object[] { "Gamma", 5, 7 } });64 var resolver = new ObjectsResultSetResolver(args);65 var rs = resolver.Execute();66 rs.Columns[0].ColumnName = "a";67 rs.Columns[1].ColumnName = "b";68 rs.Columns[2].ColumnName = "c";69 var extender = new NCalcExtendEngine(70 new ServiceLocator(),71 new Context(new Dictionary<string, IVariable> { { "myVar", new GlobalVariable(new LiteralScalarResolver<decimal>(2)) } }),72 new ColumnNameIdentifier("d"),73 "[@myVar] * [b] * [c]"74 );75 var newRs = extender.Execute(rs);76 Assert.That(newRs.Columns.Count, Is.EqualTo(4));77 Assert.That(newRs.Columns[3].ColumnName, Is.EqualTo("d"));78 Assert.That(newRs.Rows[0][3], Is.EqualTo(4));79 Assert.That(newRs.Rows[1][3], Is.EqualTo(12));80 Assert.That(newRs.Rows[2][3], Is.EqualTo(70));81 }82 [Test]83 [TestCase(1000)]84 [TestCase(10000)]85 [Retry(3)]86 public void Execute_ManyTimes_Performances(int count)87 {88 var rows = new List<object[]>();89 for (int i = 0; i < count; i++)90 rows.Add(new object[] { i, i + 1 });91 var args = new ObjectsResultSetResolverArgs(rows.ToArray());92 var resolver = new ObjectsResultSetResolver(args);93 var rs = resolver.Execute();94 rs.Columns[0].ColumnName = "a";95 rs.Columns[1].ColumnName = "b";96 var stopWatch = new Stopwatch();97 stopWatch.Start();98 var extender = new NCalcExtendEngine(99 new ServiceLocator(),100 new Context(null),101 new ColumnNameIdentifier("c"),102 "[b] - [a] + Max(a,b) - Sin(a)"103 );104 var newRs = extender.Execute(rs);105 stopWatch.Stop();106 Assert.That(stopWatch.ElapsedMilliseconds, Is.LessThanOrEqualTo(5000));...
NewNameRenamingEngineTest.cs
Source:NewNameRenamingEngineTest.cs
...17 {18 [Test]19 public void Execute_ExistingColumnByOrdinal_ColumnRenamed()20 {21 var args = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });22 var resolver = new ObjectsResultSetResolver(args);23 var rs = resolver.Execute();24 var renamer = new NewNameRenamingEngine(25 new ColumnOrdinalIdentifier(1),26 new LiteralScalarResolver<string>("myNewName")27 );28 var newRs = renamer.Execute(rs);29 Assert.That(newRs.Columns[1].ColumnName, Is.EqualTo("myNewName"));30 }31 [Test]32 public void Execute_ExistingColumnByName_ColumnRenamed()33 {34 var args = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });35 var resolver = new ObjectsResultSetResolver(args);36 var rs = resolver.Execute();37 rs.Columns[1].ColumnName = "myOldName";38 var renamer = new NewNameRenamingEngine(39 new ColumnNameIdentifier("myOldName"),40 new LiteralScalarResolver<string>("myNewName")41 );42 var newRs = renamer.Execute(rs);43 Assert.That(newRs.Columns[1].ColumnName, Is.EqualTo("myNewName"));44 Assert.That(newRs.Columns.Cast<DataColumn>().Any(c => c.ColumnName == "myOldName"), Is.False);45 }46 [Test]47 public void Execute_NotExistingColumnFailureStrategy_IgnoreIssue()48 {49 var args = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });50 var resolver = new ObjectsResultSetResolver(args);51 var rs = resolver.Execute();52 var renamer = new NewNameRenamingEngine(53 new ColumnNameIdentifier("unexistingColumn"),54 new LiteralScalarResolver<string>("myNewName")55 );56 Assert.Throws<NBiException>( () => renamer.Execute(rs));57 }58 [Test]59 public void Execute_NotExistingColumnSkipStrategy_IgnoreIssue()60 {61 var args = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });62 var resolver = new ObjectsResultSetResolver(args);63 var rs = resolver.Execute();64 var renamer = new NewNameRenamingEngine(65 new ColumnNameIdentifier("unexistingColumn"),66 new LiteralScalarResolver<string>("myNewName"),67 new SkipAlterationStrategy()68 );69 var newRs = renamer.Execute(rs);70 Assert.That(newRs.Columns.Cast<DataColumn>().Any(c => c.ColumnName == "unexistingColumn"), Is.False);71 }72 }73}...
ObjectsResultSetResolver
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.Resolver;8using NBi.Core.Calculation;9using NBi.Core.Calculation.Predicate;10using NBi.Core.Calculation.Resolver;11using NBi.Core.Variable;12using NBi.Core.Injection;13using NBi.Extensibility.Resolving;14{15 {16 static void Main(string[] args)17 {18 ObjectsResultSetResolver rsResolver = new ObjectsResultSetResolver();19 ObjectsResultSetResolverArgs rsResolverArgs = new ObjectsResultSetResolverArgs();20 ObjectResultSetResolverArgs objResolverArgs = new ObjectResultSetResolverArgs();21 objResolverArgs.Values = new object[] { "1", "2", "3" };22 rsResolverArgs.Values = new ObjectResultSetResolverArgs[] { objResolverArgs };23 rsResolver.Setup(rsResolverArgs);24 var rs = rsResolver.Execute();25 Console.WriteLine(rs);26 Console.ReadLine();27 }28 }29}30{31}
ObjectsResultSetResolver
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Resolver;7using NBi.Core.ResultSet;8using NBi.Core.Calculation;9using NBi.Core.Calculation.Predicate;10using NBi.Core.Calculation.Ranking;11using NBi.Core.Calculation.Ranking.Percentile;12using NBi.Core.Calculation.Ranking.TopBottom;13using NBi.Core.Calculation.Ranking.Position;14using NBi.Core.Calculation.Ranking.Aggregation;15using NBi.Core.Calculation.Ranking.Window;16using NBi.Core.Calculation.Ranking.Numeric;17using NBi.Core.Calculation.Ranking.Numeric.Percentile;18using NBi.Core.Calculation.Ranking.Numeric.TopBottom;19using NBi.Core.Calculation.Ranking.Numeric.Position;20using NBi.Core.Calculation.Ranking.Numeric.Aggregation;21using NBi.Core.Calculation.Ranking.Numeric.Window;22using NBi.Core.Evaluation;23using NBi.Core.ResultSet.Equivalence;24using NBi.Core.ResultSet.Lookup.Violation;25using NBi.Core.ResultSet.Lookup;26using NBi.Core.ResultSet.Alteration.Projection;
ObjectsResultSetResolver
Using AI Code Generation
1using NBi.Core.ResultSet;2using NBi.Core.ResultSet.Resolver;3using NBi.Core.Calculation;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9using System.Data;10{11 {12 static void Main(string[] args)13 {14 List<object> list = new List<object>();15 list.Add(1);16 list.Add(2);17 list.Add(3);18 list.Add(4);19 list.Add(5);20 var column = new ColumnIdentifier("Column1");21 var rs = new ObjectsResultSetResolver(list, column);22 var resultset = rs.Execute();23 foreach (DataRow row in resultset.Rows)24 {25 Console.WriteLine(row["Column1"]);26 }27 Console.ReadLine();28 }29 }30}
ObjectsResultSetResolver
Using AI Code Generation
1using System;2using System.Data;3using System.Data.SqlClient;4using System.IO;5using NBi.Core;6using NBi.Core.ResultSet;7using NBi.Core.ResultSet.Resolver;8using NBi.Core.ResultSet.Resolver.File;9using NUnit.Framework;10{11 {12 public void Test1()13 {14 DataTable table = new DataTable("TestTable");15 DataColumn column;16 DataRow row;17 column = new DataColumn();18 column.DataType = System.Type.GetType("System.Int32");19 column.ColumnName = "id";20 column.AutoIncrement = true;21 column.AutoIncrementSeed = 1;22 column.AutoIncrementStep = 1;23 table.Columns.Add(column);24 column = new DataColumn();25 column.DataType = Type.GetType("System.String");26 column.ColumnName = "name";27 table.Columns.Add(column);28 DataColumn[] PrimaryKeyColumns = new DataColumn[1];29 PrimaryKeyColumns[0] = table.Columns["id"];30 table.PrimaryKey = PrimaryKeyColumns;31 DataSet dataSet = new DataSet();32 dataSet.Tables.Add(table);33 for (int i = 0; i < 10; i++)34 {35 row = table.NewRow();36 row["name"] = "Name " + i;37 table.Rows.Add(row);38 }39 table.AcceptChanges();40 string connectionString = "Data Source=.;Initial Catalog=Northwind;Integrated Security=True";41 string queryString = "SELECT * FROM Customers";42 using (SqlConnection connection = new SqlConnection(connectionString))43 {44 SqlCommand command = new SqlCommand(queryString, connection);45 SqlDataAdapter adapter = new SqlDataAdapter(command);
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!!