comparison UnitTests/CS/DataAccess/DataAccessorBuilderTest.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.Collections;
3 using System.Data;
4 using System.Reflection;
5 using NUnit.Framework;
6
7 using BLToolkit.DataAccess;
8 using BLToolkit.TypeBuilder;
9
10 namespace DataAccess
11 {
12 [TestFixture]
13 public class DataAccessorBuilderTest : MarshalByRefObject
14 {
15 DataAccessorBuilderTest _localTest;
16 AppDomain _localDomain;
17
18 public struct Person
19 {
20 }
21
22 [TestFixtureSetUp]
23 public void SetUp()
24 {
25 string path = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
26
27 _localDomain = AppDomain.CreateDomain("NewDomain");
28 _localDomain.Load(typeof(DataAccessor).Assembly.GetName());
29 _localTest = (DataAccessorBuilderTest)_localDomain.CreateInstanceFromAndUnwrap(path, GetType().FullName);
30 }
31
32 [TestFixtureTearDown]
33 public void TearDown()
34 {
35 AppDomain.Unload(_localDomain);
36 }
37
38 public abstract class TypelessAccessor : DataAccessor
39 {
40 [SqlQuery("SELECT * FROM Person WHERE PersonID < 3")]
41 public abstract Hashtable Typeless();
42 }
43
44 private void Typeless()
45 {
46 // Can not determine object type for the method 'TypelessAccessor.Typeless'
47 //
48 DataAccessor.CreateInstance(typeof(TypelessAccessor));
49 }
50
51 [Test, ExpectedException(typeof(TypeBuilderException))]
52 public void TypelessTest()
53 {
54 AppDomain.CurrentDomain.DoCallBack(_localTest.Typeless);
55 }
56
57 public abstract class TypelessAccessor2 : DataAccessor
58 {
59 [SprocName("Person_SelectAll")]
60 public abstract ArrayList Typeless();
61 }
62
63 private void Typeless2()
64 {
65 // Can not determine object type for the method 'TypelessAccessor2.Typeless'
66 //
67 DataAccessor.CreateInstance(typeof(TypelessAccessor2));
68 }
69
70 [Test, ExpectedException(typeof(TypeBuilderException))]
71 public void Gen_SelectAllListException()
72 {
73 AppDomain.CurrentDomain.DoCallBack(_localTest.Typeless2);
74 }
75
76 public abstract class MultiDestinationAccessor : DataAccessor
77 {
78 [ObjectType(typeof(Person))]
79 public abstract IList SelectAll([Destination] IList list1, [Destination] IList list2);
80 }
81
82 private void MultiDestinationException()
83 {
84 // More then one parameter is marked as destination.
85 //
86 DataAccessor.CreateInstance(typeof(MultiDestinationAccessor));
87 }
88
89 [Test, ExpectedException(typeof(TypeBuilderException))]
90 public void MultiDestinationExceptionTest()
91 {
92 AppDomain.CurrentDomain.DoCallBack(_localTest.MultiDestinationException);
93 }
94
95 public abstract class ScalarDestinationAccessor : DataAccessor
96 {
97 [ObjectType(typeof(Person))]
98 public abstract int SelectAll([Destination] int p);
99 }
100
101 private void ScalarDestinationException()
102 {
103 // ExecuteScalar destination must be an out or a ref parameter
104 //
105 DataAccessor.CreateInstance(typeof(ScalarDestinationAccessor));
106 }
107
108 [Test, ExpectedException(typeof(TypeBuilderException))]
109 public void ScalarDestinationExceptionTest()
110 {
111 AppDomain.CurrentDomain.DoCallBack(_localTest.ScalarDestinationException);
112 }
113
114 public abstract class IncompatibleScalarDestinationAccessor : DataAccessor
115 {
116 [ObjectType(typeof(Person))]
117 public abstract int SelectAll([Destination] out string p);
118 }
119
120 private void IncompatibleScalarDestinationException()
121 {
122 // The return type 'System.Int32' of the method 'SelectAll'
123 // is incompatible with the destination parameter type 'System.String'
124 //
125 DataAccessor.CreateInstance(typeof(IncompatibleScalarDestinationAccessor));
126 }
127
128 [Test, ExpectedException(typeof(TypeBuilderException))]
129 public void IncompatibleScalarDestinationExceptionTest()
130 {
131 AppDomain.CurrentDomain.DoCallBack(_localTest.IncompatibleScalarDestinationException);
132 }
133
134 public abstract class VoidDestinationAccessor : DataAccessor
135 {
136 [ObjectType(typeof(Person))]
137 public abstract void SelectAll([Destination] int p);
138 }
139
140 private void VoidDestinationException()
141 {
142 // ExecuteNonQuery does not support the Destination attribute
143 //
144 DataAccessor.CreateInstance(typeof(VoidDestinationAccessor));
145 }
146
147 [Test, ExpectedException(typeof(TypeBuilderException))]
148 public void VoidDestinationExceptionTest()
149 {
150 AppDomain.CurrentDomain.DoCallBack(_localTest.VoidDestinationException);
151 }
152
153 public abstract class IllegalDataSetTableAccessor : DataAccessor
154 {
155 [DataSetTable(12345)]
156 public abstract DataTable SelectAll();
157 }
158
159 private void IllegalDataSetTable()
160 {
161 // DataSetTable attribute may not be an index
162 //
163 DataAccessor.CreateInstance(typeof(IllegalDataSetTableAccessor));
164 }
165
166 [Test, ExpectedException(typeof(TypeBuilderException))]
167 public void IllegalDataSetTableTest()
168 {
169 AppDomain.CurrentDomain.DoCallBack(_localTest.IllegalDataSetTable);
170 }
171 }
172 }