public static RowDataCompareResult Compare(TableDefinition tableDefinition, SnapshotRowKey snapshotRowKey,
                                                   SnapshotRow beforeRow, SnapshotRow afterRow)
        {
            var result = true;

            var nonKeyFieldNames = beforeRow.GetFieldNames()
                                   .Concat(afterRow.GetFieldNames())
                                   .Distinct()
                                   .Except(snapshotRowKey.GetFieldNames().Concat(tableDefinition.ExcludedColumns))
                                   .ToList();

            var diffs = new List <FieldDifference>();

            foreach (var fieldName in nonKeyFieldNames)
            {
                var before        = beforeRow.GetField(fieldName);
                var after         = afterRow.GetField(fieldName);
                var compareResult = ValueComparer.Compare(before, after);
                if (compareResult != 0)
                {
                    diffs.Add(new FieldDifference(fieldName, before, after));
                    result = false;
                }
            }

            return(new RowDataCompareResult(result, diffs, beforeRow, afterRow));
        }
Esempio n. 2
0
        public SnapshotRow AddRow()
        {
            var row = new SnapshotRow(this);

            _rows.Add(row);
            return(row);
        }
 public RowDataCompareResult(bool matched, IList <FieldDifference> differences, SnapshotRow before, SnapshotRow after)
 {
     Matched      = matched;
     _differences = differences != null ? new ReadOnlyCollection <FieldDifference>(differences) : null;
     Before       = before;
     After        = after;
 }
 internal SnapshotRowKey(SnapshotRow snapshotRow, TableDefinition tableDefinition)
 {
     if (tableDefinition.CompareKeys.Any())
     {
         _keys = GetKeys(snapshotRow, tableDefinition.CompareKeys);
     }
     else if (tableDefinition.PrimaryKeys.Any())
     {
         _keys = GetKeys(snapshotRow, tableDefinition.PrimaryKeys);
     }
     else
     {
         _keys = GetKeys(snapshotRow, tableDefinition.Columns.Select(c => c.Name));
     }
 }
 private List <object> GetKeys(SnapshotRow snapshotRow, IEnumerable <string> keyFields)
 {
     _fields = keyFields.ToList();
     return(_fields.Select(snapshotRow.GetField).ToList());
 }