Mercurial > pub > bltoolkit
comparison UnitTests/CS/DataAccess/DataTypeTest.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.ComponentModel; | |
4 using System.Data; | |
5 using System.Data.SqlTypes; | |
6 using System.IO; | |
7 using System.Text; | |
8 using System.Xml; | |
9 using BLToolkit.Data.DataProvider; | |
10 using BLToolkit.Reflection.Extension; | |
11 using NUnit.Framework; | |
12 | |
13 #if FW2 | |
14 using System.Collections.Generic; | |
15 using PersonDataSet = DataAccessTest.PersonDataSet2; | |
16 #else | |
17 using PersonDataSet = DataAccessTest.PersonDataSet; | |
18 #endif | |
19 | |
20 using BLToolkit.EditableObjects; | |
21 using BLToolkit.Data; | |
22 using BLToolkit.DataAccess; | |
23 using BLToolkit.Mapping; | |
24 using BLToolkit.Validation; | |
25 using BLToolkit.Reflection; | |
26 using BLToolkit.TypeBuilder; | |
27 | |
28 namespace DataAccess | |
29 { | |
30 [TestFixture] | |
31 public class DataTypeTest | |
32 { | |
33 [TableName("DataTypeTest")] | |
34 public abstract class ScalarData | |
35 { | |
36 [MapField("DataTypeID"), PrimaryKey, NonUpdatable] | |
37 public abstract int ID { get; set; } | |
38 [MapIgnore(false)] | |
39 public abstract Byte[] Binary_ { get; set; } | |
40 public abstract Boolean Boolean_ { get; set; } | |
41 public abstract Byte Byte_ { get; set; } | |
42 [MapIgnore(false)] | |
43 public abstract Byte[] Bytes_ { get; set; } | |
44 [NullDateTime] | |
45 public abstract DateTime DateTime_ { get; set; } | |
46 public abstract Decimal Decimal_ { get; set; } | |
47 public abstract Double Double_ { get; set; } | |
48 public abstract Guid Guid_ { get; set; } | |
49 public abstract Int16 Int16_ { get; set; } | |
50 public abstract Int32 Int32_ { get; set; } | |
51 public abstract Int64 Int64_ { get; set; } | |
52 public abstract Decimal Money_ { get; set; } | |
53 public abstract Single Single_ { get; set; } | |
54 public abstract String String_ { get; set; } | |
55 #if FW2 | |
56 public abstract Char Char_ { get; set; } | |
57 // public abstract SByte SByte_ { get; set; } | |
58 // [MapIgnore(false)] | |
59 // public abstract Stream Stream_ { get; set; } | |
60 // public abstract UInt16 UInt16_ { get; set; } | |
61 // public abstract UInt32 UInt32_ { get; set; } | |
62 // public abstract UInt64 UInt64_ { get; set; } | |
63 // public abstract XmlReader Xml_ { get; set; } | |
64 #endif | |
65 } | |
66 | |
67 [TableName("DataTypeTest")] | |
68 public class SqlData | |
69 { | |
70 [MapField("DataTypeID"), PrimaryKey, NonUpdatable] | |
71 public int ID; | |
72 public SqlBinary Binary_; | |
73 /* public SqlBoolean Boolean_; | |
74 public SqlByte Byte_; | |
75 public SqlDateTime DateTime_; | |
76 public SqlDecimal Decimal_; | |
77 public SqlDouble Double_; | |
78 public SqlGuid Guid_; | |
79 public SqlInt16 Int16_; | |
80 public SqlInt32 Int32_; | |
81 public SqlInt64 Int64_; | |
82 public SqlMoney Money_; | |
83 public SqlSingle Single_; | |
84 public SqlString String_; | |
85 #if FW2 | |
86 [MapIgnore(false)] | |
87 public SqlBytes Bytes_; | |
88 [MapIgnore(false)] | |
89 public SqlChars Char_; | |
90 [MapIgnore(false)] | |
91 public SqlXml Xml_; | |
92 #endif | |
93 */ } | |
94 | |
95 | |
96 public abstract class DataTypeAccessor : DataAccessor | |
97 { | |
98 public abstract void Insert([Direction.Output("@DataTypeID")] ScalarData data); | |
99 } | |
100 | |
101 private DataTypeAccessor _da; | |
102 private SprocQuery _sproc = new SprocQuery(); | |
103 private SqlQuery _sql = new SqlQuery(); | |
104 | |
105 public DataTypeTest() | |
106 { | |
107 TypeFactory.SaveTypes = true; | |
108 | |
109 object o = TypeAccessor.CreateInstance(typeof(ScalarData)); | |
110 Assert.IsInstanceOfType(typeof(ScalarData), o); | |
111 | |
112 _da = (DataTypeAccessor)DataAccessor.CreateInstance(typeof(DataTypeAccessor)); | |
113 Assert.IsInstanceOfType(typeof(DataTypeAccessor), _da); | |
114 } | |
115 | |
116 [Test] | |
117 public void Sql_Scalar_InsertDeleteTest() | |
118 { | |
119 ArrayList list = _sql.SelectAll(typeof(ScalarData)); | |
120 Hashtable tbl = new Hashtable(); | |
121 | |
122 foreach (ScalarData d in list) | |
123 tbl[d.ID] = d; | |
124 | |
125 ScalarData data = (ScalarData) TypeAccessor.CreateInstance(typeof(ScalarData)); | |
126 | |
127 _sql.Insert(data); | |
128 | |
129 list = _sql.SelectAll(typeof(ScalarData)); | |
130 | |
131 foreach (ScalarData d in list) | |
132 if (tbl.ContainsKey(d.ID) == false) | |
133 _sql.Delete(d); | |
134 } | |
135 | |
136 [Test] | |
137 public void Sql_SqlTypes_InsertDeleteTest() | |
138 { | |
139 ArrayList list = _sql.SelectAll(typeof(SqlData)); | |
140 Hashtable tbl = new Hashtable(); | |
141 | |
142 foreach (SqlData d in list) | |
143 tbl[d.ID] = d; | |
144 | |
145 SqlData data = (SqlData) TypeAccessor.CreateInstance(typeof(SqlData)); | |
146 | |
147 _sql.Insert(data); | |
148 | |
149 list = _sql.SelectAll(typeof(SqlData)); | |
150 | |
151 foreach (SqlData d in list) | |
152 if (tbl.ContainsKey(d.ID) == false) | |
153 _sql.Delete(d); | |
154 } | |
155 | |
156 [Test] | |
157 public void SunsetByHands() | |
158 { | |
159 using (DbManager db = new DbManager()) | |
160 { | |
161 db | |
162 .SetCommand(@"INSERT INTO DataTypeTest (Binary_) VALUES (@Binary)", db.Parameter("@Binary", SqlBinary.Null)) | |
163 .ExecuteNonQuery() | |
164 ; | |
165 } | |
166 } | |
167 } | |
168 } | |
169 |