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

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

LookupReplaceEngineTest.cs

Source:LookupReplaceEngineTest.cs Github

copy

Full Screen

...13using System.Text;14using System.Threading.Tasks;15namespace NBi.Testing.Core.ResultSet.Alteration.Lookup16{17 public class LookupReplaceEngineTest18 {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));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 }...

Full Screen

Full Screen

LookupReplaceEngine.cs

Source:LookupReplaceEngine.cs Github

copy

Full Screen

...9using System.Text;10using System.Threading.Tasks;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

LookupFactory.cs

Source:LookupFactory.cs Github

copy

Full Screen

...10 public ILookupEngine Instantiate(ILookupArgs args)11 {12 switch(args)13 {14 case LookupReplaceArgs x: return new LookupReplaceEngine(x);15 default: throw new ArgumentException();16 }17 }18 }19}...

Full Screen

Full Screen

LookupReplaceEngine

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet;7using NBi.Core.ResultSet.Alteration.Lookup;8using NBi.Core.ResultSet.Resolver;9using NBi.Core.Calculation;10using NBi.Core.Calculation.Predicate;11{12 {13 public LookupReplaceEngineTest()14 {15 var lookup = new ResultSet();16 lookup.Load(NBi.Core.ResultSet.Serialization.ResultSetFlatFileSerializer.Deserialize("C:\\Users\\julien\\Desktop\\lookup.csv"));17 var lookupResolver = new ResultSetResolver(lookup);18 var lookupEngine = new LookupReplaceEngine(lookupResolver);19 var rs = new ResultSet();20 rs.Load(NBi.Core.ResultSet.Serialization.ResultSetFlatFileSerializer.Deserialize("C:\\Users\\julien\\Desktop\\rs.csv"));21 rs.Columns[0].Type = ColumnType.Numeric;22 rs.Columns[1].Type = ColumnType.Text;23 var rsResolver = new ResultSetResolver(rs);24 lookupEngine.Execute(rsResolver);25 }26 }27}28using System;29using System.Collections.Generic;30using System.Linq;31using System.Text;32using System.Threading.Tasks;33using NBi.Core.ResultSet;34using NBi.Core.ResultSet.Alteration.Lookup;35using NBi.Core.ResultSet.Resolver;36using NBi.Core.Calculation;37using NBi.Core.Calculation.Predicate;38{39 {40 public LookupReplaceEngineTest()41 {42 var lookup = new ResultSet();43 lookup.Columns.Add(new Column("Id", ColumnType.Numeric));44 lookup.Columns.Add(new Column("Name", ColumnType.Text));45 lookup.Rows.Add(new Row(new object[] { 1, "John" }));46 lookup.Rows.Add(new Row(new object[] { 2, "Paul" }));47 lookup.Rows.Add(new Row(new object[] { 3, "George" }));48 lookup.Rows.Add(new Row(new object[] { 4, "Ringo" }));49 var lookupResolver = new ResultSetResolver(lookup);50 var lookupEngine = new LookupReplaceEngine(lookupResolver);51 var rs = new ResultSet();52 rs.Columns.Add(new Column("Id

Full Screen

Full Screen

LookupReplaceEngine

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Lookup;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Resolver;9using NBi.Core.ResultSet.Resolver.File;10{11 {12 static void Main(string[] args)13 {14 var lookupTable = new ResultSet();15 var lookupRows = new List<object[]>();16 lookupRows.Add(new object[] { "1", "A" });17 lookupRows.Add(new object[] { "2", "B" });18 lookupRows.Add(new object[] { "3", "C" });19 lookupTable.Rows = lookupRows;20 var lookupEngine = new LookupReplaceEngine(lookupTable);21 var lookupTableResolver = new FileResultSetResolver(@"C:\Users\Public\Documents\NBi\LookupTable.csv");22 var lookupEngine2 = new LookupReplaceEngine(lookupTableResolver);23 var resultSet = new ResultSet();24 var resultSetRows = new List<object[]>();25 resultSetRows.Add(new object[] { "1", "A" });26 resultSetRows.Add(new object[] { "2", "B" });27 resultSetRows.Add(new object[] { "3", "C" });28 resultSet.Rows = resultSetRows;29 var resultSetResolver = new FileResultSetResolver(@"C:\Users\Public\Documents\NBi\ResultSet.csv");30 var resultSetEngine = new ResultSetEngine(resultSetResolver);31 var resultSetEngine2 = new ResultSetEngine(resultSet);32 var lookupResultSet = lookupEngine.Execute(resultSet);33 var lookupResultSet2 = lookupEngine2.Execute(resultSetEngine);34 var lookupResultSetResolver = new FileResultSetResolver(@"C:\Users\Public\Documents\NBi\LookupResultSet.csv");35 var lookupResultSetEngine = new ResultSetEngine(lookupResultSetResolver);36 var lookupResultSetEngine2 = new ResultSetEngine(lookupResultSet);37 var lookupResultSetEngine3 = new ResultSetEngine(lookupResultSet2);

Full Screen

Full Screen

LookupReplaceEngine

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Lookup;7{8 {9 public void Execute(DataTable table, DataTable lookupTable, string lookupColumn, string resultColumn)10 {11 var lookup = new LookupReplace(table, lookupTable, lookupColumn, resultColumn);12 lookup.Execute();13 }14 }15}16using System;17using System.Collections.Generic;18using System.Linq;19using System.Text;20using System.Threading.Tasks;21using NBi.Core.ResultSet.Alteration.Lookup;22{23 {24 public void Execute(DataTable table, DataTable lookupTable, string lookupColumn, string resultColumn)25 {26 var lookup = new LookupReplace(table, lookupTable, lookupColumn, resultColumn);27 lookup.Execute();28 }29 }30}31using System;32using System.Collections.Generic;33using System.Linq;34using System.Text;35using System.Threading.Tasks;36using NBi.Core.ResultSet.Alteration.Lookup;37{38 {39 public void Execute(DataTable table, DataTable lookupTable, string lookupColumn, string resultColumn)40 {41 var lookup = new LookupReplace(table, lookupTable, lookupColumn, resultColumn);42 lookup.Execute();43 }44 }45}46using System;47using System.Collections.Generic;48using System.Linq;49using System.Text;50using System.Threading.Tasks;51using NBi.Core.ResultSet.Alteration.Lookup;52{53 {54 public void Execute(DataTable table, DataTable lookupTable, string lookupColumn, string resultColumn)55 {56 var lookup = new LookupReplace(table, lookupTable, lookupColumn, resultColumn);57 lookup.Execute();58 }59 }60}61using System;

Full Screen

Full Screen

LookupReplaceEngine

Using AI Code Generation

copy

Full Screen

1var lookupReplaceEngine = new LookupReplaceEngine();2var result = lookupReplaceEngine.Execute(3 new LookupReplaceArgs()4 {5 ResultSet = new ResultSet()6 {7 Columns = new List<IColumnDefinition>()8 {9 new ColumnDefinition("Column1", typeof(string)),10 new ColumnDefinition("Column2", typeof(string)),11 },12 Rows = new List<IRow>()13 {14 new Row(new List<object>() { "1", "2" }),15 new Row(new List<object>() { "3", "4" }),16 }17 },18 Lookup = new ResultSet()19 {20 Columns = new List<IColumnDefinition>()21 {22 new ColumnDefinition("Column1", typeof(string)),23 new ColumnDefinition("Column2", typeof(string)),24 },25 Rows = new List<IRow>()26 {27 new Row(new List<object>() { "1", "a" }),28 new Row(new List<object>() { "3", "b" }),29 }30 },31 LookupColumns = new List<string>() { "Column1" },32 ReplaceColumns = new List<string>() { "Column2" },33 });34foreach (var row in result.Rows)35 Console.WriteLine($"{row[0]} - {row[1]}");

Full Screen

Full Screen

LookupReplaceEngine

Using AI Code Generation

copy

Full Screen

1var engine = new LookupReplaceEngine();2var result = engine.Execute(resultset, lookup);3var engine = new ReplaceEngine();4var result = engine.Execute(resultset, lookup);5var lookup = new ResultSet();6lookup.Columns.Add(new Column("col1", new List<object> { "a", "b", "c" }));7lookup.Columns.Add(new Column("col2", new List<object> { "a", "b", "c" }));8var resultset = new ResultSet();9resultset.Columns.Add(new Column("col1", new List<object>

Full Screen

Full Screen

LookupReplaceEngine

Using AI Code Generation

copy

Full Screen

1var engine = new LookupReplaceEngine();2engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });3var engine = new LookupReplaceEngine();4engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });5var engine = new LookupReplaceEngine();6engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });7var engine = new LookupReplaceEngine();8engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });9var engine = new LookupReplaceEngine();10engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });11var engine = new LookupReplaceEngine();12engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });13var engine = new LookupReplaceEngine();14engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });15var engine = new LookupReplaceEngine();16engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });17var engine = new LookupReplaceEngine();18engine.Execute(rs, new[] { new LookupReplaceArgs("Column1", "Column2", "Column3") });

Full Screen

Full Screen

LookupReplaceEngine

Using AI Code Generation

copy

Full Screen

1Assembly assembly = Assembly.Load("NBi.Core");2Type type = assembly.GetType("NBi.Core.ResultSet.Alteration.Lookup.LookupReplaceEngine");3object obj = Activator.CreateInstance(type);4MethodInfo method = type.GetMethod("Execute");5method.Invoke(obj, null);6Assembly assembly = Assembly.Load("NBi.Core");7Type type = assembly.GetType("NBi.Core.ResultSet.Alteration.Lookup.LookupReplaceEngine");8object obj = Activator.CreateInstance(type);9MethodInfo method = type.GetMethod("Execute");10method.Invoke(obj, null);11Assembly assembly = Assembly.Load("NBi.Core");12Type type = assembly.GetType("NBi.Core.ResultSet.Alteration.Lookup.LookupReplaceEngine");13object obj = Activator.CreateInstance(type);14MethodInfo method = type.GetMethod("Execute");15method.Invoke(obj, null);

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 LookupReplaceEngine

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful