Exemplo n.º 1
0
        public void FetchIsCaughtByTracking()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
                prepdb.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                db.SingleById <SampleRecord>(1, 2);
            }

            // --- Assert
            var tableChangeSet  = changeSet["[dbo].[sample]"];
            var recordChangeSet = tableChangeSet[new PrimaryKeyValue(new List <object> {
                1, 2
            })];

            recordChangeSet.State.ShouldEqual(ChangedRecordState.Attached);
            recordChangeSet.IssueList.ShouldHaveCountOf(0);
            recordChangeSet.ShouldHaveCountOf(0);
        }
Exemplo n.º 2
0
        public void TrackingWorksWithAbortedNestedTransactions()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
                prepdb.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                db.BeginTransaction();
                var record = db.SingleById <SampleRecord>(1, 2);
                record.Description = "New description";
                db.BeginTransaction();
                db.Update(record);
                db.AbortTransaction();
                record.Name = "New name";
                db.BeginTransaction();
                db.Update(record);
                db.CompleteTransaction();
                db.CompleteTransaction();
            }

            // --- Assert
            changeSet.ContainsKey("[dbo].[sample]").ShouldBeFalse();
        }
Exemplo n.º 3
0
        public void EliminateNonChangedTablesWorksAsExpected()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
                prepdb.Execute(CREATE_SAMPLE_TABLE_1);
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                db.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
                db.Insert(new SampleRecord1 {
                    Id = 2, Name = "Sample1"
                });
                db.DeleteById <SampleRecord>(1, 2);
            }

            // --- Assert
            changeSet.ContainsKey("[dbo].[sample]").ShouldBeFalse();
            changeSet.ContainsKey("[dbo].[sample1]").ShouldBeTrue();
        }
Exemplo n.º 4
0
        public void TrackingWorksWithMultipleTransactions()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
                prepdb.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                var record = db.SingleById <SampleRecord>(1, 2);
                record.Description = "New description";
                db.BeginTransaction();
                db.Update(record);
                db.AbortTransaction();
                record.Name = "New name";
                db.BeginTransaction();
                db.Insert(new SampleRecord {
                    Id1 = 2, Id2 = 3, Name = "Second"
                });
                db.CompleteTransaction();
            }

            // --- Assert
            var tableChangeSet  = changeSet["[dbo].[sample]"];
            var recordChangeSet = tableChangeSet[new PrimaryKeyValue(new List <object> {
                2, 3
            })];

            recordChangeSet.State.ShouldEqual(ChangedRecordState.Inserted);
            recordChangeSet.IssueList.ShouldHaveCountOf(0);
            recordChangeSet.ShouldHaveCountOf(3);
            recordChangeSet["Id1"].PreviousValue.ShouldBeNull();
            recordChangeSet["Id1"].NewValue.ShouldEqual(2);
            recordChangeSet["Id2"].PreviousValue.ShouldBeNull();
            recordChangeSet["Id2"].NewValue.ShouldEqual(3);
            recordChangeSet["Name"].PreviousValue.ShouldBeNull();
            recordChangeSet["Name"].NewValue.ShouldEqual("Second");
        }
Exemplo n.º 5
0
        public void UpdateAfterDeleteRaisesAnIssue()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
                prepdb.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                db.DeleteById <SampleRecord>(1, 2);
                var record = new SampleRecord();
                ((IDataRecord)record).SignLoaded();
                record.Id1  = 1;
                record.Id2  = 2;
                record.Name = "First";
                db.Update(record);
            }

            // --- Assert
            var tableChangeSet  = changeSet["[dbo].[sample]"];
            var recordChangeSet = tableChangeSet[new PrimaryKeyValue(new List <object> {
                1, 2
            })];

            recordChangeSet.State.ShouldEqual(ChangedRecordState.Deleted);
            recordChangeSet.IssueList.ShouldHaveCountOf(2);
            recordChangeSet.IssueList[1].Description.ShouldContainIgnoringCase("has already been deleted");
            recordChangeSet.ShouldHaveCountOf(3);
            recordChangeSet["Id1"].PreviousValue.ShouldEqual(1);
            recordChangeSet["Id1"].NewValue.ShouldBeNull();
            recordChangeSet["Id2"].PreviousValue.ShouldEqual(2);
            recordChangeSet["Id2"].NewValue.ShouldBeNull();
            recordChangeSet["Name"].PreviousValue.ShouldEqual("First");
            recordChangeSet["Name"].NewValue.ShouldBeNull();
        }
