comparison UnitTests/CS/Data/OutputParameter.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.Data;
3
4 using BLToolkit.Data;
5 using BLToolkit.Data.DataProvider;
6 using BLToolkit.DataAccess;
7
8 using NUnit.Framework;
9
10 namespace Data
11 {
12 [TestFixture]
13 public class OutputParameter
14 {
15 [Test]
16 public void DirectTest()
17 {
18 using (DbManager db = new DbManager())
19 {
20 string paramName = (string) db.DataProvider.Convert("name", ConvertType.NameToQueryParameter);
21 string fieldName = (string) db.DataProvider.Convert("FirstName", ConvertType.NameToQueryField);
22
23 db.SetCommand(string.Format("SELECT {0} = {1} FROM Person WHERE PersonID = 1", paramName, fieldName)
24 , db.OutputParameter(paramName, DbType.String, 50))
25 .ExecuteNonQuery();
26 Assert.AreEqual("John", db.Parameter(paramName).Value);
27 }
28 }
29
30 public abstract class TestAccessor : DataAccessor
31 {
32 [SqlQuery("SELECT {0} = {1} FROM Person WHERE PersonID = 1")]
33 public abstract void SelectJohn([ParamSize(50), ParamDbType(DbType.String)] out string name, [Format] string paramName, [Format] string FieldName);
34 }
35
36 [Test]
37 public void AccessorTest()
38 {
39 using (DbManager db = new DbManager())
40 {
41 string paramName = (string)db.DataProvider.Convert("name", ConvertType.NameToQueryParameter);
42 string fieldName = (string)db.DataProvider.Convert("FirstName", ConvertType.NameToQueryField);
43
44 TestAccessor ta = (TestAccessor)TestAccessor.CreateInstance(typeof(TestAccessor), db);
45
46 string actual;
47 ta.SelectJohn(out actual, paramName, fieldName);
48
49 Assert.AreEqual("John", actual);
50 }
51 }
52 }
53 }