コード例 #1
0
		public void CanUseExecuteToSwitchConversation()
		{
			NhConversationContext context = new NhConversationContext();
			var sf = MockRepository.GenerateStub<ISessionFactory>();
			var conv1 = new NhConversation(sf, context);
			var conv2 = new NhConversation(sf, context);

			Assert.That(context.CurrentConversation, Is.Null);
			conv1.Execute(() => Assert.That(context.CurrentConversation, Is.SameAs(conv1)));
			conv2.Execute(() => Assert.That(context.CurrentConversation, Is.SameAs(conv2)));
			Assert.That(context.CurrentConversation, Is.Null);
		}
コード例 #2
0
		public void ScopesAreNotLeaking()
		{
			var sf = MockRepository.GenerateStub<ISessionFactory>();
			var cc = new NhConversationContext();
			var c = new NhConversation(sf, cc);
			WeakReference weakRef = CreateScope(c);
			GC.Collect();
			GC.WaitForPendingFinalizers();
			Assert.That(weakRef.Target, Is.Null);
		}
コード例 #3
0
		public void CanSwitchBetweenConversations()
		{
			NhConversationContext context = new NhConversationContext();
			var sf = MockRepository.GenerateStub<ISessionFactory>();
			var conv1 = new NhConversation(sf, context);
			var conv2 = new NhConversation(sf, context);

			Assert.That(context.CurrentConversation, Is.Null);
			using (conv1.Scope())
			{
				Assert.That(context.CurrentConversation, Is.SameAs(conv1));
				using (conv2.Scope())
				{
					Assert.That(context.CurrentConversation, Is.SameAs(conv2));
				}
				Assert.That(context.CurrentConversation, Is.SameAs(conv1));
			}
			Assert.That(context.CurrentConversation, Is.Null);
		}