comparison UnitTests/CS/Data/ExecuteScalarTest.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
3 using NUnit.Framework;
4
5 using BLToolkit.Data;
6
7 namespace Data
8 {
9 [TestFixture]
10 public class ExecuteScalarTest
11 {
12 [Test]
13 public void RegressionTest()
14 {
15 using (var db = new DbManager())
16 {
17 var expectedValue = 12345;
18 var actualValue = db.MappingSchema.ConvertToInt32(
19 db
20 #if SQLITE || SQLCE
21 .SetCommand("SELECT 12345")
22 #else
23 .SetSpCommand("Scalar_DataReader")
24 #endif
25 .ExecuteScalar());
26
27 Assert.AreEqual(expectedValue, actualValue);
28 }
29 }
30
31 [Test]
32 public void DataReaderTest()
33 {
34 using (var db = new DbManager())
35 {
36 var expectedValue = 12345;
37 var actualValue = db.MappingSchema.ConvertToInt32(
38 db
39 #if SQLITE || SQLCE
40 .SetCommand("SELECT 12345")
41 #else
42 .SetSpCommand("Scalar_DataReader")
43 #endif
44 .ExecuteScalar(ScalarSourceType.DataReader));
45
46 Assert.AreEqual(expectedValue, actualValue);
47 }
48 }
49
50 [Test]
51 public void DataReader2Test()
52 {
53 using (var db = new DbManager())
54 {
55 var expectedValue = "54321";
56 var actualValue = db.MappingSchema.ConvertToString(
57 db
58 #if SQLITE || SQLCE
59 .SetCommand("SELECT 12345, '54321'")
60 #else
61 .SetSpCommand("Scalar_DataReader")
62 #endif
63 .ExecuteScalar(ScalarSourceType.DataReader, 1));
64
65 Assert.AreEqual(expectedValue, actualValue);
66 }
67 }
68
69 [Test]
70 public void DataReader3Test()
71 {
72 using (var db = new DbManager())
73 {
74 var expectedValue = "54321";
75 var actualValue = db.MappingSchema.ConvertToString(
76 db
77 #if SQLITE || SQLCE
78 .SetCommand("SELECT 12345 intField, '54321' stringField")
79 #else
80 .SetSpCommand("Scalar_DataReader")
81 #endif
82 .ExecuteScalar(ScalarSourceType.DataReader, "stringField"));
83
84 Assert.AreEqual(expectedValue, actualValue);
85 }
86 }
87
88 #if !ACCESS && !SQLITE && !SQLCE
89 [Test]
90 public void OutputParameterTest()
91 {
92 using (var db = new DbManager())
93 {
94 var expectedValue = 12345;
95 var actualValue = db.MappingSchema.ConvertToInt32(db
96 .SetSpCommand("Scalar_OutputParameter")
97 .ExecuteScalar(ScalarSourceType.OutputParameter));
98
99 Assert.AreEqual(expectedValue, actualValue);
100 }
101 }
102
103 [Test]
104 public void OutputParameter2Test()
105 {
106 using (var db = new DbManager())
107 {
108 var expectedValue = "54321";
109 var actualValue = db.MappingSchema.ConvertToString(db
110 .SetSpCommand("Scalar_OutputParameter")
111 .ExecuteScalar(ScalarSourceType.OutputParameter, 1));
112
113 Assert.AreEqual(expectedValue, actualValue);
114 }
115 }
116
117 [Test]
118 public void OutputParameter3Test()
119 {
120 using (var db = new DbManager())
121 {
122 var expectedValue = "54321";
123 var actualValue = db.MappingSchema.ConvertToString(db
124 .SetSpCommand("Scalar_OutputParameter")
125 .ExecuteScalar(ScalarSourceType.OutputParameter, "outputString"));
126
127 Assert.AreEqual(expectedValue, actualValue);
128 }
129 }
130
131 [Test]
132 public void ReturnParameterTest()
133 {
134 using (var db = new DbManager())
135 {
136 var expectedValue = 12345;
137 var actualValue = db.MappingSchema.ConvertToInt32(db
138 .SetSpCommand("Scalar_ReturnParameter")
139 .ExecuteScalar(ScalarSourceType.ReturnValue));
140
141 Assert.AreEqual(expectedValue, actualValue);
142 }
143 }
144 #endif
145
146 [Test]
147 public void AffectedRowsTest()
148 {
149 using (var db = new DbManager())
150 {
151 #if ACCESS || SQLITE
152 var expectedValue = 0;
153 #else
154 var expectedValue = -1;
155 #endif
156 var actualValue = db.MappingSchema.ConvertToInt32(
157 db
158 #if SQLITE || SQLCE
159 .SetCommand("SELECT 12345")
160 #else
161 .SetSpCommand("Scalar_DataReader")
162 #endif
163 .ExecuteScalar(ScalarSourceType.AffectedRows));
164
165 Assert.AreEqual(expectedValue, actualValue);
166 }
167 }
168
169 [Test]
170 public void GenericsRegressionTest()
171 {
172 using (var db = new DbManager())
173 {
174 var expectedValue = 12345;
175 var actualValue = db
176 #if SQLITE || SQLCE
177 .SetCommand("SELECT 12345")
178 #else
179 .SetSpCommand("Scalar_DataReader")
180 #endif
181 .ExecuteScalar<int>();
182
183 Assert.AreEqual(expectedValue, actualValue);
184 }
185 }
186
187 [Test]
188 public void GenericsDataReaderTest()
189 {
190 using (var db = new DbManager())
191 {
192 var expectedValue = 12345;
193 var actualValue = db
194 #if SQLITE || SQLCE
195 .SetCommand("SELECT 12345")
196 #else
197 .SetSpCommand("Scalar_DataReader")
198 #endif
199 .ExecuteScalar<int>(ScalarSourceType.DataReader);
200
201 Assert.AreEqual(expectedValue, actualValue);
202 }
203 }
204
205 [Test]
206 public void GenericsDataReader2Test()
207 {
208 using (var db = new DbManager())
209 {
210 var expectedValue = "54321";
211 var actualValue = db
212 #if SQLITE || SQLCE
213 .SetCommand("SELECT 12345, '54321'")
214 #else
215 .SetSpCommand("Scalar_DataReader")
216 #endif
217 .ExecuteScalar<string>(ScalarSourceType.DataReader, 1);
218
219 Assert.AreEqual(expectedValue, actualValue);
220 }
221 }
222
223 [Test]
224 public void NoResult()
225 {
226 using (var db = new DbManager())
227 {
228 var actualValue = db.SetCommand("SELECT FirstName FROM Person WHERE PersonID = -1").ExecuteScalar<string>();
229 Assert.AreEqual("", actualValue);
230 }
231 }
232 }
233 }