Пример #1
0
        public async Task ExceptionsInTransactionSynchronizationBeforeTransactionCompletionAbortTransactionAsync()
        {
            var c = new C {
                ID = 1, Value = "value"
            };

            var synchronization = new TransactionSynchronizationThatThrowsExceptionAtBeforeTransactionCompletion();

            using (ISession s = Sfi.OpenSession())
                using (ITransaction t = s.BeginTransaction())
                {
                    t.RegisterSynchronization(synchronization);

                    await(s.SaveAsync(c));

                    Assert.ThrowsAsync <BadException>(() => t.CommitAsync());
                }

            using (ISession s = Sfi.OpenSession())
            {
                var objectInDb = await(s.GetAsync <C>(1));
                Assert.IsNull(objectInDb);
            }
        }
Пример #2
0
        public void ExceptionsInTransactionSynchronizationBeforeTransactionCompletionAbortTransaction()
        {
            var c = new C {
                ID = 1, Value = "value"
            };

            var synchronization = new TransactionSynchronizationThatThrowsExceptionAtBeforeTransactionCompletion();

            using (ISession s = Sfi.OpenSession())
                using (ITransaction t = s.BeginTransaction())
                {
                    t.RegisterSynchronization(synchronization);

                    s.Save(c);

                    Assert.Throws <BadException>(t.Commit);
                }

            using (ISession s = Sfi.OpenSession())
            {
                var objectInDb = s.Get <C>(1);
                Assert.IsNull(objectInDb);
            }
        }