Mercurial > pub > bltoolkit
comparison UnitTests/CS/DataAccess/DynamicSqlQueryTest.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Runtime.CompilerServices; | |
3 | |
4 using NUnit.Framework; | |
5 | |
6 using BLToolkit.Data; | |
7 using BLToolkit.DataAccess; | |
8 using BLToolkit.Reflection; | |
9 | |
10 namespace DataAccess | |
11 { | |
12 [TestFixture] | |
13 public class DynamicSqlQueryTest | |
14 { | |
15 public abstract class DynamicSqlQueryAccessor : DataAccessor | |
16 { | |
17 class DynamicSqlQueryAttribute : SqlQueryAttribute | |
18 { | |
19 public override string GetSqlText(DataAccessor accessor, DbManager dbManager) | |
20 { | |
21 return SqlText + 1; | |
22 } | |
23 } | |
24 | |
25 [DynamicSqlQuery(SqlText="SELECT ", IsDynamic=true)] | |
26 public abstract int GetID1(); | |
27 | |
28 [SqlQuery("SELECT ", ID = 2)] | |
29 public abstract int GetID2(); | |
30 | |
31 protected override string PrepareSqlQuery( | |
32 DbManager db, int queryID, int uniqueQueryID, string sqlQuery) | |
33 { | |
34 switch (queryID) | |
35 { | |
36 case 2: return sqlQuery + queryID; | |
37 } | |
38 | |
39 return base.PrepareSqlQuery(db, queryID, uniqueQueryID, sqlQuery); | |
40 } | |
41 } | |
42 | |
43 [Test] | |
44 public void DynamicQueryTest() | |
45 { | |
46 DynamicSqlQueryAccessor da = TypeAccessor<DynamicSqlQueryAccessor>.CreateInstance(); | |
47 Assert.AreEqual(da.GetID1(), 1); | |
48 } | |
49 | |
50 [Test] | |
51 public void QueryIDTest() | |
52 { | |
53 DynamicSqlQueryAccessor da = TypeAccessor<DynamicSqlQueryAccessor>.CreateInstance(); | |
54 Assert.AreEqual(da.GetID2(), 2); | |
55 } | |
56 } | |
57 } |