Best NBi code snippet using NBi.Core.ResultSet.Lookup.ColumnMappingCollection
LookupViolationCollection.cs
Source:LookupViolationCollection.cs
...10{11 public abstract class LookupViolationCollection : Dictionary<KeyCollection, LookupViolationInformation>12 {13 private bool isBuilt = false;14 public ColumnMappingCollection KeyMappings { get; set; }15 public ColumnMappingCollection ValueMappings { get; set; }16 public LookupViolationCollection(ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings)17 {18 KeyMappings = keyMappings;19 ValueMappings = valueMappings;20 }21 protected virtual LookupViolationInformation Register(RowViolationState state, NBiRs.KeyCollection key, DataRow candidateRow)22 {23 if (ContainsKey(key))24 {25 var info = this[key];26 if (info.State != state)27 throw new ArgumentException("Can't change the state of lookup violation", nameof(state));28 info.AddCandidateRow(candidateRow);29 return info;30 }31 else32 {33 LookupViolationInformation info = state==RowViolationState.Mismatch34 ? (LookupViolationInformation) new LookupMatchesViolationInformation(state)35 : new LookupExistsViolationInformation(state);36 info.AddCandidateRow(candidateRow);37 Add(key, info);38 return info;39 }40 }41 public IEnumerable<DataRow> GetRows(RowViolationState state)42 {43 if (Count > 0 && !isBuilt)44 {45 var firstRow = this.ElementAt(0).Value.Rows.ElementAt(0);46 foreach (var keyMapping in KeyMappings.Reverse())47 {48 var column = keyMapping.CandidateColumn.GetColumn(firstRow.Table);49 column.ExtendedProperties["NBi::Role"] = ColumnRole.Key;50 column.ExtendedProperties["NBi::Lookup"] = keyMapping.ReferenceColumn.Label;51 }52 }53 isBuilt = true;54 foreach (var violation in this.Where(x => x.Value.State == state))55 foreach (var row in violation.Value.Rows)56 yield return row;57 }58 }59 public class LookupExistsViolationCollection : LookupViolationCollection60 {61 public LookupExistsViolationCollection(ColumnMappingCollection keyMappings)62 : base(keyMappings, null) { }63 public LookupViolationInformation Register(NBiRs.KeyCollection key, DataRow candidateRow)64 => Register(RowViolationState.Unexpected, key, candidateRow);65 }66 public class LookupMatchesViolationCollection : LookupViolationCollection67 {68 public LookupMatchesViolationCollection(ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings)69 : base(keyMappings, valueMappings) { }70 public LookupViolationInformation Register(NBiRs.KeyCollection key, DataRow candidateRow)71 => Register(RowViolationState.Unexpected, key, candidateRow);72 public LookupViolationInformation Register(NBiRs.KeyCollection key, LookupMatchesViolationComposite composite)73 {74 if (ContainsKey(key))75 {76 var info = this[key] as LookupMatchesViolationInformation;77 if (info.State != RowViolationState.Mismatch)78 throw new ArgumentException("Can't change the state of lookup violation");79 info.CandidateRows.Add(composite);80 return info;81 }82 else83 {84 var info = new LookupMatchesViolationInformation(RowViolationState.Mismatch);85 info.CandidateRows.Add(composite);86 Add(key, info);87 return info;88 }89 }90 }91 public class ReverseLookupExistsViolationCollection : LookupViolationCollection92 {93 public ReverseLookupExistsViolationCollection(ColumnMappingCollection keyMappings)94 : base(keyMappings, null) { }95 public LookupViolationInformation Register(NBiRs.KeyCollection key, DataRow candidateRow)96 => Register(RowViolationState.Missing, key, candidateRow);97 }98}...
LookupViolationMessage.cs
Source:LookupViolationMessage.cs
...18 protected T reference;19 protected T candidate;20 protected T analysis;21 public LookupViolationMessage(IDictionary<string, ISampler<DataRow>> samplers) => Samplers = samplers;22 public void Generate(IEnumerable<DataRow> referenceRows, IEnumerable<DataRow> candidateRows, LookupViolationCollection violations, ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings)23 {24 var metadata = BuildMetadata(keyMappings, ColumnRole.Key, x => x.ReferenceColumn)25 .Union(BuildMetadata(valueMappings, ColumnRole.Value, x => x.ReferenceColumn));26 RenderStandardTable(referenceRows, metadata, Samplers["reference"], "Reference", reference);27 metadata = BuildMetadata(keyMappings, ColumnRole.Key, x => x.CandidateColumn)28 .Union(BuildMetadata(valueMappings, ColumnRole.Value, x => x.CandidateColumn));29 RenderStandardTable(candidateRows, metadata, Samplers["candidate"], "Candidate", candidate);30 RenderAnalysis(violations, metadata, Samplers["analysis"], keyMappings, valueMappings, analysis);31 }32 private IEnumerable<ColumnMetadata> BuildMetadata(ColumnMappingCollection mappings, ColumnRole role, Func<ColumnMapping, IColumnIdentifier> identify)33 {34 foreach (var mapping in mappings ?? new ColumnMappingCollection())35 yield return new ColumnMetadata()36 {37 Identifier = identify.Invoke(mapping),38 Role = role,39 Type = mapping.Type,40 };41 }42 protected abstract void RenderStandardTable(IEnumerable<DataRow> rows, IEnumerable<ColumnMetadata> metadata, ISampler<DataRow> sampler, string title, T writer);43 protected abstract void RenderAnalysis(LookupViolationCollection violations, IEnumerable<ColumnMetadata> metadata, ISampler<DataRow> sampler, ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings, T writer);44 public abstract string RenderReference();45 public abstract string RenderCandidate();46 public abstract string RenderAnalysis();47 public virtual string RenderPredicate() => "Some references are missing and violate referential integrity";48 public abstract string RenderMessage();49 }50}...
LookupMatchesConstraint.cs
Source:LookupMatchesConstraint.cs
...20 21 protected internal override ILookupAnalyzer Engine22 {23 get => engine ?? (engine = new LookupMatchesAnalyzer(24 keyMappings ?? ColumnMappingCollection.Default25 , valueMappings ?? throw new ArgumentNullException()26 , tolerances 27 ));28 set => engine = value ?? throw new ArgumentNullException();29 }30 protected override ILookupViolationMessageFormatter BuildFailure()31 {32 var factory = new LookupMatchesViolationsMessageFormatterFactory();33 var msg = factory.Instantiate(Configuration.FailureReportProfile);34 msg.Generate(rsReference.Rows.Cast<DataRow>(), rsCandidate.Rows.Cast<DataRow>(), violations, keyMappings, valueMappings);35 return msg;36 }37 public LookupMatchesConstraint(IResultSetService reference)38 : base(reference) { }39 private ColumnMappingCollection keyMappings;40 private ColumnMappingCollection valueMappings;41 private IDictionary<IColumnIdentifier, Tolerance> tolerances;42 public LookupExistsConstraint Using(ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings, IDictionary<IColumnIdentifier, Tolerance> tolerances)43 {44 this.keyMappings = keyMappings;45 this.valueMappings = valueMappings;46 this.tolerances = tolerances;47 return this;48 }49 }50}
ColumnMappingCollection
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 ColumnMappingCollection collection = new ColumnMappingCollection();12 collection.Add(new ColumnMapping("col1", "col2"));13 collection.Add(new ColumnMapping("col3", "col4"));14 collection.Add(new ColumnMapping("col5", "col6"));15 foreach (ColumnMapping item in collection)16 {17 Console.WriteLine(item);18 }19 Console.ReadLine();20 }21 }22}
ColumnMappingCollection
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.Lookup;8{9 {10 static void Main(string[] args)11 {12 var columnMappingCollection = new ColumnMappingCollection();13 columnMappingCollection.Add(new ColumnMapping("Column1", "Column1"));14 columnMappingCollection.Add(new ColumnMapping("Column2", "Column2"));15 columnMappingCollection.Add(new ColumnMapping("Column3", "Column3"));16 Console.WriteLine(columnMappingCollection);17 Console.ReadLine();18 }19 }20}21ColumnMappingCollection { ColumnMapping { Reference = Column1, Test = Column1 }, ColumnMapping { Reference = Column2, Test = Column2 }, ColumnMapping { Reference = Column3, Test = Column3 } }22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using NBi.Core;28using NBi.Core.ResultSet;29using NBi.Core.ResultSet.Lookup;30{31 {32 static void Main(string[] args)33 {34 var columnMappingCollection = new ColumnMappingCollection();35 columnMappingCollection.Add(new ColumnMapping("Column1", "Column1"));36 columnMappingCollection.Add(new ColumnMapping("Column2", "Column2"));37 columnMappingCollection.Add(new ColumnMapping("Column3", "Column3"));38 Console.WriteLine(columnMappingCollection);39 Console.ReadLine();40 }41 }42}43ColumnMappingCollection { ColumnMapping { Reference = Column1, Test = Column1 }, ColumnMapping { Reference = Column2, Test = Column2 }, ColumnMapping { Reference = Column3, Test = Column3 } }
ColumnMappingCollection
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Data;6using NBi.Core.ResultSet.Lookup;7{8 {9 static void Main(string[] args)10 {11 ColumnMappingCollection cmc = new ColumnMappingCollection();12 cmc.Add(new ColumnMapping("col1", "col2"));13 cmc.Add(new ColumnMapping("col3", "col4"));14 cmc.Add(new ColumnMapping("col5", "col6"));15 foreach (ColumnMapping cm in cmc)16 {
ColumnMappingCollection
Using AI Code Generation
1using System;2using System.Data;3using System.Data.SqlClient;4using NBi.Core.ResultSet.Lookup;5{6 {7 static void Main(string[] args)8 {9 ColumnMappingCollection columnMappingCollection = new ColumnMappingCollection();10 columnMappingCollection.Add(new ColumnMapping("Name", "Name"));11 columnMappingCollection.Add(new ColumnMapping("Age", "Age"));12 columnMappingCollection.Add(new ColumnMapping("Address", "Address"));13 Console.WriteLine(columnMappingCollection.ToString());14 Console.ReadLine();15 }16 }17}
ColumnMappingCollection
Using AI Code Generation
1NBi.Core.ResultSet.ColumnMappingCollection colMapping = new NBi.Core.ResultSet.ColumnMappingCollection();2colMapping.Add(new NBi.Core.ResultSet.ColumnMapping("col1", "col1"));3colMapping.Add(new NBi.Core.ResultSet.ColumnMapping("col2", "col2"));4colMapping.Add(new NBi.Core.ResultSet.ColumnMapping("col3", "col3"));5NBi.Core.ResultSet.Lookup.LookupResultSet lookupResultSet = new NBi.Core.ResultSet.Lookup.LookupResultSet();6lookupResultSet.Columns = colMapping;7lookupResultSet.AddRow(new object[] { "1", "2", "3" });8lookupResultSet.AddRow(new object[] { "4", "5", "6" });9lookupResultSet.AddRow(new object[] { "7", "8", "9" });10lookupResultSet.AddRow(new object[] { "10", "11", "12" });11lookupResultSet.AddRow(new object[] { "13", "14", "15" });12NBi.Core.ResultSet.Lookup.Lookup lookup = new NBi.Core.ResultSet.Lookup.Lookup();13lookup.ResultSet = lookupResultSet;14context.LookupCollection.Add("lookup", lookup);15NBi.NUnit.ResultSet.LookupEqualTo lookupEqualTo = new NBi.NUnit.ResultSet.LookupEqualTo();16lookupEqualTo.Lookup = "lookup";17lookupEqualTo.Expected = lookupResultSet;18NBi.NUnit.ResultSet.LookupEqualToTest lookupEqualToTest = new NBi.NUnit.ResultSet.LookupEqualToTest(lookupEqualTo);
ColumnMappingCollection
Using AI Code Generation
1var settings = new ResultSetComparisonSettings();2settings.ColumnMappingCollection.Add(new ColumnMapping("col1", "col1"));3settings.ColumnMappingCollection.Add(new ColumnMapping("col2", "col2"));4var result = new ResultSetComparison(5 new ResultSet(new[] { "col1", "col2" }, new[] { new object[] { 1, 2 } }),6 new ResultSet(new[] { "col1", "col2" }, new[] { new object[] { 1, 2 } }),7 ).Compare();8Assert.That(result, Is.True);9var settings = new ResultSetComparisonSettings();10settings.ColumnMappingCollection.Add(new ColumnMapping("col1", "col1"));11settings.ColumnMappingCollection.Add(new ColumnMapping("col2", "col2"));12var result = new ResultSetComparison(13 new ResultSet(new[] { "col1", "col2" }, new[] { new object[] { 1, 2 } }),14 new ResultSet(new[] { "col1", "col2" }, new[] { new object[] { 1, 2 } }),15 ).Compare();16Assert.That(result, Is.True);17var settings = new ResultSetComparisonSettings();18settings.ColumnMappingCollection.Add(new ColumnMapping("col1", "col1"));19settings.ColumnMappingCollection.Add(new ColumnMapping("col2", "col2"));20var result = new ResultSetComparison(21 new ResultSet(new[] { "col1", "col2" }, new[] { new object[] { 1, 2 } }),22 new ResultSet(new[] { "col1", "col2" }, new[] { new object[] { 1, 2 } }),23 ).Compare();24Assert.That(result, Is.True);25var settings = new ResultSetComparisonSettings();
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!!