public void DateDiagnosticsAreReported()
        {
            //Arrange
            var collection = new SnapshotCollection();

            var beforeDates = new[]
            {
                DateTime.Parse("2020-10-11 10:35"),
                DateTime.Parse("2020-10-11 10:36"),
                DateTime.Parse("2020-10-11 10:37"),
                DateTime.Parse("2020-10-11 10:38"),
            };

            var afterDates = new[]
            {
                DateTime.Parse("2020-10-11 10:35"),
                DateTime.Parse("2020-10-11 10:36"),
                DateTime.Parse("2020-10-11 10:39"),
                DateTime.Parse("2020-10-11 10:40"),
                DateTime.Parse("2020-10-11 10:41"),
            };

            var beforeBuilder = collection.NewSnapshot("before");

            collection.DefineTable("Dates").PrimaryKey("Key").IsUnpredictable("Date");

            beforeDates.Select((bd, ix) => new { Key = ix, Date = bd, Other = "o", OtherDate = DateTime.MinValue }).ToSnapshotTable(beforeBuilder, "Dates");
            var deleteRow = beforeBuilder.AddNewRow("Dates");

            deleteRow["Key"]       = 100;
            deleteRow["Date"]      = DateTime.Parse("2020-10-18 11:19");
            deleteRow["Other"]     = "o";
            deleteRow["OtherDate"] = DateTime.MinValue;

            var afterBuilder = collection.NewSnapshot("after");

            afterDates.Select((bd, ix) => new { Key = ix, Date = bd, Other = "a", OtherDate = DateTime.MaxValue }).ToSnapshotTable(afterBuilder, "Dates");

            var before      = collection.GetSnapshot("before");
            var after       = collection.GetSnapshot("after");
            var differences = SnapshotDifferenceAnalyser.ExtractDifferences(collection, before, after);

            var output = new Output();

            //Act
            var ranges = new List <NamedTimeRange>
            {
                new NamedTimeRange(beforeDates[0], beforeDates[3], "before"),
                new NamedTimeRange(afterDates[2], afterDates[3], "after"),
            };

            DateDiagnosticReporter.Report(output, ranges, before, after, differences);

            //Assert
            output.Report.Verify();
        }
Example #2
0
        public void SnapshotHasTimestamp()
        {
            //Arrange
            _collection.NewSnapshot("Test");

            //Act
            var snapshot = _collection.GetSnapshot("Test");

            //Assert
            snapshot.SnapshotTimestamp.Should().BeAfter(DateTime.MinValue);
        }
Example #3
0
        public void SubstitutionsCanBeSuppressed()
        {
            //Arrange
            var collection = new SnapshotCollection();

            collection.DefineTable("TheTable")
            .PrimaryKey("Id")
            .IsUnpredictable("Id");

            void AddRow(SnapshotBuilder snapshot, int id, string name)
            {
                var add = snapshot.AddNewRow("TheTable");

                add["Id"]   = id;
                add["Name"] = name;
            }

            void AddData(SnapshotBuilder snapshot, string names)
            {
                var id = 1;

                foreach (var name in names.Split(','))
                {
                    AddRow(snapshot, id++, name);
                }
            }

            var beforeBuilder = collection.NewSnapshot("Before");

            AddData(beforeBuilder, "A,B,C");

            var afterBuilder = collection.NewSnapshot("After");

            AddData(afterBuilder, "D,E,F");

            var before = collection.GetSnapshot("Before");
            var after  = collection.GetSnapshot("After");
            var diffs  = SnapshotDifferenceAnalyser.ExtractDifferences(collection, before, after, ChangeReportOptions.NoSubs);

            //Act
            var result = SnapshotDifferenceSorter.SortDifferences(collection, diffs.TableDifferences.ToList());

            //Assert
            var output = new Output();

            result.Report(output);
            output.Report.Verify();
        }
Example #4
0
        public void SnapshotRowsInMissingTablesAreNull()
        {
            //Arrange
            var snapshots = new SnapshotCollection(GetType(), t => t != typeof(Snapshots.TestDefinitions.TableDef));

            snapshots.DefineTable("Customer")
            .PrimaryKey("Id")
            .CompareKey("Surname")
            .IsUnpredictable("Id");

            var builder    = snapshots.NewSnapshot("Before");
            var rowBuilder = builder.AddNewRow("Customer");

            rowBuilder["Id"]      = 1;
            rowBuilder["Surname"] = "surname";

            var snapshot = snapshots.GetSnapshot("Before");

            //Act
            var row    = snapshot.Rows("Customer").First();
            var result = snapshot.GetRow(new SnapshotRowKey(row, snapshots.GetTableDefinition("Customer")), "Wrong");

            //Assert
            result.Should().BeNull();
        }
 internal TestData()
 {
     _collection = new SnapshotCollection();
     Definer     = _collection.DefineTable(TableName);
     Builder     = _collection.NewSnapshot("Test");
     Snapshot    = _collection.GetSnapshot("Test");
     NewRow();
 }
