comparison UnitTests/Linq/TableFunctionTest.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.Linq;
3
4 using BLToolkit.Data;
5 using BLToolkit.Data.Linq;
6
7 using NUnit.Framework;
8
9 namespace Data.Linq
10 {
11 using Model;
12
13 [TestFixture]
14 public class TableFunctionTest : TestBase
15 {
16 [Test]
17 public void Func1([IncludeDataContexts("Sql2008", "Sql2012")] string context)
18 {
19 using (var db = new TestDbManager(context))
20 {
21 var q =
22 from p in new Model.Functions(db).GetParentByID(1)
23 select p;
24
25 q.ToList();
26 }
27 }
28
29 [Test]
30 public void Func2([IncludeDataContexts("Sql2008", "Sql2012")] string context)
31 {
32 using (var db = new TestDbManager(context))
33 {
34 var q =
35 from c in db.Child
36 from p in db.GetParentByID(2)
37 select p;
38
39 q.ToList();
40 }
41 }
42
43 [Test]
44 public void Func3([IncludeDataContexts("Sql2008", "Sql2012")] string context)
45 {
46 using (var db = new TestDbManager(context))
47 {
48 var q =
49 from c in db.Child
50 from p in db.GetParentByID(c.ParentID)
51 select p;
52
53 q.ToList();
54 }
55 }
56
57 readonly Func<DbManager,int,IQueryable<Parent>> _f1 = CompiledQuery.Compile(
58 (DbManager db, int id) => from p in new Model.Functions(db).GetParentByID(id) select p);
59
60 [Test]
61 public void CompiledFunc1([IncludeDataContexts("Sql2008", "Sql2012")] string context)
62 {
63 using (var db = new TestDbManager(context))
64 {
65 var q = _f1(db, 1);
66 q.ToList();
67 }
68 }
69
70 readonly Func<TestDbManager,int,IQueryable<Parent>> _f2 = CompiledQuery.Compile(
71 (TestDbManager db, int id) => from c in db.Child from p in db.GetParentByID(id) select p);
72
73 [Test]
74 public void CompiledFunc2([IncludeDataContexts("Sql2008", "Sql2012")] string context)
75 {
76 using (var db = new TestDbManager(context))
77 {
78 var q = _f2(db, 1);
79 q.ToList();
80 }
81 }
82
83 [Test]
84 public void WithTabLock([IncludeDataContexts("Sql2008", "Sql2012")] string context)
85 {
86 using (var db = new TestDbManager(context))
87 {
88 var q =
89 from p in new Model.Functions(db).WithTabLock<Parent>()
90 select p;
91
92 q.ToList();
93 }
94 }
95
96 [Test, Category("FULLTEXT")]
97 public void FreeText1([IncludeDataContexts("Northwind")] string context)
98 {
99 using (var db = new NorthwindDB())
100 {
101 var q =
102 from c in db.Category
103 join t in db.FreeTextTable<Northwind.Category,int>("[Description]", "sweetest candy bread and dry meat")
104 on c.CategoryID equals t.Key
105 select c;
106
107 q.ToList();
108 }
109 }
110
111 [Test, Category("FULLTEXT")]
112 public void FreeText2([IncludeDataContexts("Northwind")] string context)
113 {
114 using (var db = new NorthwindDB())
115 {
116 var q =
117 from c in db.Category
118 join t in db.FreeTextTable<Northwind.Category,int>(c => c.Description, "sweetest candy bread and dry meat")
119 on c.CategoryID equals t.Key
120 select c;
121
122 q.ToList();
123 }
124 }
125
126 [Test, Category("FULLTEXT")]
127 public void FreeText3([IncludeDataContexts("Northwind")] string context)
128 {
129 using (var db = new NorthwindDB())
130 {
131 var q =
132 from t in db.FreeTextTable<Northwind.Category,int>(c => c.Description, "sweetest candy bread and dry meat")
133 join c in db.Category
134 on t.Key equals c.CategoryID
135 select c;
136
137 q.ToList();
138 }
139 }
140 }
141 }