public virtual void ShouldCallRealCompleteOnlyOnce() { var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New); var sessionBuilder = new Lazy<IDataSession>(() => session, false); var policy = new ImmediateTerminationPolicy(); using (var context = new DataContext(config, sessionBuilder, policy)) { Awaken(context); context.Complete(); context.Complete(); } session.Received(1).Complete(); }
public virtual void ShouldNotCallRealCompleteIfSessionHasNotBeenUsed() { var config = new UnitOfWorkConfig(string.Empty, IsolationLevel.ReadCommitted, Require.New); var sessionBuilder = new Lazy<IDataSession>(() => session, false); var policy = new ImmediateTerminationPolicy(); using (var context = new DataContext(config, sessionBuilder, policy)) { context.Complete(); } session.DidNotReceive().Complete(); }
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(); }
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(); }