public void ReferenceIdValuesAreReplacedInDiff()
        {
            var table1    = _om.Make <SnapshotObjectMother.Table>(1, 2, 3, 4, 5);
            var refTable1 = _om.Make <SnapshotObjectMother.ReferencingTable>((1, 1), (2, 1));

            void TakeSnapshot(string name)
            {
                var builder = _om.NewSnapshot(name);

                table1.ToSnapshotTable(builder);
                refTable1.ToSnapshotTable(builder);
            }

            TakeSnapshot("Before");
            refTable1[0].Variable = "edited";
            refTable1[1].Variable = "edited";
            refTable1[0].ParentId = table1[3].Id;
            refTable1[1].ParentId = table1[4].Id;
            table1[0].Variable    = "edited";
            table1[1].Variable    = "edited";
            TakeSnapshot("After");

            var before = _om.GetSnapshot("Before");
            var after  = _om.GetSnapshot("After");

            var diffs = DifferenceRegulator.ExpandDifferences(_om.Collection, SnapshotDifferenceCalculator.GetDifferences(_om.Collection, before, after), before);
            var cols  = UnpredictableColumnLocator.Locate(_om.Collection.TablesInDefinitionOrder.ToList())
                        .Single(t => t.Table.TableName == nameof(SnapshotObjectMother.Unpredictables));
            var columnValues = UnpredictableColumnLocator.Locate(diffs.Select(td => td.TableDefinition).ToList())
                               .SelectMany(u => UnpredictableValueScanner.Scan(u, diffs))
                               .ToList();
            var substitutes = columnValues
                              .Select(uv => new SubstituteValues(uv, SubstitutionMaker.Make(uv.Values, TrackerMaker.Make(uv, _om.Collection))))
                              .ToList();

            //Act
            var result = DiffValueSubstituter.Substitute(diffs, substitutes);

            //Assert
            var output         = new Output();
            var originalFields = diffs.Single(d => d.TableDefinition.TableName == nameof(SnapshotObjectMother.ReferencingTable))
                                 .RowDifferences.SelectMany(rd => rd.Differences.Differences);
            var resultFields = result.Single(d => d.TableDefinition.TableName == nameof(SnapshotObjectMother.ReferencingTable))
                               .RowDifferences.SelectMany(rd => rd.Differences.Differences);
            var combined = originalFields.Zip(resultFields,
                                              (o, r) => new
            {
                o.Name, OriginalBefore = o.Before, OriginalAfter = o.After, SubstitutedBefore = r.Before,
                SubstitutedAfter       = r.After
            }).OrderBy(o => o.Name);

            output.FormatTable(combined);
            output.Report.Verify();
        }
        public void UnpredictableValuesAreExtracted()
        {
            //Arrange
            var refGuids  = GuidArray(3);
            var table1    = _om.Make <SnapshotObjectMother.GuidKeyTable>(GuidArray(4));
            var refTable1 = _om.Make <SnapshotObjectMother.GuidRefTable>((refGuids[0], table1[0].GuidKeyId), (refGuids[1], table1[1].GuidKeyId));

            void TakeSnapshot(string name)
            {
                var builder = _om.NewSnapshot(name);

                table1.ToSnapshotTable(builder);
                refTable1.ToSnapshotTable(builder);
            }

            TakeSnapshot("Before");
            table1[0].Variable    = "edited";
            table1[1].Variable    = "edited";
            refTable1[0].Variable = "edited";
            refTable1[1].Variable = "edited";
            TakeSnapshot("After");

            var before = _om.GetSnapshot("Before");
            var after  = _om.GetSnapshot("After");

            var diffs = DifferenceRegulator.ExpandDifferences(_om.Collection, SnapshotDifferenceCalculator.GetDifferences(_om.Collection, before, after), before);

            var tables            = diffs.Select(d => d.TableDefinition).ToList();
            var unpredictableCols = UnpredictableColumnLocator.Locate(tables).Single(t => t.Table.TableName == nameof(SnapshotObjectMother.GuidKeyTable));

            //Act
            var result = UnpredictableValueScanner.Scan(unpredictableCols, diffs);

            //Assert
            var output = new Output();

            output.WrapLine($"Table {unpredictableCols.Table.TableName}");
            output.WriteLine();
            foreach (var valueSet in result)
            {
                output.WriteLine();
                output.WrapLine($"Column {valueSet.Column.Name}");
                output.WriteLine();
                var values     = valueSet.Values;
                var references = valueSet.References;
                var paddedRefs = references.Concat(Enumerable.Range(0, values.Count - references.Count).Select(r => (object)null));
                var report     = values.Zip(paddedRefs, (value, reference) => new { Value = value, Reference = reference });

                output.FormatTable(report);
            }

            output.Report.Verify();
        }
