How to use LookupReplaceArgs class of NBi.Core.ResultSet.Alteration.Lookup package

Best NBi code snippet using NBi.Core.ResultSet.Alteration.Lookup.LookupReplaceArgs

LookupReplaceEngineTest.cs

Source:LookupReplaceEngineTest.cs Github

copy

Full Screen

...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));214 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("alpha"));215 Assert.That(result.Rows.Cast<DataRow>().Select(x => x[1]).Distinct(), Does.Contain("beta"));216 var otherValues = result.Rows.Cast<DataRow>().Select(x => x[1] as string).Where(x => x != "alpha" && x != "beta");217 Assert.That(otherValues, Is.Empty);218 }219 }220}...

Full Screen

Full Screen

LookupReplaceEngine.cs

Source:LookupReplaceEngine.cs Github

copy

Full Screen

...11namespace NBi.Core.ResultSet.Alteration.Lookup12{13 class LookupReplaceEngine : ILookupEngine14 {15 private LookupReplaceArgs Args { get; }16 public LookupReplaceEngine(LookupReplaceArgs args)17 => (Args) = (args);18 public IResultSet Execute(IResultSet candidate)19 {20 var reference = Args.Reference.Execute();21 var stopWatch = new Stopwatch();22 stopWatch.Start();23 var referenceKeyRetriever = BuildColumnsRetriever(Args.Mapping, x => x.ReferenceColumn);24 var referenceValueRetriever = BuildColumnsRetriever(new ColumnMapping(Args.Replacement, ColumnType.Untyped), x => x.ReferenceColumn);25 var index = BuildReferenceIndex(reference.Table, referenceKeyRetriever, referenceValueRetriever);26 Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceInfo, $"Built the index for reference table containing {index.Count()} rows [{stopWatch.Elapsed:d'.'hh':'mm':'ss'.'fff'ms'}]");27 stopWatch.Restart();28 var candidateKeyBuilder = BuildColumnsRetriever(Args.Mapping, x => x.CandidateColumn);29 var originalColumn = candidate.Table.GetColumn(Args.Mapping.CandidateColumn);30 var newColumn = candidate.Table.Columns.Add($"tmp_{originalColumn.ColumnName}", typeof(object));...

Full Screen

Full Screen

LookupReplaceArgs.cs

Source:LookupReplaceArgs.cs Github

copy

Full Screen

...7using System.Text;8using System.Threading.Tasks;9namespace NBi.Core.ResultSet.Alteration.Lookup10{11 public class LookupReplaceArgs : ILookupArgs12 {13 public ColumnMapping Mapping { get; set; }14 public IResultSetService Reference { get; set; }15 public IColumnIdentifier Replacement { get; set; }16 public IMissingStrategy MissingStrategy { get; set; }17 public LookupReplaceArgs(IResultSetService resultSet, ColumnMapping mapping, IColumnIdentifier replacement)18 : this(resultSet, mapping, replacement, new FailureMissingStrategy()) { }19 public LookupReplaceArgs(IResultSetService resultSet, ColumnMapping mapping, IColumnIdentifier replacement, IMissingStrategy missingStrategy)20 => (Reference, Mapping, Replacement, MissingStrategy) = (resultSet, mapping, replacement, missingStrategy);21 }22}...

Full Screen

Full Screen

LookupReplaceArgs

Using AI Code Generation

copy

Full Screen

1using NBi.Core.ResultSet.Alteration.Lookup;2using NBi.Core.ResultSet.Alteration;3LookupReplaceArgs args = new LookupReplaceArgs();4args.LookupTable = "LookupTable";5args.LookupColumn = "LookupColumn";6args.LookupValue = "LookupValue";7args.LookupReplacement = "LookupReplacement";8args.LookupReplacementColumn = "LookupReplacementColumn";9args.CaseSensitive = true;10LookupAlteration lookupAlteration = new LookupAlteration(args);11lookupAlteration.Execute(resultSet);12AlterationEngine engine = new AlterationEngine(lookupAlteration);13engine.Execute();14ResultSet rs = new ResultSet();15rs.Load(@"C:\Users\username\Documents\MyResultSet.csv", new ResultSetSettings()16{17});18ResultSetService service = new ResultSetService();19service.Alter(rs, engine);20using NBi.Core.ResultSet;21ResultSetWriter writer = new ResultSetWriter(rs);22writer.Write(@"C:\Users\username\Documents\MyResultSet.csv", new ResultSetSettings()23{24});

Full Screen

Full Screen

LookupReplaceArgs

Using AI Code Generation

copy

Full Screen

1LookupReplaceArgs args = new LookupReplaceArgs();2args.KeyColumns.Add("Column1");3args.KeyColumns.Add("Column2");4args.ValueColumn = "Column3";5args.LookupTable = new DataTable("LookupTable");6args.LookupTable.Columns.Add("Column1");7args.LookupTable.Columns.Add("Column2");8args.LookupTable.Columns.Add("Column3");9args.LookupTable.Rows.Add("1", "2", "3");10LookupReplace lookupReplace = new LookupReplace(args);11lookupReplace.Execute(result);12DataTable lookupTable = new DataTable("LookupTable");13lookupTable.Columns.Add("Column1");14lookupTable.Columns.Add("Column2");15lookupTable.Columns.Add("Column3");16lookupTable.Rows.Add("1", "2", "3");17lookupTable.Rows.Add("1", "3", "4");18LookupReplace lookupReplace = new LookupReplace("Column1", "Column2", "Column3", lookupTable);19lookupReplace.Execute(result);20LookupReplaceArgs args = new LookupReplaceArgs();21args.KeyColumns.Add("Column1");22args.KeyColumns.Add("Column2");23args.ValueColumn = "Column3";24args.LookupTable = new DataTable("LookupTable");25args.LookupTable.Columns.Add("Column1");26args.LookupTable.Columns.Add("Column2");27args.LookupTable.Columns.Add("Column3");28args.LookupTable.Rows.Add("1", "2", "3");29LookupReplace lookupReplace = new LookupReplace(args);30lookupReplace.Execute(result);31LookupReplace lookupReplace = new LookupReplace("Column1", "Column2", "Column3", lookupTable);32lookupReplace.Execute(result);

Full Screen

Full Screen

LookupReplaceArgs

Using AI Code Generation

copy

Full Screen

1string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);2path = System.IO.Path.Combine(path, "lookup.csv");3var lookup = new LookupReplaceArgs(path, "id", "name");4var alterer = new LookupReplace(lookup);5var result = alterer.Execute(resultSet);6result.Dump();7string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);8path = System.IO.Path.Combine(path, "lookup.csv");9var lookup = new LookupReplaceArgs(path, "id", "name");10var alterer = new LookupReplace(lookup);11var result = alterer.Execute(resultSet);12result.Dump();13string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);14path = System.IO.Path.Combine(path, "lookup.csv");15var lookup = new LookupReplaceArgs(path, "id", "name");16var alterer = new LookupReplace(lookup);17var result = alterer.Execute(resultSet);18result.Dump();19string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);20path = System.IO.Path.Combine(path, "lookup.csv");21var lookup = new LookupReplaceArgs(path, "id", "name");22var alterer = new LookupReplace(lookup);23var result = alterer.Execute(resultSet);24result.Dump();25string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);26path = System.IO.Path.Combine(path, "lookup.csv");27var lookup = new LookupReplaceArgs(path, "id", "name");28var alterer = new LookupReplace(lookup);29var result = alterer.Execute(resultSet);30result.Dump();31string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);32path = System.IO.Path.Combine(path, "lookup.csv");33var lookup = new LookupReplaceArgs(path, "id", "name");

