コード例 #1
0
		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));
		}
コード例 #2
0
		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"));
		}
コード例 #3
0
		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);
		}
コード例 #4
0
		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());
		}
コード例 #5
0
		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);
		}