Example #6
0
        public void DifferenceDataIsSortedDescending()
        {
            //Arrange
            var collection = new SnapshotCollection();

            collection.DefineTable("TheTable").PrimaryKey("Id").SortDescending("Name");

            void AddRow(SnapshotBuilder snapshot, int id, string name)
            {
                var add = snapshot.AddNewRow("TheTable");

                add["Id"]   = id;
                add["Name"] = name;
            }

            var beforeBuilder = collection.NewSnapshot("Before");

            AddRow(beforeBuilder, 1, "Alice");
            AddRow(beforeBuilder, 2, "Xavier");
            AddRow(beforeBuilder, 3, "Zed");

            var afterBuilder = collection.NewSnapshot("After");

            AddRow(afterBuilder, 1, "Alice+");
            AddRow(afterBuilder, 2, "Xavier+");
            AddRow(afterBuilder, 3, "Zed+");

            var before = collection.GetSnapshot("Before");
            var after  = collection.GetSnapshot("After");
            var diffs  = SnapshotDifferenceAnalyser.ExtractDifferences(collection, before, after);

            //Act
            var result = SnapshotDifferenceSorter.SortDifferences(collection, diffs.TableDifferences.ToList());

            //Assert
            var output = new Output();

            result.Report(output);
            output.Report.Verify();
        }
Example #7
0
        private Snapshot MakeSnapshot(string name, int startRow = 1, int numRows = 10, IEnumerable <object[]> rowValues = null)
        {
            var rowValuesList = rowValues?.ToList() ?? new List <object[]>();
            var builder       = _collection.NewSnapshot(name);

            for (var n = startRow; n < startRow + numRows; n++)
            {
                var cpRow  = builder.AddNewRow(TableName);
                var values = n - startRow < rowValuesList.Count ? rowValuesList[n - startRow] : null;
                PopulateRow(n, cpRow, values);
            }

            return(_collection.GetSnapshot(name));
        }
Example #8
0
        public void GetSnapshotReturnsTheRequestedSnapshot()
        {
            //Arrange/Act
            var snapshots = new SnapshotCollection(GetType(), t => t != typeof(Snapshots.TestDefinitions.TableDef));

            snapshots.DefineTable("Customer")
            .PrimaryKey("Id")
            .CompareKey("Surname")
            .IsUnpredictable("Id");

            var builder = snapshots.NewSnapshot("Before");

            //Assert
            snapshots.GetSnapshot("Before").Name.Should().Be("Before");
        }
Example #9
0
        public void SetUp()
        {
            _collection = new SnapshotCollection();
            _collection.DefineTable(CompareKeyTableName).CompareKey(NameCol).PrimaryKey(IdCol);
            _collection.DefineTable(PrimaryKeyTableName).PrimaryKey(IdCol);
            _collection.DefineTable(CompoundKeyTableName).PrimaryKey(IdCol).PrimaryKey(NameCol);
            var builder = _collection.NewSnapshot("Test");

            for (var n = 1; n <= 10; n++)
            {
                var ckRow = builder.AddNewRow(CompareKeyTableName);
                var pkRow = builder.AddNewRow(PrimaryKeyTableName);
                var cpRow = builder.AddNewRow(CompoundKeyTableName);
                PopulateRows(n, ckRow, pkRow, cpRow);
            }

            _snapshot = _collection.GetSnapshot("Test");
        }
        public void CollectionsCanBePlacedInSnapshots()
        {
            //Arrange
            var data = new[]
            {
                new { A = 1, B = "Bee", C = 5.5 },
                new { A = 2, B = "Cee", C = 6.6 },
                new { A = 3, B = "Dee", C = 7.7 },
                new { A = 4, B = "Eee", C = 8.8 },
                new { A = 5, B = "Eff", C = 9.9 },
            };

            var snapshot = _collection.NewSnapshot("Test");

            //Act
            data.ToSnapshotTable(snapshot, "Data");

            //Assert
            var output = new Output();

            _collection.GetSnapshot("Test").ReportContents(output);
            output.Report.Verify();
        }
Example #11
0
        public void DifferenceDataIsSortedByMultipleColumns()
        {
            //Arrange
            var collection = new SnapshotCollection();

            collection.DefineTable("TheTable")
            .PrimaryKey("Id")
            .Sort("ColAsc1")
            .SortDescending("ColDesc1")
            .Sort("ColAsc2")
            .SortDescending("ColDesc2");

            void AddRow(SnapshotBuilder snapshot, int id, string asc1, string desc1, string asc2, string desc2)
            {
                var add = snapshot.AddNewRow("TheTable");

                add["Id"]       = id;
                add["ColAsc1"]  = asc1;
                add["ColDesc1"] = desc1;
                add["ColAsc2"]  = asc2;
                add["ColDesc2"] = desc2;
            }

            void AddData(SnapshotBuilder snapshot, string ascData, string descData)
            {
                var id = 1;

                foreach (var colAsc1 in ascData.Split(','))
                {
                    foreach (var colDesc1 in descData.Split(','))
                    {
                        foreach (var colAsc2 in ascData.Split(','))
                        {
                            foreach (var colDesc2 in descData.Split(','))
                            {
                                AddRow(snapshot, id++, colAsc1, colDesc1, colAsc2, colDesc2);
                            }
                        }
                    }
                }
            }

            var beforeBuilder = collection.NewSnapshot("Before");

            AddData(beforeBuilder, "A,B,C", "C,B,A");

            var afterBuilder = collection.NewSnapshot("After");

            AddData(afterBuilder, "A+,B+,C+", "C+,B+,A+");

            var before = collection.GetSnapshot("Before");
            var after  = collection.GetSnapshot("After");
            var diffs  = SnapshotDifferenceAnalyser.ExtractDifferences(collection, before, after);

            //Act
            var result = SnapshotDifferenceSorter.SortDifferences(collection, diffs.TableDifferences.ToList());

            //Assert
            var output = new Output();

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