예제 #3
0
        public void SubstitutionsReplaceReferencedKeys()
        {
            //Arrange
            var refGuids  = GuidArray(3);
            var table1    = _om.Make <SnapshotObjectMother.GuidKeyTable>(GuidArray(4));
            var refTable1 = _om.Make <SnapshotObjectMother.GuidRefTable>((refGuids[0], table1[0].GuidKeyId), (refGuids[1], table1[1].GuidKeyId));

            void TakeSnapshot(string name)
            {
                var builder = _om.NewSnapshot(name);

                table1.ToSnapshotTable(builder);
                refTable1.ToSnapshotTable(builder);
            }

            TakeSnapshot("Before");
            table1[0].Variable           = "edited";
            table1[1].Variable           = "edited";
            refTable1[0].GuidKeyParentId = table1[1].GuidKeyId;
            refTable1[1].GuidKeyParentId = table1[2].GuidKeyId;
            TakeSnapshot("After");

            var before = _om.GetSnapshot("Before");
            var after  = _om.GetSnapshot("After");

            var diffs = DifferenceRegulator.ExpandDifferences(_om.Collection, SnapshotDifferenceCalculator.GetDifferences(_om.Collection, before, after), before);

            var tables            = diffs.Select(d => d.TableDefinition).ToList();
            var unpredictableCols = UnpredictableColumnLocator.Locate(tables);
            var columnValueSets   = unpredictableCols.Select(u => UnpredictableValueScanner.Scan(u, diffs)).ToList();

            //Act
            var result = diffs;

            foreach (var columnValueSet in columnValueSets)
            {
                result = ValueSubstituter.Substitute(columnValueSet, result, _om.Collection);
            }

            //Assert
            var output = new Output();

            result.Report(output);
            output.Report.Verify();
        }
예제 #4
0
        public void SubstitutionsReplaceDifferences()
        {
            //Arrange
            var refGuids = GuidArray(3);
            var table1   = _om.Make <SnapshotObjectMother.GuidKeyTable>(GuidArray(4));

            void TakeSnapshot(string name)
            {
                var builder = _om.NewSnapshot(name);

                table1.ToSnapshotTable(builder);
            }

            TakeSnapshot("Before");
            table1[0].Variable = "edited";
            table1[1].Variable = "edited";
            TakeSnapshot("After");

            var before = _om.GetSnapshot("Before");
            var after  = _om.GetSnapshot("After");

            var allDiffs = SnapshotDifferenceCalculator.GetDifferences(_om.Collection, before, after);
            var diffs    = DifferenceRegulator.ExpandDifferences(_om.Collection, allDiffs, before);

            var tables            = diffs.Select(d => d.TableDefinition).ToList();
            var unpredictableCols = UnpredictableColumnLocator.Locate(tables).Single(t => t.Table.TableName == nameof(SnapshotObjectMother.GuidKeyTable));
            var columnValueSets   = UnpredictableValueScanner.Scan(unpredictableCols, diffs);

            //Act
            var result = ValueSubstituter.Substitute(columnValueSets, diffs, _om.Collection);

            //Assert
            var output = new Output();

            result.Report(output);
            output.Report.Verify();
        }
예제 #5
0
        public void SubstitutionCanBeDisabled()
        {
            //Arrange
            var table1    = _om.Make <SnapshotObjectMother.Table>(1, 2, 3, 4, 5);
            var refTable1 = _om.Make <SnapshotObjectMother.ReferencingTable>((1, 1), (2, 1));

            void TakeSnapshot(string name)
            {
                var builder = _om.NewSnapshot(name);

                table1.ToSnapshotTable(builder);
                refTable1.ToSnapshotTable(builder);
            }

            TakeSnapshot("Before");
            refTable1[0].Variable = "edited";
            refTable1[1].Variable = "edited";
            refTable1[0].ParentId = table1[3].Id;
            refTable1[1].ParentId = table1[4].Id;
            TakeSnapshot("After");

            var before = _om.GetSnapshot("Before");
            var after  = _om.GetSnapshot("After");

            var diffs = DifferenceRegulator.ExpandDifferences(_om.Collection, SnapshotDifferenceCalculator.GetDifferences(_om.Collection, before, after), before);

            var tables = diffs.Select(d => d.TableDefinition).ToList();

            //Act
            var result = UnpredictableValueRefiner.Refine(_om.Collection, diffs, false);

            //Assert
            var output = new Output();

            result.Report(output);
            output.Report.Verify();
        }