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

📄 projectionfixture.cs

📁 NHibernate NET开发者所需的
💻 CS
字号:
using NHibernate.DomainModel;
using NHibernate.Criterion;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NUnit.Framework;

namespace NHibernate.Test.ExpressionTest.Projection
{
	using Util;

	[TestFixture]
	public class ProjectionFixture : BaseExpressionFixture
	{
		[Test]
		public void RowCountTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.RowCount();
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string,IFilter>());
			string expectedSql = "count(*) as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void AvgTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Avg("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "avg(sql_alias.Pay) as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void MaxTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Max("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "max(sql_alias.Pay) as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void MinTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Min("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "min(sql_alias.Pay) as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void CountTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Count("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "count(sql_alias.Pay) as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void CountDistinctTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.CountDistinct("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "count(distinct sql_alias.Pay) as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void DistinctTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Distinct(Projections.Property("Pay"));
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "distinct sql_alias.Pay as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void GroupPropertyTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.GroupProperty("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "sql_alias.Pay as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			SqlString groupSql = expression.ToGroupSqlString(criteria, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedGroupSql = "sql_alias.Pay";
			CompareSqlStrings(groupSql, expectedGroupSql);
			session.Close();
		}

		[Test]
		public void IdTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Id();
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "sql_alias.id_ as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void PropertyTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Property("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "sql_alias.Pay as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void SqlGroupProjectionTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.SqlGroupProjection("count(Pay)", "Pay",
			                                                        new string[] {"PayCount"},
			                                                        new IType[] {NHibernateUtil.Double}
				);
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "count(Pay)";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void SqlProjectionTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.SqlProjection("count(Pay)",
			                                                   new string[] {"CountOfPay"}, new
			                                                                                	IType[] {NHibernateUtil.Double});
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "count(Pay)";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}

		[Test]
		public void SumTest()
		{
			ISession session = factory.OpenSession();
			IProjection expression = Projections.Sum("Pay");
			CreateObjects(typeof(Simple), session);
			SqlString sqlString = expression.ToSqlString(criteria, 0, criteriaQuery, new CollectionHelper.EmptyMapClass<string, IFilter>());
			string expectedSql = "sum(sql_alias.Pay) as y0_";
			CompareSqlStrings(sqlString, expectedSql, 0);
			session.Close();
		}
	}
}

⌨️ 快捷键说明

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