0
|
1 using System;
|
|
2 using System.IO;
|
|
3 using System.Xml;
|
|
4
|
|
5 using NUnit.Framework;
|
|
6
|
|
7 using BLToolkit.Data;
|
|
8 using BLToolkit.DataAccess;
|
|
9 using BLToolkit.Reflection;
|
|
10
|
|
11 namespace DataAccess
|
|
12 {
|
|
13 [TestFixture]
|
|
14 public class ScalarTest
|
|
15 {
|
|
16 public enum TestEnum
|
|
17 {
|
|
18 Null = 0,
|
|
19 Value = 12345,
|
|
20 }
|
|
21
|
|
22 public abstract class TestAccessor : DataAccessor
|
|
23 {
|
|
24 [ActionName("Scalar_DataReader")]
|
|
25 public abstract int Scalar_Regression(DbManager db);
|
|
26
|
|
27 [ScalarSource(ScalarSourceType.DataReader)]
|
|
28 public abstract int Scalar_DataReader(DbManager db);
|
|
29
|
|
30 [ActionName("Scalar_DataReader")]
|
|
31 [ScalarSource(ScalarSourceType.DataReader, 1)]
|
|
32 public abstract string Scalar_DataReader2(DbManager db);
|
|
33
|
|
34 [ActionName("Scalar_DataReader")]
|
|
35 [ScalarSource(ScalarSourceType.DataReader, "stringField")]
|
|
36 public abstract string Scalar_DataReader3(DbManager db);
|
|
37
|
|
38 [ActionName("Scalar_OutputParameter")]
|
|
39 public abstract void Scalar_OutputParameterRegression(
|
|
40 DbManager db, out int outputInt, out string outputString);
|
|
41
|
|
42 [ScalarSource(ScalarSourceType.OutputParameter)]
|
|
43 public abstract int Scalar_OutputParameter(DbManager db);
|
|
44
|
|
45 [ActionName("Scalar_OutputParameter")]
|
|
46 [ScalarSource(ScalarSourceType.OutputParameter, 1)]
|
|
47 public abstract string Scalar_OutputParameter2(DbManager db);
|
|
48
|
|
49 [ActionName("Scalar_OutputParameter")]
|
|
50 [ScalarSource(ScalarSourceType.OutputParameter, "outputString")]
|
|
51 public abstract string Scalar_OutputParameter3(DbManager db);
|
|
52
|
|
53 [ScalarSource(ScalarSourceType.ReturnValue)]
|
|
54 public abstract int Scalar_ReturnParameter(DbManager db);
|
|
55
|
|
56 [ActionName("Scalar_DataReader")]
|
|
57 [ScalarSource(ScalarSourceType.AffectedRows)]
|
|
58 public abstract int Scalar_AffectedRows(DbManager db);
|
|
59
|
|
60 [TestQuery(
|
|
61 SqlText = "SELECT Stream_ FROM DataTypeTest WHERE DataTypeID = @id",
|
|
62 OracleText = "SELECT Stream_ FROM DataTypeTest WHERE DataTypeID = :id")]
|
|
63 public abstract Stream GetStream(DbManager db, int id);
|
|
64
|
|
65 [TestQuery(
|
|
66 SqlText = "SELECT Xml_ FROM DataTypeTest WHERE DataTypeID = @id",
|
|
67 OracleText = "SELECT Xml_ FROM DataTypeTest WHERE DataTypeID = :id")]
|
|
68 public abstract XmlReader GetXml(DbManager db, int id);
|
|
69
|
|
70 [TestQuery(
|
|
71 SqlText = "SELECT Xml_ FROM DataTypeTest WHERE DataTypeID = @id",
|
|
72 OracleText = "SELECT Xml_ FROM DataTypeTest WHERE DataTypeID = :id")]
|
|
73 public abstract XmlDocument GetXmlDoc(DbManager db, int id);
|
|
74
|
|
75 [SprocName("Scalar_DataReader")]
|
|
76 public abstract int ScalarDestination1([Destination] out int id);
|
|
77
|
|
78 [SprocName("Scalar_DataReader")]
|
|
79 public abstract void ScalarDestination2([Destination] out int id);
|
|
80
|
|
81 [SprocName("Scalar_DataReader")]
|
|
82 public abstract object ScalarDestination3([Destination] out int id);
|
|
83
|
|
84 [SprocName("Scalar_DataReader")]
|
|
85 public abstract int ScalarDestination4([Destination] ref int id);
|
|
86
|
|
87 [SprocName("Scalar_DataReader")]
|
|
88 public abstract void ScalarDestination5([Destination] ref int id);
|
|
89
|
|
90 [SprocName("Scalar_DataReader")]
|
|
91 public abstract object ScalarDestination6([Destination] ref int id);
|
|
92
|
|
93 [SprocName("Scalar_DataReader")]
|
|
94 public abstract int? ScalarNullableDestination([Destination] ref int? id);
|
|
95
|
|
96 [SprocName("Scalar_DataReader")]
|
|
97 public abstract TestEnum ScalarEnumDestination([Destination] ref TestEnum value);
|
|
98
|
|
99 [SprocName("Scalar_DataReader")]
|
|
100 public abstract TestEnum? ScalarNullableEnumDestination([Destination] ref TestEnum? value);
|
|
101
|
|
102 public static TestAccessor CreateInstance()
|
|
103 {
|
|
104 return (TestAccessor)CreateInstance(typeof(TestAccessor));
|
|
105 }
|
|
106 }
|
|
107
|
|
108 [Test]
|
|
109 public void RegressionTest()
|
|
110 {
|
|
111 using (DbManager db = new DbManager())
|
|
112 {
|
|
113 TestAccessor ta = TestAccessor.CreateInstance();
|
|
114
|
|
115 int expectedValue = 12345;
|
|
116 int actualValue = ta.Scalar_Regression(db);
|
|
117
|
|
118 Assert.AreEqual(expectedValue, actualValue);
|
|
119 }
|
|
120 }
|
|
121
|
|
122 [Test]
|
|
123 public void DataReaderTest()
|
|
124 {
|
|
125 using (DbManager db = new DbManager())
|
|
126 {
|
|
127 TestAccessor ta = TestAccessor.CreateInstance();
|
|
128
|
|
129 int expectedValue = 12345;
|
|
130 int actualValue = ta.Scalar_DataReader(db);
|
|
131
|
|
132 Assert.AreEqual(expectedValue, actualValue);
|
|
133 }
|
|
134 }
|
|
135
|
|
136 [Test]
|
|
137 public void DataReader2Test()
|
|
138 {
|
|
139 using (DbManager db = new DbManager())
|
|
140 {
|
|
141 TestAccessor ta = TestAccessor.CreateInstance();
|
|
142
|
|
143 string expectedValue = "54321";
|
|
144 string actualValue = ta.Scalar_DataReader2(db);
|
|
145
|
|
146 Assert.AreEqual(expectedValue, actualValue);
|
|
147 }
|
|
148 }
|
|
149
|
|
150 [Test]
|
|
151 public void DataReader3Test()
|
|
152 {
|
|
153 using (DbManager db = new DbManager())
|
|
154 {
|
|
155 TestAccessor ta = TestAccessor.CreateInstance();
|
|
156
|
|
157 string expectedValue = "54321";
|
|
158 string actualValue = ta.Scalar_DataReader3(db);
|
|
159
|
|
160 Assert.AreEqual(expectedValue, actualValue);
|
|
161 }
|
|
162 }
|
|
163
|
|
164 #if !ACCESS && !SQLITE
|
|
165 [Test]
|
|
166 public void OutputParameterRegressionTest()
|
|
167 {
|
|
168 using (DbManager db = new DbManager())
|
|
169 {
|
|
170 TestAccessor ta = TestAccessor.CreateInstance();
|
|
171
|
|
172 int expectedIntValue = 12345;
|
|
173 int actualIntValue;
|
|
174 string expectedStringValue = "54321";
|
|
175 string actualStringValue;
|
|
176
|
|
177 ta.Scalar_OutputParameterRegression(db,
|
|
178 out actualIntValue, out actualStringValue);
|
|
179
|
|
180 Assert.AreEqual(expectedIntValue, actualIntValue);
|
|
181 Assert.AreEqual(expectedStringValue, actualStringValue);
|
|
182 }
|
|
183 }
|
|
184
|
|
185 [Test]
|
|
186 public void OutputParameterTest()
|
|
187 {
|
|
188 using (DbManager db = new DbManager())
|
|
189 {
|
|
190 TestAccessor ta = TestAccessor.CreateInstance();
|
|
191
|
|
192 int expectedValue = 12345;
|
|
193 int actualValue = ta.Scalar_OutputParameter(db);
|
|
194
|
|
195 Assert.AreEqual(expectedValue, actualValue);
|
|
196 }
|
|
197 }
|
|
198
|
|
199 [Test]
|
|
200 public void OutputParameter2Test()
|
|
201 {
|
|
202 using (DbManager db = new DbManager())
|
|
203 {
|
|
204 TestAccessor ta = TestAccessor.CreateInstance();
|
|
205
|
|
206 string expectedValue = "54321";
|
|
207 string actualValue = ta.Scalar_OutputParameter2(db);
|
|
208
|
|
209 Assert.AreEqual(expectedValue, actualValue);
|
|
210 }
|
|
211 }
|
|
212
|
|
213 [Test]
|
|
214 public void OutputParameter3Test()
|
|
215 {
|
|
216 using (DbManager db = new DbManager())
|
|
217 {
|
|
218 TestAccessor ta = TestAccessor.CreateInstance();
|
|
219
|
|
220 string expectedValue = "54321";
|
|
221 string actualValue = ta.Scalar_OutputParameter3(db);
|
|
222
|
|
223 Assert.AreEqual(expectedValue, actualValue);
|
|
224 }
|
|
225 }
|
|
226
|
|
227 [Test]
|
|
228 public void ReturnParameterTest()
|
|
229 {
|
|
230 using (DbManager db = new DbManager())
|
|
231 {
|
|
232 TestAccessor ta = TestAccessor.CreateInstance();
|
|
233
|
|
234 int expectedValue = 12345;
|
|
235 int actualValue = ta.Scalar_ReturnParameter(db);
|
|
236
|
|
237 Assert.AreEqual(expectedValue, actualValue);
|
|
238 }
|
|
239 }
|
|
240 #endif
|
|
241
|
|
242 [Test]
|
|
243 public void AffectedRowsTest()
|
|
244 {
|
|
245 using (DbManager db = new DbManager())
|
|
246 {
|
|
247 TestAccessor ta = TestAccessor.CreateInstance();
|
|
248
|
|
249 #if ACCESS
|
|
250 int expectedValue = 0;
|
|
251 #else
|
|
252 int expectedValue = -1;
|
|
253 #endif
|
|
254 int actualValue = ta.Scalar_AffectedRows(db);
|
|
255
|
|
256 Assert.AreEqual(expectedValue, actualValue);
|
|
257 }
|
|
258 }
|
|
259
|
|
260 [Test]
|
|
261 public void StreamTest()
|
|
262 {
|
|
263 using (DbManager db = new DbManager())
|
|
264 {
|
|
265 TestAccessor ta = TestAccessor.CreateInstance();
|
|
266
|
|
267 Stream s = ta.GetStream(db, 2);
|
|
268 Byte[] bytes = new byte[16];
|
|
269
|
|
270 Assert.IsNotNull(s);
|
|
271 Assert.AreEqual(s.Length, bytes.Length);
|
|
272
|
|
273 Assert.AreEqual(s.Read(bytes, 0, bytes.Length), bytes.Length);
|
|
274 TypeAccessor.WriteConsole(bytes);
|
|
275 }
|
|
276 }
|
|
277
|
|
278 [Test]
|
|
279 public void ScalarDestinationTest()
|
|
280 {
|
|
281 TestAccessor ta = TestAccessor.CreateInstance();
|
|
282
|
|
283 int id1;
|
|
284 int id2;
|
|
285
|
|
286 id1 = ta.ScalarDestination1(out id2);
|
|
287 Assert.AreEqual(id1, 12345);
|
|
288 Assert.AreEqual(id2, 12345);
|
|
289
|
|
290 ta.ScalarDestination2(out id2);
|
|
291 Assert.AreEqual(id2, 12345);
|
|
292
|
|
293 id1 = (int)ta.ScalarDestination3(out id2);
|
|
294 Assert.AreEqual(id1, 12345);
|
|
295 Assert.AreEqual(id2, 12345);
|
|
296
|
|
297 id2 = 0;
|
|
298 id1 = ta.ScalarDestination4(ref id2);
|
|
299 Assert.AreEqual(id1, 12345);
|
|
300 Assert.AreEqual(id2, 12345);
|
|
301
|
|
302 id2 = 0;
|
|
303 ta.ScalarDestination5(ref id2);
|
|
304 Assert.AreEqual(id2, 12345);
|
|
305
|
|
306 id2 = 0;
|
|
307 id1 = (int)ta.ScalarDestination6(ref id2);
|
|
308 Assert.AreEqual(id1, 12345);
|
|
309 Assert.AreEqual(id2, 12345);
|
|
310 }
|
|
311
|
|
312 [Test]
|
|
313 public void XmlTest()
|
|
314 {
|
|
315 using (DbManager db = new DbManager())
|
|
316 {
|
|
317 TestAccessor ta = TestAccessor.CreateInstance();
|
|
318
|
|
319 XmlReader xml = ta.GetXml(db, 2);
|
|
320 xml.MoveToContent();
|
|
321 Assert.IsTrue(xml.ReadToDescendant("element"));
|
|
322 Assert.AreEqual("strvalue", xml.GetAttribute("strattr"));
|
|
323 }
|
|
324 }
|
|
325
|
|
326 public void XmlDocTest()
|
|
327 {
|
|
328 using (DbManager db = new DbManager())
|
|
329 {
|
|
330 TestAccessor ta = TestAccessor.CreateInstance();
|
|
331
|
|
332 XmlDocument xmlDocument= ta.GetXmlDoc(db, 2);
|
|
333 Assert.IsNotNull(xmlDocument);
|
|
334 Assert.IsNotNull(xmlDocument.DocumentElement);
|
|
335 Assert.AreEqual("strvalue", xmlDocument.DocumentElement.GetAttribute("strattr"));
|
|
336 }
|
|
337 }
|
|
338
|
|
339 [Test]
|
|
340 public void ScalarNullableDestinationTest()
|
|
341 {
|
|
342 TestAccessor ta = TestAccessor.CreateInstance();
|
|
343
|
|
344 int? id1;
|
|
345 int? id2 = -1;
|
|
346 id1 = ta.ScalarNullableDestination(ref id2);
|
|
347 Assert.AreEqual(id1, id2);
|
|
348 }
|
|
349
|
|
350 [Test]
|
|
351 public void ScalarEnumDestinationTest()
|
|
352 {
|
|
353 TestAccessor ta = TestAccessor.CreateInstance();
|
|
354
|
|
355 TestEnum refVal = TestEnum.Null;
|
|
356 TestEnum outVal = ta.ScalarEnumDestination(ref refVal);
|
|
357 Assert.That(outVal, Is.EqualTo(TestEnum.Value));
|
|
358 Assert.That(refVal, Is.EqualTo(TestEnum.Value));
|
|
359 }
|
|
360
|
|
361 [Test]
|
|
362 public void ScalarNullableEnumDestinationTest()
|
|
363 {
|
|
364 TestAccessor ta = TestAccessor.CreateInstance();
|
|
365
|
|
366 TestEnum? refVal = null;
|
|
367 TestEnum? outVal = ta.ScalarNullableEnumDestination(ref refVal);
|
|
368 Assert.That(outVal, Is.EqualTo(TestEnum.Value));
|
|
369 Assert.That(refVal, Is.EqualTo(TestEnum.Value));
|
|
370 }
|
|
371 }
|
|
372 }
|