public RowDifference(SnapshotRowKey key, DifferenceType differenceType, SnapshotRow before, SnapshotRow after)
 {
     Key            = key;
     DifferenceType = differenceType;
     Before         = before;
     After          = after;
 }
        public void DifferencesAreEnumerated()
        {
            //Arrange
            var first  = GetRow(1);
            var second = GetRow(2);

            first["Variable"]   = 1;
            second["Variable"]  = 2;
            first["Variable2"]  = "before";
            second["Variable2"] = "after";
            first["Match"]      = "same"; //no difference, so not in the output
            second["Match"]     = "same"; //no difference, so not in the output

            var key = new SnapshotRowKey(first.Row, _tableDef);

            //Act
            var result = RowDataComparer.Compare(_tableDef, key, first.Row, second.Row); //note: Keys are different but they are not compared

            //Assert
            var output = new Output();

            output.WrapLine($"Matched = {result.Matched}");
            output.WriteLine();
            output.FormatTable(result.Differences);
            output.Report.Verify();
        }
 public RowDifference(SnapshotRowKey key, RowDataCompareResult differences, DifferenceType type)
 {
     Key            = key;
     DifferenceType = type;
     Differences    = differences;
     Before         = differences.Before;
     After          = differences.After;
 }
        public void AllFieldsExtractedForUnkeyedTable()
        {
            //Arrange
            var td = new TestData();

            td.RowFields[NameCol] = "Name";
            td.RowFields[IdCol]   = 100;

            //Act
            var key = new SnapshotRowKey(td.Row, td.Table);

            //Assert
            key.AllKeys.Should().Equal("Name", 100);
        }
        public void PrimaryKeyIsExtracted()
        {
            //Arrange
            var td = new TestData();

            td.Definer.PrimaryKey(IdCol); //Primary key only
            td.RowFields[NameCol] = "Name";
            td.RowFields[IdCol]   = 100;

            //Act
            var key = new SnapshotRowKey(td.Row, td.Table);

            //Assert
            key[0].Should().Be(100);
        }
        public void CompoundCompareKeyIsExtracted()
        {
            //Arrange
            var td = new TestData();

            td.Definer.CompareKey(NameCol).PrimaryKey(IdCol).CompareKey(IdCol);
            td.RowFields[NameCol] = "Name";
            td.RowFields[IdCol]   = 100;

            //Act
            var key = new SnapshotRowKey(td.Row, td.Table);

            //Assert
            key.AllKeys.Should().Equal("Name", 100);
        }
        public void KeyIsNotEqualToNull()
        {
            var td = new TestData();

            td.Definer.CompareKey(NameCol).PrimaryKey(IdCol);
            td.RowFields[NameCol] = "Name";
            td.RowFields[IdCol]   = 100;
            var key = new SnapshotRowKey(td.Row, td.Table);

            //Act
            var result = key.Equals(null);

            //Assert
            result.Should().BeFalse();
        }
        public void KeyIsNotEqualToNonKey()
        {
            var td = new TestData();

            td.Definer.CompareKey(NameCol).PrimaryKey(IdCol);
            td.RowFields[NameCol] = "Name";
            td.RowFields[IdCol]   = 100;
            var key = new SnapshotRowKey(td.Row, td.Table);

            //Act
            // ReSharper disable once SuspiciousTypeConversion.Global
            var result = key.Equals(1);

            //Assert
            result.Should().BeFalse();
        }
        public void DifferentRowsCompareUnequal()
        {
            //Arrange
            var first  = GetRow(1);
            var second = GetRow(2);

            first["Variable"]  = 1;
            second["Variable"] = 2;

            var key = new SnapshotRowKey(first.Row, _tableDef);

            //Act
            var result = RowDataComparer.Compare(_tableDef, key, first.Row, second.Row); //note: Keys are different but they are not compared

            //Assert
            result.Matched.Should().BeFalse();
        }
        public void IdenticalKeysCompareEqual()
        {
            //Arrange
            var td = new TestData();

            td.RowFields[NameCol] = "Name";
            td.RowFields[IdCol]   = 100;

            var key  = new SnapshotRowKey(td.Row, td.Table);
            var key2 = new SnapshotRowKey(td.Row, td.Table);

            //Act
            var result = key.CompareTo(key2);

            //Assert
            result.Should().Be(0);
        }
        public void ExcludedFieldsAreNotCompared()
        {
            //Arrange
            _tableDef.ExcludeColumnFromComparison("Variable");
            var first  = GetRow(1);
            var second = GetRow(2);

            first["Variable"]   = 1;
            second["Variable"]  = 2;
            first["Variable2"]  = "before";
            second["Variable2"] = "after";
            first["Match"]      = "same"; //no difference, so not in the output
            second["Match"]     = "same"; //no difference, so not in the output

            var key = new SnapshotRowKey(first.Row, _tableDef);

            //Act
            var result = RowDataComparer.Compare(_tableDef, key, first.Row, second.Row); //note: Keys are different but they are not compared

            //Assert
            result.Differences.Any(d => d.Name == "Variable").Should().BeFalse();
        }