Exemplo n.º 6
0
        public void DeleteAfterUpdateIsCaughtByTracking()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
                prepdb.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                var record = db.SingleById <SampleRecord>(1, 2);
                record.Name        = "New name";
                record.Description = "New description";
                db.Update(record);
                db.Delete(record);
            }

            // --- Assert
            var tableChangeSet  = changeSet["[dbo].[sample]"];
            var recordChangeSet = tableChangeSet[new PrimaryKeyValue(new List <object> {
                1, 2
            })];

            recordChangeSet.State.ShouldEqual(ChangedRecordState.Deleted);
            recordChangeSet.IssueList.ShouldHaveCountOf(0);
            recordChangeSet.ShouldHaveCountOf(4);
            recordChangeSet["Id1"].PreviousValue.ShouldEqual(1);
            recordChangeSet["Id1"].NewValue.ShouldBeNull();
            recordChangeSet["Id2"].PreviousValue.ShouldEqual(2);
            recordChangeSet["Id2"].NewValue.ShouldBeNull();
            recordChangeSet["Name"].PreviousValue.ShouldEqual("New name");
            recordChangeSet["Name"].NewValue.ShouldBeNull();
            recordChangeSet["Description"].PreviousValue.ShouldEqual("New description");
            recordChangeSet["Description"].NewValue.ShouldBeNull();
        }
Exemplo n.º 7
0
        public void SecondInsertRaisesAnIssue()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                db.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
                db.Execute("delete from sample where Id1=1 and Id2=2");
                db.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
            }

            // --- Assert
            var tableChangeSet  = changeSet["[dbo].[sample]"];
            var recordChangeSet = tableChangeSet[new PrimaryKeyValue(new List <object> {
                1, 2
            })];

            recordChangeSet.State.ShouldEqual(ChangedRecordState.Inserted);
            recordChangeSet.IssueList.ShouldHaveCountOf(1);
            recordChangeSet.IssueList[0].Description.ShouldContainIgnoringCase("has already been attached");
            recordChangeSet.ShouldHaveCountOf(3);
            recordChangeSet["Id1"].PreviousValue.ShouldBeNull();
            recordChangeSet["Id1"].NewValue.ShouldEqual(1);
            recordChangeSet["Id2"].PreviousValue.ShouldBeNull();
            recordChangeSet["Id2"].NewValue.ShouldEqual(2);
            recordChangeSet["Name"].PreviousValue.ShouldBeNull();
            recordChangeSet["Name"].NewValue.ShouldEqual("First");
        }
Exemplo n.º 8
0
        public void DeleteAfterInsertIsCaughtByTracking()
        {
            // --- Arrange
            using (var prepdb = new SqlDatabase(DB_CONN))
            {
                prepdb.Execute(CREATE_SAMPLE_TABLE);
            }

            // --- Act
            SqlDatabaseChangeSet changeSet = null;

            using (var db = new SqlDatabase(DB_CONN, SqlOperationMode.Tracked))
            {
                db.TrackingCompleted += (sender, e) => { changeSet = e.ChangeSet; };
                db.Insert(new SampleRecord {
                    Id1 = 1, Id2 = 2, Name = "First"
                });
                var record = db.SingleById <SampleRecord>(1, 2);
                db.Delete(record);
            }

            // --- Assert
            changeSet.ContainsKey("[dbo].[sample]").ShouldBeFalse();
        }
 /// <summary>
 /// Initializes the event args with the specified change set
 /// </summary>
 /// <param name="changeSet"></param>
 public TrackingInfoEventArgs(SqlDatabaseChangeSet changeSet)
 {
     ChangeSet = changeSet;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes the event args with the specified change set
 /// </summary>
 /// <param name="changeSet"></param>
 public TrackingInfoEventArgs(SqlDatabaseChangeSet changeSet)
 {
     ChangeSet = changeSet;
 }