Mercurial > pub > bltoolkit
comparison HowTo/Data/ExecuteScalar.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 NUnit.Framework; | |
3 using BLToolkit.Data; | |
4 | |
5 namespace HowTo.Data | |
6 { | |
7 [TestFixture] | |
8 public class ExecuteScalar | |
9 { | |
10 string GetFirstName(int id) | |
11 { | |
12 using (DbManager db = new DbManager()) | |
13 { | |
14 return db | |
15 .SetCommand("SELECT FirstName FROM Person WHERE PersonID = @id", | |
16 db.Parameter("@id", id)) | |
17 ./*[a]*/ExecuteScalar/*[/a]*/<string>(); | |
18 } | |
19 } | |
20 | |
21 [Test] | |
22 public void ReaderTest() | |
23 { | |
24 string firstName = GetFirstName(1); | |
25 | |
26 Assert.IsNotNull(firstName); | |
27 } | |
28 | |
29 [Test] | |
30 public void ReturnValueTest() | |
31 { | |
32 using (DbManager db = new DbManager()) | |
33 { | |
34 /* | |
35 * CREATE Function Scalar_ReturnParameter() | |
36 * RETURNS int | |
37 * AS | |
38 * BEGIN | |
39 * RETURN 12345 | |
40 * END | |
41 */ | |
42 int n = db | |
43 .SetSpCommand("Scalar_ReturnParameter") | |
44 ./*[a]*/ExecuteScalar/*[/a]*/<int>(/*[a]*/ScalarSourceType.ReturnValue/*[/a]*/); | |
45 | |
46 Assert.AreEqual(12345, n); | |
47 } | |
48 } | |
49 | |
50 [Test] | |
51 public void OutputParameterAsReturnValueTest() | |
52 { | |
53 using (DbManager db = new DbManager()) | |
54 { | |
55 /* | |
56 * CREATE Procedure Scalar_OutputParameter | |
57 * @outputInt int = 0 output, | |
58 * @outputString varchar(50) = '' output | |
59 * AS | |
60 * BEGIN | |
61 * SET @outputInt = 12345 | |
62 * SET @outputString = '54321' | |
63 * END | |
64 */ | |
65 string returnValue = db | |
66 .SetSpCommand("Scalar_OutputParameter") | |
67 ./*[a]*/ExecuteScalar/*[/a]*/<string>(/*[a]*/ScalarSourceType.OutputParameter/*[/a]*/, /*[a]*/"outputString"/*[/a]*/); | |
68 | |
69 Assert.AreEqual("54321", returnValue); | |
70 } | |
71 } | |
72 } | |
73 } |