public void CancelingRaisesEvent() { var sf = MockRepository.GenerateStub<ISessionFactory>(); var cc = MockRepository.GenerateStub<INhConversationContext>(); var c = new NhConversation(sf, cc); ConversationCanceledEventArgs eventRaised = null; object eventRaiser = null; c.Canceled += (o, a) => { eventRaiser = o; eventRaised = a; }; c.Cancel(); Assert.That(eventRaised, Is.Not.Null); Assert.That(eventRaised.CanceledByUser); Assert.That(eventRaised.Exception, Is.Null); Assert.That(eventRaiser, Is.SameAs(c)); }
public void CannotCallExecuteWhenConversationIsCanceled() { var sf = MockRepository.GenerateStub<ISessionFactory>(); var cc = MockRepository.GenerateStub<INhConversationContext>(); var c = new NhConversation(sf, cc); c.Cancel(); var e = Assert.Throws<InvalidOperationException>(() => c.Execute(() => { ; })); // Call doesn't matter, it's a stub Assert.That(e.Message, Contains.Substring("canceled")); }
public void CancelStateCanBeQueried() { var sf = MockRepository.GenerateStub<ISessionFactory>(); var cc = MockRepository.GenerateStub<INhConversationContext>(); var c = new NhConversation(sf, cc); c.Cancel(); Assert.That(c.IsCanceled); }
public void CantCommitAfterCanceling() { var sf = MockRepository.GenerateStub<ISessionFactory>(); var cc = MockRepository.GenerateStub<INhConversationContext>(); var c = new NhConversation(sf, cc); c.Cancel(); Assert.Throws<InvalidOperationException>(() => c.Commit()); }
public void RestartingTheConversationResetsCancelState() { var t = MockRepository.GenerateStub<ITransaction>(); var s = MockRepository.GenerateStub<ISession>(); var sf = MockRepository.GenerateStub<ISessionFactory>(); var cc = MockRepository.GenerateStub<INhConversationContext>(); sf.Stub(x => x.OpenSession()).Return(s); s.Stub(x => x.BeginTransaction()).IgnoreArguments().Return(t); var c = new NhConversation(sf, cc); c.Cancel(); c.Restart(); bool called = false; c.Execute(x => called = true); // Call doesn't matter, it's a stub Assert.That(called); }