comparison UnitTests/CS/DataAccess/OutRefTest.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.DataAccess;
6 using BLToolkit.TypeBuilder;
7
8 namespace DataAccess
9 {
10 [TestFixture]
11 public class OutRefTest
12 {
13 public class Entity
14 {
15 public int ID = 5;
16 public int outputID;
17 public int inputOutputID = 10;
18 public string str = "5";
19 public string outputStr;
20 public string inputOutputStr = "10";
21 }
22
23 public abstract class TestAccessor : DataAccessor
24 {
25 public abstract void OutRefTest(
26 int @ID, out int @outputID, ref int @inputOutputID,
27 string @str, out string @outputStr, ref string @inputOutputStr);
28
29 [SprocName("OutRefTest")]
30 public abstract void OutRefTest2(
31 [ParamNullValue(-1)] int ID,
32 [ParamNullValue(-2)] out int outputID,
33 [ParamNullValue(-3)] ref int inputOutputID,
34 [ParamNullValue("A")] string str,
35 [ParamNullValue("B")] out string outputStr,
36 [ParamNullValue("C")] ref string inputOutputStr);
37
38 public abstract void OutRefTest(out int outputID,
39 [Direction.InputOutput("inputOutputID", "inputOutputStr"), Direction.Output("outputStr", "outputID")] Entity entity,
40 ref string inputOutputStr);
41 }
42
43 [Test]
44 public void Test1()
45 {
46 int @outputID;
47 int @inputOutputID = 10;
48 string @outputStr;
49 string @inputOutputStr = "10";
50
51 ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor)))
52 .OutRefTest(5, out @outputID, ref @inputOutputID,
53 "5", out @outputStr, ref @inputOutputStr);
54
55 Assert.AreEqual(5, @outputID);
56 Assert.AreEqual(15, @inputOutputID);
57 Assert.AreEqual("5", @outputStr);
58 Assert.AreEqual("510", @inputOutputStr);
59 }
60
61 [Test]
62 public void Test2()
63 {
64 Entity e = new Entity();
65 int @outputID;
66 string @inputOutputStr = "20";
67
68 ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor)))
69 .OutRefTest(out @outputID, e, ref @inputOutputStr);
70
71 Assert.AreEqual(5, e.outputID);
72 Assert.AreEqual(5, @outputID);
73 Assert.AreEqual(15, e.inputOutputID);
74 Assert.AreEqual("5", e.outputStr);
75 Assert.AreEqual("510", e.inputOutputStr);
76 Assert.AreEqual("510", @inputOutputStr);
77 }
78
79 [Test]
80 public void NullValueTest()
81 {
82 int @outputID;
83 int @inputOutputID = 10;
84 string @outputStr;
85 string @inputOutputStr = "C";
86
87 ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor)))
88 .OutRefTest2(-1, out @outputID, ref @inputOutputID,
89 "A", out @outputStr, ref @inputOutputStr);
90
91 Assert.AreEqual(-2, @outputID);
92 Assert.AreEqual(-3, @inputOutputID);
93 Assert.AreEqual("B", @outputStr);
94 Assert.AreEqual("C", @inputOutputStr);
95 }
96
97 public class NullableEntity
98 {
99 public int? ID = null;
100 public int? outputID;
101 public int? inputOutputID = 20;
102 public string str = null;
103 public string outputStr;
104 public string inputOutputStr = "40";
105 }
106
107 public abstract class TestNullableAccessor : DataAccessor
108 {
109 public abstract void OutRefTest(
110 int? @ID, out int? @outputID, ref int? @inputOutputID,
111 string @str, out string @outputStr, ref string @inputOutputStr);
112
113 public abstract void OutRefTest(
114 out int? @outputID,
115 [Direction.InputOutput("inputOutputID", "inputOutputStr"), Direction.Output("outputStr", "outputID")] NullableEntity entity,
116 ref string @inputOutputStr);
117
118 }
119
120 [Test]
121 public void TestNullable1()
122 {
123 int? @outputID;
124 int? @inputOutputID = 10;
125 string @outputStr;
126 string @inputOutputStr = "";
127
128 DataAccessor.CreateInstance<TestNullableAccessor>()
129 .OutRefTest(null, out @outputID, ref @inputOutputID,
130 null, out @outputStr, ref @inputOutputStr);
131
132 Assert.IsNull (@outputID);
133 Assert.IsNull (@inputOutputID);
134 Assert.IsEmpty(@outputStr);
135 Assert.IsEmpty(@inputOutputStr);
136 }
137
138 [Test]
139 public void TestNullable2()
140 {
141 NullableEntity e = new NullableEntity();
142 int? @outputID;
143 string @inputOutputStr = "20";
144 e.str = "20";
145
146 DataAccessor.CreateInstance<TestNullableAccessor>()
147 .OutRefTest(out @outputID, e, ref @inputOutputStr);
148
149 Assert.IsNull (@outputID);
150 Assert.AreEqual("20", e.outputStr);
151 Assert.IsNull (e.inputOutputID);
152 Assert.AreEqual("2040", @inputOutputStr);
153 }
154 }
155 }