Mercurial > pub > bltoolkit
comparison UnitTests/CS/DataAccess/SqlQueryTest2.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.Collections.Generic; | |
3 | |
4 using NUnit.Framework; | |
5 | |
6 using BLToolkit.DataAccess; | |
7 | |
8 namespace DataAccess | |
9 { | |
10 [TestFixture] | |
11 public class SqlQueryTest2 | |
12 { | |
13 public class Person | |
14 { | |
15 public int ID; | |
16 public string LastName; | |
17 public string FirstName; | |
18 public string MiddleName; | |
19 } | |
20 | |
21 public abstract class PersonAccessor : DataAccessor<Person> | |
22 { | |
23 [TestQuery( | |
24 SqlText = "SELECT * FROM Person WHERE LastName = @lastName", | |
25 OracleText = "SELECT * FROM Person WHERE LastName = :lastName")] | |
26 public abstract List<Person> SelectByLastName(string lastName); | |
27 | |
28 [TestQuery( | |
29 SqlText = "SELECT * FROM Person WHERE {0} = @value", | |
30 OracleText = "SELECT * FROM Person WHERE {0} = :value")] | |
31 public abstract List<Person> SelectBy([Format] string fieldName, string value); | |
32 | |
33 [TestQuery( | |
34 SqlText = "SELECT TOP ({0}) * FROM Person WHERE LastName = @lastName", | |
35 AccessText = "SELECT TOP {0} * FROM Person WHERE LastName = @lastName", | |
36 OracleText = "SELECT * FROM Person WHERE LastName = :lastName AND rownum <= {0}", | |
37 FbText = "SELECT FIRST {0} * FROM Person WHERE LastName = @lastName", | |
38 SQLiteText = "SELECT * FROM Person WHERE LastName = @lastName LIMIT {0}")] | |
39 public abstract List<Person> SelectByLastName(string lastName, [Format(0)] int top); | |
40 | |
41 [TestQuery( | |
42 SqlText = "SELECT @id as ID", | |
43 OracleText = "SELECT :id ID FROM Dual", | |
44 FbText = "SELECT CAST(@id AS INTEGER) ID FROM Dual")] | |
45 public abstract List<Person> SelectID(int @id); | |
46 } | |
47 | |
48 [Test] | |
49 public void Test1() | |
50 { | |
51 var da = DataAccessor.CreateInstance<PersonAccessor>(); | |
52 var list = da.SelectByLastName("Pupkin"); | |
53 | |
54 Assert.AreNotEqual(0, list.Count); | |
55 } | |
56 | |
57 [Test] | |
58 public void Test2() | |
59 { | |
60 var da = DataAccessor.CreateInstance<PersonAccessor>(); | |
61 var list = da.SelectBy("FirstName", "John"); | |
62 | |
63 Assert.AreNotEqual(0, list.Count); | |
64 } | |
65 | |
66 [Test] | |
67 public void Test3() | |
68 { | |
69 var da = DataAccessor.CreateInstance<PersonAccessor>(); | |
70 var list = da.SelectByLastName("Pupkin", 1); | |
71 | |
72 Assert.AreNotEqual(0, list.Count); | |
73 } | |
74 | |
75 #if !SQLCE // Works in Query window but not here??? | |
76 [Test] | |
77 #endif | |
78 public void Test4() | |
79 { | |
80 var da = DataAccessor.CreateInstance<PersonAccessor>(); | |
81 var list = da.SelectID(42); | |
82 | |
83 Assert.AreEqual(42, list[0].ID); | |
84 } | |
85 } | |
86 } |