public void Test_Nested_Scope_Abort2() { Assert.Throws(Is.InstanceOf <TransactionAbortedException>().Or.InstanceOf <DataAccessTransactionAbortedException>(), () => { var methodName = MethodBase.GetCurrentMethod().Name; using (var scope = new DataAccessScope()) { var child = this.model.Children.Create(); scope.Flush(); using (var inner = new DataAccessScope()) { child.Nickname = methodName; } scope.Flush(); Assert.AreEqual(child.Id, this.model.Children.Single(c => c.Nickname == methodName).Id); scope.Complete(); } }); }
public void Test_Nested_DataAccessScope_Inner_Complete_Calls_DataModelHook(bool flush, bool complete) { using (var outerScope = new DataAccessScope()) { var cat1 = this.model.Cats.Create(); using (var innerScope = new DataAccessScope()) { var cat2 = this.model.Cats.Create(); innerScope.Complete(); } var cat3 = this.model.Cats.Create(); if (flush) { outerScope.Flush(); } if (complete) { outerScope.Complete(); } } Assert.AreEqual(complete ? 1 : 0, this.testDataModelHook.CommitCount); Assert.AreEqual(complete || !flush ? 0 : 1, this.testDataModelHook.RollbackCount); }
public void Test_Distributed_Transaction_DataAccessScope_CreateFlushComplete_Calls_DataModelHook(bool flush, bool complete) { var config2 = this.CreateSqliteClassicInMemoryConfiguration(null); var model2 = DataAccessModel.BuildDataAccessModel <ComplexPrimaryKeyDataAccessModel>(config2); var hook2 = new TestDataModelHook(); model2.AddHook(hook2); model2.Create(DatabaseCreationOptions.IfDatabaseNotExist); using (var scope = new DataAccessScope()) { var cat = this.model.Cats.Create(); var coord = model2.Coordinates.Create(1); Console.WriteLine("==="); if (flush) { scope.Flush(); } if (complete) { scope.Complete(); } } Assert.AreEqual(complete ? 1 : 0, this.testDataModelHook.CommitCount); Assert.AreEqual(complete || !flush ? 0 : 1, this.testDataModelHook.RollbackCount); Assert.AreEqual(complete ? 1 : 0, hook2.CommitCount); Assert.AreEqual(complete || !flush ? 0 : 1, hook2.RollbackCount); }