⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixture.cs

📁 NHibernate NET开发者所需的
💻 CS
字号:
using System.Collections.Generic;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH995
{
	[TestFixture]
	public class Fixture : BugTestCase
	{
		public override string BugNumber
		{
			get
			{
				return "NH995";
			}
		}

		protected override void OnTearDown()
		{
			using (ISession s = OpenSession())
			using(ITransaction tx = s.BeginTransaction())
			{
				s.Delete("from ClassC");
				s.Delete("from ClassB");
				s.Delete("from ClassA");
				tx.Commit();
			}
		}

		[Test]
		public void Test()
		{
			int a_id;
			using(ISession s = OpenSession())
			using(ITransaction tx = s.BeginTransaction())
			{
				// Create an A and save it
				ClassA a = new ClassA();
				a.Name = "a1";
				s.Save(a);

				// Create a B and save it
				ClassB b = new ClassB();
				b.Id = new ClassBId("bbb", a);
				b.SomeProp = "Some property";
				s.Save(b);

				// Create a C and save it
				ClassC c = new ClassC();
				c.B = b;
				s.Save(c);

				tx.Commit();

				a_id = a.Id;
			}

			// Clear the cache
			sessions.Evict(typeof(ClassA));
			sessions.Evict(typeof(ClassB));
			sessions.Evict(typeof(ClassC));
			
			using(ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				// Load a so we can use it to load b
				ClassA a = s.Get<ClassA>(a_id);

				// Load b so b will be in cache
				ClassB b = s.Get<ClassB>(new ClassBId("bbb", a));

				tx.Commit();
			}
			
			using(ISession s = OpenSession())
			using(ITransaction tx = s.BeginTransaction())
			{
				using (SqlLogSpy sqlLogSpy = new SqlLogSpy())
				{
					IList<ClassC> c_list = s.CreateCriteria(typeof (ClassC)).List<ClassC>();
					// make sure we initialize B
					NHibernateUtil.Initialize(c_list[0].B);

					Assert.AreEqual(1, sqlLogSpy.Appender.GetEvents().Length,
					                "Only one SQL should have been issued");
				}

				tx.Commit();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -