Mercurial > pub > bltoolkit
comparison UnitTests/Linq/SelectScalar.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.Linq; | |
5 | |
6 using NUnit.Framework; | |
7 | |
8 namespace Data.Linq | |
9 { | |
10 using Model; | |
11 | |
12 [TestFixture] | |
13 public class SelectScalar : TestBase | |
14 { | |
15 [Test] | |
16 public void Parameter1() | |
17 { | |
18 var p = 1; | |
19 ForEachProvider(db => Assert.AreEqual(p, db.Select(() => p))); | |
20 } | |
21 | |
22 [Test] | |
23 public void Parameter2() | |
24 { | |
25 ForEachProvider(db => | |
26 { | |
27 var p = 1; | |
28 Assert.AreEqual(p, db.Select(() => new { p }).p); | |
29 }); | |
30 } | |
31 | |
32 [Test] | |
33 public void Constant1() | |
34 { | |
35 ForEachProvider(db => Assert.AreEqual(1, db.Select(() => 1))); | |
36 } | |
37 | |
38 [Test] | |
39 public void Constant2() | |
40 { | |
41 ForEachProvider(db => Assert.AreEqual(1, db.Select(() => new { p = 1 }).p)); | |
42 } | |
43 | |
44 [Test] | |
45 public void Constant3() | |
46 { | |
47 ForEachProvider(db => Assert.AreEqual(1, db.Select(() => new Person { ID = 1, FirstName = "John" }).ID)); | |
48 } | |
49 | |
50 [Test] | |
51 public void StrLen() | |
52 { | |
53 ForEachProvider(db => Assert.AreEqual("1".Length, db.Select(() => "1".Length))); | |
54 } | |
55 | |
56 [Test] | |
57 public void IntMaxValue() | |
58 { | |
59 ForEachProvider(db => Assert.AreEqual(int.MaxValue, db.Select(() => int.MaxValue))); | |
60 } | |
61 | |
62 [Test] | |
63 public void Substring() | |
64 { | |
65 const string s = "123"; | |
66 ForEachProvider(db => Assert.AreEqual(s.Substring(1), db.Select(() => s.Substring(1)))); | |
67 } | |
68 | |
69 [Test] | |
70 public void Add() | |
71 { | |
72 const string s = "123"; | |
73 ForEachProvider(db => Assert.AreEqual(s.Substring(1).Length + 3, db.Select(() => s.Substring(1).Length + 3))); | |
74 } | |
75 | |
76 [Test] | |
77 public void Scalar1() | |
78 { | |
79 ForEachProvider(db => | |
80 { | |
81 var q = (from p in db.Person select new { p } into p1 select p1.p).ToList().Where(p => p.ID == 1).First(); | |
82 Assert.AreEqual(1, q.ID); | |
83 }); | |
84 } | |
85 | |
86 [Test] | |
87 public void Scalar11() | |
88 { | |
89 ForEachProvider(db => | |
90 { | |
91 var n = (from p in db.Person select p.ID).ToList().Where(id => id == 1).First(); | |
92 Assert.AreEqual(1, n); | |
93 }); | |
94 } | |
95 | |
96 [Test] | |
97 public void Scalar2() | |
98 { | |
99 ForEachProvider(db => | |
100 { | |
101 var q = (from p in db.Person select new { p }).ToList().Where(p => p.p.ID == 1).First(); | |
102 Assert.AreEqual(1, q.p.ID); | |
103 }); | |
104 } | |
105 | |
106 [Test] | |
107 public void Scalar21() | |
108 { | |
109 ForEachProvider(db => | |
110 { | |
111 var n = (from p in db.Person select p.FirstName.Length).ToList().Where(len => len == 4).First(); | |
112 Assert.AreEqual(4, n); | |
113 }); | |
114 } | |
115 | |
116 [Test] | |
117 public void Scalar22() | |
118 { | |
119 var expected = | |
120 from p in Person | |
121 select new { p1 = p, p2 = p } | |
122 into p1 | |
123 where p1.p1.ID == 1 && p1.p2.ID == 1 | |
124 select p1; | |
125 | |
126 ForEachProvider(db => | |
127 { | |
128 var result = | |
129 from p in db.Person | |
130 select new { p1 = p, p2 = p } | |
131 into p1 | |
132 where p1.p1.ID == 1 && p1.p2.ID == 1 | |
133 select p1; | |
134 | |
135 Assert.IsTrue(result.ToList().SequenceEqual(expected)); | |
136 }); | |
137 } | |
138 | |
139 [Test] | |
140 public void Scalar23() | |
141 { | |
142 var expected = | |
143 from p in Person | |
144 select p.ID | |
145 into p1 | |
146 where p1 == 1 | |
147 select new { p1 }; | |
148 | |
149 ForEachProvider(db => | |
150 { | |
151 var result = | |
152 from p in db.Person | |
153 select p.ID | |
154 into p1 | |
155 where p1 == 1 | |
156 select new { p1 }; | |
157 | |
158 Assert.IsTrue(result.ToList().SequenceEqual(expected)); | |
159 }); | |
160 } | |
161 | |
162 [Test] | |
163 public void Scalar3() | |
164 { | |
165 var expected = from p in Person where p.ID == 1 select 1; | |
166 | |
167 ForEachProvider(db => | |
168 { | |
169 var result = from p in db.Person where p.ID == 1 select 1; | |
170 Assert.IsTrue(result.ToList().SequenceEqual(expected)); | |
171 }); | |
172 } | |
173 | |
174 [Test] | |
175 public void Scalar31() | |
176 { | |
177 var n = 1; | |
178 var expected = from p in Person where p.ID == 1 select n; | |
179 | |
180 ForEachProvider(db => | |
181 { | |
182 var result = from p in db.Person where p.ID == 1 select n; | |
183 Assert.IsTrue(result.ToList().SequenceEqual(expected)); | |
184 }); | |
185 } | |
186 | |
187 [Test] | |
188 public void Scalar4() | |
189 { | |
190 var expected = | |
191 from p in Parent | |
192 join c in Child on p.ParentID equals c.ParentID | |
193 where c.ChildID > 20 | |
194 select p; | |
195 | |
196 ForEachProvider(db => | |
197 { | |
198 var result = | |
199 from p in db.Parent | |
200 join c in db.Child on p.ParentID equals c.ParentID | |
201 where c.ChildID > 20 | |
202 select p; | |
203 | |
204 Assert.AreEqual(expected.Where(p => p.ParentID == 3).First(), result.Where(p => p.ParentID == 3).First()); | |
205 }); | |
206 } | |
207 | |
208 [Test] | |
209 public void Function() | |
210 { | |
211 var text = "123"; | |
212 | |
213 ForEachProvider(db => Assert.AreEqual( | |
214 Child.Select(c => string.Format("{0},{1}", c.ChildID, text)).FirstOrDefault(), | |
215 db.Child.Select(c => string.Format("{0},{1}", c.ChildID, text)).FirstOrDefault())); | |
216 } | |
217 } | |
218 } |