Skip to content

Compare Lists / Tabular data with informative results

License

Notifications You must be signed in to change notification settings

michal-ciechan/DataCompare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataCompare

Compare Lists / Tabular data with rich set of results for reporting.

Table of Content

Code Samples Preface

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;

Compare Result Information

Same

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();

Left only

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());

Right Only

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());

Row Collection

'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.

Config

The following are available settings on the DataComparerConfig settings class

HasHeaders

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.

Key Columns

//Default
Keys = new HashSet<string>
{
    "Key"
}

Skipped Columns

//Default
Skip = new HashSet<string>
{
    "ID", "Skip"
}

About

Compare Lists / Tabular data with informative results

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages