fixture.cs

来自「NHibernate NET开发者所需的」· CS 代码 · 共 70 行

CS
70
字号
using System.Collections;
using NUnit.Framework;

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

		[Test, Ignore("Not supported.")]
		public void ApplyFilterExplicitJoin()
		{
			// Note: if we fix this we must fix it for Criteria too (NH-1293)

			RelatedClass rc1 = new RelatedClass(1);
			RelatedClass rc2 = new RelatedClass(2);
			RelatedClass rc11 = new RelatedClass(1);
			RelatedClass rc12 = new RelatedClass(2);
			RelatedClass rc13 = new RelatedClass(2);

			MainClass[] mc =
				new MainClass[]
					{
						new MainClass("d0", rc1), new MainClass("d0", rc2), new MainClass("d1", rc11), new MainClass("d1", rc12),
						new MainClass("d1", rc13)
					};

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				foreach (MainClass mainClass in mc)
					s.Save(mainClass);

				tx.Commit();
			}

			using (ISession s = OpenSession())
			{
				s.EnableFilter("RelatedClass_Valued").SetParameter("forValue", 2);
				IQuery q =
					s.CreateQuery("select mc.Description, count(mc.Id) from MainClass mc join mc.Related r group by mc.Description order by mc.Description");

				IList l = q.List();
				Assert.AreEqual(2, l.Count);
				Assert.AreEqual(1, (l[0] as IList)[1]);
				Assert.AreEqual(2, (l[1] as IList)[1]);

				s.DisableFilter("RelatedClass_Valued");
				l = q.List();
				Assert.AreEqual(2, l.Count);
				Assert.AreEqual(2, (l[0] as IList)[1]);
				Assert.AreEqual(3, (l[1] as IList)[1]);
			}

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.Delete("from MainClass");
				s.Delete("from RelatedClass");
				tx.Commit();
			}

		}
	}
}

⌨️ 快捷键说明

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