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();
        }
Exemplo n.º 2
0
        public void SnapshotHasTimestamp()
        {
            //Arrange
            _collection.NewSnapshot("Test");

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

            //Assert
            snapshot.SnapshotTimestamp.Should().BeAfter(DateTime.MinValue);
        }
Exemplo n.º 3
0
        public void SubstitutionsCanBeDisabledInDiffReports()
        {
            //Arrange
            var snapshots = new SnapshotCollection();

            snapshots.DefineTable("Customer")
            .PrimaryKey("Id")
            .CompareKey("Surname")
            .IsUnpredictable("Id");
            snapshots.DefineTable("Address")
            .PrimaryKey("AddressId")
            .IsUnpredictable("AddressId")
            .IsReference("CustomerId", "Customer", "Id");

            var customers = new[]
            {
                new { Id = 1, Surname = "S1", FirstName = "F1", Age = 40 },
                new { Id = 2, Surname = "S2", FirstName = "F2", Age = 45 },
                new { Id = 3, Surname = "S3", FirstName = "F3", Age = 50 },
            };

            var addresses = new[]
            {
                new { AddressId = 102, CustomerId = 1, House = 15, Street = "Line 1", PostCode = "code1" },
                new { AddressId = 193, CustomerId = 2, House = 99, Street = "Line 2", PostCode = "code2" },
                new { AddressId = 6985, CustomerId = 3, House = 8000, Street = "Line 3", PostCode = "code3" }
            };

            {
                var builder = snapshots.NewSnapshot("Before");
                customers.ToSnapshotTable(builder, "Customer");
                addresses.ToSnapshotTable(builder, "Address");
            }

            customers[1] = new { Id = 2, Surname = "S2", FirstName = "F2Edited", Age = 32 };
            addresses[2] = new { AddressId = 6985, CustomerId = 2, House = 8001, Street = "Line 3", PostCode = "code3" };

            {
                var builder2 = snapshots.NewSnapshot("After");
                customers.ToSnapshotTable(builder2, "Customer");
                addresses.ToSnapshotTable(builder2, "Address");
            }

            //Act/Assert
            var output = new Output();

            snapshots.ReportChanges("Before", "After", output, ChangeReportOptions.NoSubs);
            output.Report.Verify();
        }
Exemplo n.º 4
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();
        }
 public void SetUp()
 {
     _collection = new SnapshotCollection();
     _collection.DefineTable(TableName).PrimaryKey(IdCol).PrimaryKey(NameCol);
     _tableDef        = _collection.GetTableDefinition(TableName);
     _snapshotBuilder = _collection.NewSnapshot("Test");
 }
Exemplo n.º 6
0
 public void SetUp()
 {
     _collection = new SnapshotCollection();
     _collection.DefineTable("Test").CompareKey("Key");
     _snapshot = _collection.NewSnapshot("TestSnapshot");
     _row      = _snapshot.AddNewRow("Test");
 }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
        public void ReportChangesThrowsWhenAfterSnapshotNotPresent()
        {
            //Arrange/Act
            var snapshots = new SnapshotCollection(GetType(), t => t != typeof(Snapshots.TestDefinitions.TableDef));

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

            var customers = new[]
            {
                new { Id = 1, Surname = "S1", FirstName = "F1", Age = 40 },
            };
            var builder = snapshots.NewSnapshot("Before");

            customers.ToSnapshotTable(builder, "Customer");

            var output = new Output();

            //Assert
            Action action = () => snapshots.ReportChanges("Before", "After", output);

            action.Should().Throw <SnapshotNotFoundException>().Where(x => x.SnapshotName == "After");
        }
 internal TestData()
 {
     _collection = new SnapshotCollection();
     Definer     = _collection.DefineTable(TableName);
     Builder     = _collection.NewSnapshot("Test");
     Snapshot    = _collection.GetSnapshot("Test");
     NewRow();
 }
Exemplo n.º 10
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();
        }
        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();
        }
Exemplo n.º 12
0
 public SnapshotBuilder Snapshot(string snapshotName, SnapshotOptions snapshotOpts = SnapshotOptions.Default)
 {
     lock (_lock)
     {
         ConfigureCollection();
         var builder = _collection.NewSnapshot(snapshotName);
         if ((snapshotOpts & SnapshotOptions.NoAutoSnapshot) == 0)
         {
             DbSnapshotMaker.Make(_connectionString, builder, _schemas.Values, _collection);
         }
         _snapshotTaken = true;
         return(builder);
     }
 }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
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");
        }
        public void SetUp()
        {
            _collection = new SnapshotCollection();
            _collection.DefineTable(TestTableName).CompareKey("Id");
            _table    = _collection.GetTableDefinition(TestTableName);
            _snapshot = _collection.NewSnapshot("Test");

            //Borrow a column config so that we can test with it.
            void ExtractColumnDefForTest(ColumnConfig config)
            {
                _cc = config;
            }

            var report = new[] { "T" }.AsReport(rep => rep.AddColumn(t => t, ExtractColumnDefForTest));
        }
