comparison UnitTests/CS/DataAccess/SqlQueryTest.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;
3
4 using NUnit.Framework;
5
6 using BLToolkit.DataAccess;
7
8 namespace DataAccess
9 {
10 [TestFixture]
11 public class SqlQueryTest
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 [ObjectType(typeof(Person))]
22 public abstract class PersonAccessor : DataAccessor
23 {
24 [TestQuery(
25 SqlText = "SELECT * FROM Person WHERE LastName = @lastName",
26 OracleText = "SELECT * FROM Person WHERE LastName = :lastName")]
27 public abstract ArrayList SelectByLastName(string lastName);
28
29 [TestQuery(
30 SqlText = "SELECT * FROM Person WHERE {0} = @value",
31 OracleText = "SELECT * FROM Person WHERE {0} = :value")]
32 public abstract ArrayList SelectBy([Format] string fieldName, string value);
33
34 [TestQuery(
35 SqlText = "SELECT TOP ({0}) * FROM Person WHERE LastName = @lastName",
36 AccessText = "SELECT TOP {0} * FROM Person WHERE LastName = @lastName",
37 OracleText = "SELECT * FROM Person WHERE LastName = :lastName AND rownum <= {0}",
38 FbText = "SELECT FIRST {0} * FROM Person WHERE LastName = @lastName",
39 SQLiteText = "SELECT * FROM Person WHERE LastName = @lastName LIMIT {0}")]
40 public abstract ArrayList SelectByLastName(string lastName, [Format(0)] int top);
41 }
42
43 [Test]
44 public void Test1()
45 {
46 var da = (PersonAccessor)DataAccessor.CreateInstance(typeof(PersonAccessor));
47 var list = da.SelectByLastName("Pupkin");
48
49 Assert.AreNotEqual(0, list.Count);
50 }
51
52 [Test]
53 public void Test2()
54 {
55 var da = (PersonAccessor)DataAccessor.CreateInstance(typeof(PersonAccessor));
56 var list = da.SelectBy("FirstName", "John");
57
58 Assert.AreNotEqual(0, list.Count);
59 }
60
61 [Test]
62 public void Test3()
63 {
64 var da = (PersonAccessor)DataAccessor.CreateInstance(typeof(PersonAccessor));
65 var list = da.SelectByLastName("Pupkin", 1);
66
67 Assert.AreNotEqual(0, list.Count);
68 }
69 }
70 }