Dispose() публичный Метод

public Dispose ( ) : void
Результат void
Пример #1
0
        public virtual void ShouldCallRealDisposeOnlyOnce()
        {
            var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New);
            var sessionBuilder = new Lazy<IDataSession>(() => session, false);
            var policy = new ImmediateTerminationPolicy();

            var context = new DataContext(config, sessionBuilder, policy);

            Awaken(context);

            context.Dispose();
            context.Dispose();

            session.Received(1).Dispose();
        }
Пример #2
0
        public virtual void ShouldThrowExceptionOnSessionCallIfDisposeHasAlreadyBeenCalled()
        {
            var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New);
            var sessionBuilder = new Lazy<IDataSession>(() => session, false);
            var policy = new ImmediateTerminationPolicy();

            var context = new DataContext(config, sessionBuilder, policy);
            context.Dispose();
            Awaken(context);
        }
Пример #3
0
        public virtual void ShouldReplaceFinishedEventInSubordinate()
        {
            var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New);
            var sessionBuilder = new Lazy<IDataSession>(() => session, false);
            var policy = new ImmediateTerminationPolicy();

            var called = false;

            var context = new DataContext(config, sessionBuilder, policy);

            var subordinate = new DataContext.Subordinate(context);

            Awaken(subordinate);

            ((IDataContext)subordinate).Finished += (sender, e) => { called = true; };

            context.Dispose();

            called.Should().Be.True();

            session.Received(1).Dispose();

            session.ClearReceivedCalls();

            called = false;
            context = new DataContext(config, sessionBuilder, policy);
            subordinate = new DataContext.Subordinate(context);

            Awaken(subordinate);

            EventHandler<FinishedEventArgs> eventHandler = (sender, e) => { called = true; };
            ((IDataContext)subordinate).Finished += eventHandler;
            ((IDataContext)subordinate).Finished -= eventHandler;
            context.Dispose();
            session.Received(1).Dispose();
            called.Should().Be.False();
        }
Пример #4
0
        public virtual void ShouldRaiseFinishedEventDuringDispose()
        {
            var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New);
            var sessionBuilder = new Lazy<IDataSession>(() => session, false);
            var policy = new ImmediateTerminationPolicy();

            bool? success = null;

            var context = new DataContext(config, sessionBuilder, policy);

            Awaken(context);

            context.Finished += (sender, e) =>
            {
                success = e.Completed;
                session.Received(0).Dispose();
            };

            context.Dispose();

            session.Received(1).Dispose();
            success.Should().Not.Be(null);
            success.Should().Be.EqualTo(false);

            session.ClearReceivedCalls();

            success = null;

            context = new DataContext(config, sessionBuilder, policy);

            Awaken(context);

            context.Finished += (sender, e) =>
            {
                success = e.Completed;
                session.Received(0).Dispose();
                session.Received(1).Complete();
            };
            context.Complete();
            context.Dispose();
            success.Should().Not.Be(null);
            success.Should().Be.EqualTo(true);
            session.Received(1).Dispose();

            session.ClearReceivedCalls();
        }
Пример #5
0
        public virtual void ShouldThrowExceptionIfCompleteCalledAfterDispose()
        {
            Assert.That(
                () =>
                {
                    var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New);
                    var sessionBuilder = new Lazy<IDataSession>(() => session, false);
                    var policy = new ImmediateTerminationPolicy();

                    var context = new DataContext(config, sessionBuilder, policy);
                    Awaken(context);
                    context.Dispose();
                    context.Complete();
                }, 
                Throws.Exception.With.Message.EqualTo("Data context has already been disposed(with success - 'False'), so it is not usable anymore."));

            session.Received(1).Dispose();
            session.Received(0).Complete();
        }
Пример #6
0
        public virtual void ShouldNotCallRealDisposeIfSessionHasNotBeenUsed()
        {
            var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New);
            var sessionBuilder = new Lazy<IDataSession>(() => session, false);
            var policy = new ImmediateTerminationPolicy();

            var context = new DataContext(config, sessionBuilder, policy);

            context.Dispose();
            context.Dispose();

            session.DidNotReceive().Complete();
        }