diff UnitTests/CS/DataAccess/DynamicSqlQueryTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTests/CS/DataAccess/DynamicSqlQueryTest.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,57 @@
+using System;
+using System.Runtime.CompilerServices;
+
+using NUnit.Framework;
+
+using BLToolkit.Data;
+using BLToolkit.DataAccess;
+using BLToolkit.Reflection;
+
+namespace DataAccess
+{
+	[TestFixture]
+	public class DynamicSqlQueryTest
+	{
+		public abstract class DynamicSqlQueryAccessor : DataAccessor
+		{
+			class DynamicSqlQueryAttribute : SqlQueryAttribute
+			{
+				public override string GetSqlText(DataAccessor accessor, DbManager dbManager)
+				{
+					return SqlText + 1;
+				}
+			}
+
+			[DynamicSqlQuery(SqlText="SELECT ", IsDynamic=true)]
+			public abstract int GetID1();
+
+			[SqlQuery("SELECT ", ID = 2)]
+			public abstract int GetID2();
+
+			protected override string PrepareSqlQuery(
+				DbManager db, int queryID, int uniqueQueryID, string sqlQuery)
+			{
+				switch (queryID)
+				{
+					case 2: return sqlQuery + queryID;
+				}
+
+				return base.PrepareSqlQuery(db, queryID, uniqueQueryID, sqlQuery);
+			}
+		}
+
+		[Test]
+		public void DynamicQueryTest()
+		{
+			DynamicSqlQueryAccessor da = TypeAccessor<DynamicSqlQueryAccessor>.CreateInstance();
+			Assert.AreEqual(da.GetID1(), 1);
+		}
+
+		[Test]
+		public void QueryIDTest()
+		{
+			DynamicSqlQueryAccessor da = TypeAccessor<DynamicSqlQueryAccessor>.CreateInstance();
+			Assert.AreEqual(da.GetID2(), 2);
+		}
+	}
+}