Exemplo n.º 16
0
        public void SnapshotThrowsWhenUndefinedTableUsed()
        {
            //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
            Action action = () => builder.AddNewRow("Wrong");

            action.Should().Throw <UndefinedTableInSnapshotException>().Where(x => x.TableName == "Wrong");
        }
Exemplo n.º 17
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");
        }
Exemplo n.º 18
0
        public void TableContentsAreAddedToSnapshot()
        {
            //Arrange
            var collection = new SnapshotCollection();
            var schema     = SchemaStructureLoader.Load(DbController.Server, DbController.TestDbName, "Test");
            var builder    = collection.NewSnapshot("Test");

            SnapshotTableDefiner.Define(collection, schema);

            //Act
            DbSnapshotMaker.Make(DbController.ConnectionString, builder, new [] { schema }, collection);

            //Assert
            var output = new Output();

            collection.GetSnapshotReport("Test", output);
            output.Report.Verify();
        }
Exemplo n.º 19
0
        public void CustomWhereClauseIsLoadedFromDefinition()
        {
            //Arrange
            var collection = new SnapshotCollection();
            var schema     = SchemaStructureLoader.Load(DbController.Server, DbController.TestDbName, "Test");
            var builder    = collection.NewSnapshot("Test");

            SnapshotTableDefiner.Define(collection, schema);
            var definitions = SnapshotDefinitionLoader.Load(GetType());

            collection.ApplyDefinitions(definitions);

            //Act
            DbSnapshotMaker.Make(DbController.ConnectionString, builder, new [] { schema }, collection);

            //Assert
            var output = new Output();

            collection.GetSnapshotReport("Test", output);
            output.Report.Verify();
        }
Exemplo n.º 20
0
        public void ExcludedColumnsAreNotAddedToSnapshot()
        {
            //Arrange
            var collection = new SnapshotCollection();
            var schema     = SchemaStructureLoader.Load(DbController.Server, DbController.TestDbName, "Test");
            var builder    = collection.NewSnapshot("Test");

            SnapshotTableDefiner.Define(collection, schema);
            collection.DefineTable("[Test].[B_Related]").Exclude("Name");

            //Act
            DbSnapshotMaker.Make(DbController.ConnectionString, builder, new [] { schema }, collection);

            //Assert
            var output = new Output();

            output.WrapLine("The Name column should not be present in [Test].[B_Related] below:");
            output.WriteLine();
            collection.GetSnapshotReport("Test", output);
            output.Report.Verify();
        }
Exemplo n.º 21
0
        public void SelectedSnapshotContentsCanBeReported()
        {
            //Arrange
            var snapshots = new SnapshotCollection();

            snapshots.DefineTable("Customer")
            .PrimaryKey("Id")
            .CompareKey("Surname")
            .IsUnpredictable("Id");
            snapshots.DefineTable("Address")
            .PrimaryKey("AddressId")
            .IsUnpredictable("AddressId")
            .IsReference("CustomerId", "Customer", "Id");

            var customers = new[]
            {
                new { Id = 1, Surname = "S1", FirstName = "F1", Age = 40 },
                new { Id = 2, Surname = "S2", FirstName = "F2", Age = 45 },
                new { Id = 3, Surname = "S3", FirstName = "F3", Age = 50 },
            };

            var addresses = new[]
            {
                new { AddressId = 102, CustomerId = 1, House = 15, Street = "Line 1", PostCode = "code1" },
                new { AddressId = 193, CustomerId = 2, House = 99, Street = "Line 2", PostCode = "code2" },
                new { AddressId = 6985, CustomerId = 3, House = 8000, Street = "Line 3", PostCode = "code3" }
            };

            {
                var builder = snapshots.NewSnapshot("Before");
                customers.ToSnapshotTable(builder, "Customer");
                addresses.ToSnapshotTable(builder, "Address");
            }

            //Act/Assert
            var output = new Output();

            snapshots.GetSnapshotReport("Before", output, "Address");
            output.Report.Verify();
        }
Exemplo n.º 22
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();
        }