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(); }
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(); }
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(); }