public void NoTransaction()
        {
            var interceptor     = new RecordingInterceptor();
            var synchronisation = new Synchronization();

            using (var session = Sfi.WithOptions().Interceptor(interceptor).OpenSession())
            {
                session.Transaction.RegisterSynchronization(synchronisation);
                Assert.That(interceptor.afterTransactionBeginCalled, Is.EqualTo(0), "interceptor begin");
                Assert.That(interceptor.beforeTransactionCompletionCalled, Is.EqualTo(0), "interceptor before");
                Assert.That(interceptor.afterTransactionCompletionCalled, Is.EqualTo(0), "interceptor after");
            }
            Assert.That(synchronisation.BeforeExecutions, Is.EqualTo(0), "sync before");
            Assert.That(synchronisation.AfterExecutions, Is.EqualTo(0), "sync after");
        }
Пример #2
0
        public async Task RollbackAsync()
        {
            var interceptor = new RecordingInterceptor();

            using (var session = Sfi.WithOptions().Interceptor(interceptor).OpenSession())
                using (var tx = session.BeginTransaction())
                {
                    var synchronisation = new Synchronization();
                    tx.RegisterSynchronization(synchronisation);
                    await(tx.RollbackAsync());
                    Assert.That(interceptor.afterTransactionBeginCalled, Is.EqualTo(1), "interceptor begin");
                    Assert.That(interceptor.beforeTransactionCompletionCalled, Is.EqualTo(0), "interceptor before");
                    Assert.That(interceptor.afterTransactionCompletionCalled, Is.EqualTo(1), "interceptor after");
                    Assert.That(synchronisation.BeforeExecutions, Is.EqualTo(0), "sync before");
                    Assert.That(synchronisation.AfterExecutions, Is.EqualTo(1), "sync after");
                }
        }
        public void ShouldNotifyAfterTransaction(bool usePrematureClose)
        {
            var      interceptor     = new RecordingInterceptor();
            var      synchronisation = new Synchronization();
            ISession s;

            using (s = OpenSession(interceptor))
                using (var t = s.BeginTransaction())
                {
                    t.RegisterSynchronization(synchronisation);
                    s.CreateCriteria <object>().List();

                    // Call session close while still inside transaction?
                    if (usePrematureClose)
                    {
                        s.Close();
                    }
                }

            Assert.That(s.IsOpen, Is.False);
            Assert.That(interceptor.afterTransactionCompletionCalled, Is.EqualTo(1), "interceptor");
            Assert.That(synchronisation.AfterExecutions, Is.EqualTo(1), "sync");
        }