Compare Lists / Tabular data with rich set of results for reporting.
Most of the following code sample will be using the following TestData.Lists.Default
to minimize lines of code, followed by self explanatory (hopefully) fluent calls.
public static class Lists
{
public static List<List<string>> Default => new List<List<string>>
{
new List<string> {"Key", "Value"},
new List<string> {"1", "Test"},
};
}
If you see left
and right
used somewhere with no definition, these are set to the above Lists.Default
.
left = Lists.Default;
right = Lists.Default;
Returns true if no differences where found between compared lists.
var diff = Lists.Default.Add(2, "New");
var res1 = _comparer.Compare(left, right);
var res2 = _comparer.Compare(left, diff);
res1.Same.Should().BeTrue();
res2.Same.Should().BeFalse();
Contains the rows whose keys were present only in the left list.
var leftExtra = Lists.Default.Add(2, "New");
var res1 = _comparer.Compare(left, right);
var res2 = _comparer.Compare(leftExtra, right);
res1.LeftOnly.Should().BeEmpty();
res2.LeftOnly.ShouldBeEquivalentTo(leftExtra.Last());
Contains the rows whose keys were present only in the right list.
var rightExtra = Lists.Default.Add(2, "New");
var res1 = _comparer.Compare(left, right);
var res2 = _comparer.Compare(left, rightExtra);
res1.RightOnly.Should().BeEmpty();
res2.RightOnly.ShouldBeEquivalentTo(rightExtra.Last());
'RowCollection' class represents a collection of rows, and parses first row as header, as well as finds the Key, Skipped and Data column indexes.
N.B. Uses DataComparerConfig.Default if no config is passed in.
The following are available settings on the DataComparerConfig
settings class
THIS IS NOT YET IMPLEMETNED. PLANNED FOR A FUTURE RELEASE!
Sets wether or not the first row has headers.
//Default
HasHeaders = true;
When parsing a collection with no headers, the comparer will try to convert any Key
/Skip
value into an int
, and if successfulll and is within the range of the row length, it will use this as an index.
//Default
Keys = new HashSet<string>
{
"Key"
}
//Default
Skip = new HashSet<string>
{
"ID", "Skip"
}