Mercurial > pub > bltoolkit
comparison UnitTests/CS/DataAccess/ArrayTest.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 #if ORACLE | |
2 using BLToolkit.Data; | |
3 #else | |
4 using System.Collections.Generic; | |
5 #endif | |
6 using NUnit.Framework; | |
7 | |
8 using BLToolkit.DataAccess; | |
9 using BLToolkit.TypeBuilder; | |
10 | |
11 namespace DataAccess | |
12 { | |
13 [TestFixture] | |
14 public class ArrayTest | |
15 { | |
16 public ArrayTest() | |
17 { | |
18 TypeFactory.SaveTypes = true; | |
19 } | |
20 | |
21 #if ORACLE | |
22 public abstract class TestAccessor : DataAccessor | |
23 { | |
24 public abstract void ArrayTest( | |
25 int[] @intArray, out int[] @outputIntArray, ref int[] @inputOutputIntArray, | |
26 string[] @strArray, out string[] @outputStrArray, ref string[] @inputOutputStrArray); | |
27 | |
28 [ScalarSource(ScalarSourceType.OutputParameter)] | |
29 public abstract int[] ScalarArray(); | |
30 | |
31 [SqlQuery(@" | |
32 DECLARE | |
33 intArray DBMS_UTILITY.NUMBER_ARRAY; | |
34 BEGIN | |
35 intArray := :intArray; | |
36 FOR i IN intArray.FIRST..intArray.LAST LOOP | |
37 :inputOutputIntArray(i) := intArray(i); | |
38 END LOOP; | |
39 END;" | |
40 )] | |
41 public abstract void Query(int[] @intArray, ref int[] @inputOutputIntArray); | |
42 | |
43 public abstract void ArrayTest( | |
44 int?[] @intArray, out int?[] @outputIntArray, ref int?[] @inputOutputIntArray, | |
45 string[] @strArray, out string[] @outputStrArray, ref string[] @inputOutputStrArray); | |
46 | |
47 [ScalarSource(ScalarSourceType.OutputParameter), SprocName("ScalarArray")] | |
48 public abstract int?[] NullableScalarArray(); | |
49 } | |
50 | |
51 [Test] | |
52 public void Test() | |
53 { | |
54 int[] @outputIntArray; | |
55 int[] @inputOutputIntArray = new int[] {1,2,3,4,5}; | |
56 string[] @outputStrArray; | |
57 string[] @inputOutputStrArray = new string[] {"9","8","7","6","5"}; | |
58 | |
59 ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor))).ArrayTest( | |
60 new int[] {1,2,3,4,5}, out @outputIntArray, ref @inputOutputIntArray, | |
61 new string[] {"5","4","3","2","1"}, out @outputStrArray, ref @inputOutputStrArray); | |
62 | |
63 Assert.AreEqual(new int[] {1,2,3,4,5}, @outputIntArray); | |
64 Assert.AreEqual(new int[] {2,4,6,8,10}, @inputOutputIntArray); | |
65 Assert.AreEqual(new string[] { "5","4","3","2","1"}, @outputStrArray); | |
66 Assert.AreEqual(new string[] { "95","84","73","62","51"}, @inputOutputStrArray); | |
67 } | |
68 | |
69 [Test] | |
70 public void ScalarTest() | |
71 { | |
72 int[] @outputIntArray = ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor))).ScalarArray(); | |
73 | |
74 Assert.AreEqual(new int[] { 1, 2, 3, 4, 5 }, @outputIntArray); | |
75 } | |
76 | |
77 [Test] | |
78 public void NullableTest() | |
79 { | |
80 int?[] @outputIntArray; | |
81 int?[] @inputOutputIntArray = new int?[] {1,2,3,4,5}; | |
82 string[] @outputStrArray; | |
83 string[] @inputOutputStrArray = new string[] {"9","8","7","6","5"}; | |
84 | |
85 ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor))).ArrayTest( | |
86 new int?[] {1,null,3,4,5}, out @outputIntArray, ref @inputOutputIntArray, | |
87 new string[] {"5","4","3","2","1"}, out @outputStrArray, ref @inputOutputStrArray); | |
88 | |
89 Assert.AreEqual(new int?[] {1,0,3,4,5}, @outputIntArray); | |
90 Assert.AreEqual(new int?[] {2,0,6,8,10}, @inputOutputIntArray); | |
91 Assert.AreEqual(new string[] { "5","4","3","2","1"}, @outputStrArray); | |
92 Assert.AreEqual(new string[] { "95","84","73","62","51"}, @inputOutputStrArray); | |
93 } | |
94 | |
95 [Test] | |
96 public void NullableScalarTest() | |
97 { | |
98 int?[] @outputIntArray = ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor))).NullableScalarArray(); | |
99 | |
100 Assert.AreEqual(new int?[] { 1, 2, 3, 4, 5 }, @outputIntArray); | |
101 } | |
102 | |
103 [Test] | |
104 public void QueryTest() | |
105 { | |
106 int[] intArray = new int[]{1,2,3,4,5}; | |
107 int[] inputOutputIntArray = new int[5]; | |
108 | |
109 ((TestAccessor)DataAccessor.CreateInstance(typeof(TestAccessor))).Query( | |
110 intArray, ref inputOutputIntArray); | |
111 | |
112 Assert.AreEqual(intArray, inputOutputIntArray); | |
113 } | |
114 | |
115 | |
116 #elif MSSQL | |
117 | |
118 public abstract class TestAccessor : DataAccessor | |
119 { | |
120 [SprocName("ArrayTest")] | |
121 public abstract IList<int> SprocTest(int[] @inputIntArray); | |
122 [SqlQuery("SELECT Num * 3 FROM @inputIntArray")] | |
123 public abstract IList<int> QueryTest([ParamTypeName("IntArray")] int[] @inputIntArray); | |
124 } | |
125 | |
126 [Test] | |
127 public void Test() | |
128 { | |
129 int[] intArray = { 1, 2, 3, 4, 5 }; | |
130 | |
131 TestAccessor a = TypeFactory.CreateInstance<TestAccessor>(); | |
132 IList<int> list; | |
133 | |
134 list = a.SprocTest(intArray); | |
135 for (int i = 0; i < list.Count; i++) | |
136 Assert.That(list[i], Is.EqualTo(intArray[i]*2)); | |
137 list = a.QueryTest(intArray); | |
138 for (int i = 0; i < list.Count; i++) | |
139 Assert.That(list[i], Is.EqualTo(intArray[i]*3)); | |
140 } | |
141 #endif | |
142 } | |
143 } |