Full Screen

Full Screen

LookupReplaceArgs

Using AI Code Generation

copy

Full Screen

1LookupReplaceArgs args = new LookupReplaceArgs();2args.Replacement = "OtherValue";3var lookup = new LookupReplace(args);4lookup.Execute(rs);5LookupReplaceArgs args = new LookupReplaceArgs();6args.Replacement = "OtherValue";7var lookup = new LookupReplace(args);8lookup.Execute(rs);9LookupReplaceArgs args = new LookupReplaceArgs();10args.Replacement = "OtherValue";11var lookup = new LookupReplace(args);12lookup.Execute(rs);

Full Screen

Full Screen

LookupReplaceArgs

Using AI Code Generation

copy

Full Screen

1var lookup = new LookupReplaceArgs("lookup", "lookup", "lookup", "lookup", "lookup");2var args = new AlterationArgs(lookup);3var alteration = AlterationFactory.Instantiate(args);4var result = alteration.Execute(resultset);5var lookup = new LookupReplaceArgs("lookup", "lookup", "lookup", "lookup", "lookup");6var args = new AlterationArgs(lookup);7var alteration = AlterationFactory.Instantiate(args);8var result = alteration.Execute(resultset);9var lookup = new LookupReplaceArgs("lookup", "lookup", "lookup", "lookup", "lookup");10var args = new AlterationArgs(lookup);11var alteration = AlterationFactory.Instantiate(args);12var result = alteration.Execute(resultset);13var lookup = new LookupReplaceArgs("lookup", "lookup", "lookup", "lookup", "lookup");14var args = new AlterationArgs(lookup);15var alteration = AlterationFactory.Instantiate(args);16var result = alteration.Execute(resultset);17var lookup = new LookupReplaceArgs("lookup", "lookup", "lookup", "lookup", "lookup");18var args = new AlterationArgs(lookup);19var alteration = AlterationFactory.Instantiate(args);20var result = alteration.Execute(resultset);21var lookup = new LookupReplaceArgs("lookup", "lookup", "lookup", "lookup", "lookup");22var args = new AlterationArgs(lookup);23var alteration = AlterationFactory.Instantiate(args);24var result = alteration.Execute(resultset);25var lookup = new LookupReplaceArgs("lookup", "lookup", "lookup", "lookup", "lookup");26var args = new AlterationArgs(lookup);27var alteration = AlterationFactory.Instantiate(args);28var result = alteration.Execute(result

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run NBi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in LookupReplaceArgs

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful