comparison UnitTests/CS/Data/BinaryTest.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.Data;
6 using BLToolkit.Data.DataProvider;
7
8 namespace Data
9 {
10 [TestFixture]
11 public class BinaryTest
12 {
13 public class BinaryData
14 {
15 public int BinaryDataID;
16 public byte[] Stamp;
17 public byte[] Data;
18 }
19
20 [Test]
21 public void Test()
22 {
23 using (DbManager db = new DbManager())
24 {
25 object id;
26 #if ORACLE
27 id = db
28 .SetCommand("INSERT INTO BinaryData (Data) VALUES (:pData) RETURNING BinaryDataID INTO :pID",
29 db.Parameter("pData", new byte[] { 1, 2, 3, 4, 5}),
30 db.OutputParameter("pID", System.Data.DbType.Int32)
31 )
32 .ExecuteScalar(ScalarSourceType.OutputParameter, "ID");
33 #elif MSSQL
34 id = db
35 .SetCommand("INSERT INTO BinaryData (Data) VALUES (@Data)\nSELECT Cast(SCOPE_IDENTITY() as int)",
36 db.Parameter("@Data", new byte[] { 1, 2, 3, 4, 5}))
37 .ExecuteScalar();
38 #elif FIREBIRD
39 db
40 .SetCommand("INSERT INTO BinaryData (Data) VALUES (@Data)",
41 db.Parameter("@Data", new byte[] { 1, 2, 3, 4, 5}))
42 .ExecuteNonQuery();
43
44 id = db
45 .SetCommand("SELECT GEN_ID(PersonID, 0) FROM dual")
46 .ExecuteScalar();
47 #elif ACCESS || SQLCE
48 db
49 .SetCommand("INSERT INTO BinaryData (Data) VALUES (@Data)",
50 db.Parameter("@Data", new byte[] { 1, 2, 3, 4, 5}))
51 .ExecuteNonQuery();
52
53 id = db
54 .SetCommand("SELECT @@IDENTITY")
55 .ExecuteScalar();
56 #elif SQLITE
57 db
58 .SetCommand("INSERT INTO BinaryData (Stamp, Data) VALUES (datetime('now'), @Data)",
59 db.Parameter("@Data", new byte[] { 1, 2, 3, 4, 5}))
60 .ExecuteNonQuery();
61
62 id = db
63 .SetCommand("SELECT last_insert_rowid()")
64 .ExecuteScalar();
65 #else
66 Assert.Fail("Unknown DB type.");
67 #endif
68
69 BinaryData bd = (BinaryData)db
70 .SetCommand(
71 "SELECT * FROM BinaryData WHERE BinaryDataID = " + db.DataProvider.Convert("id", ConvertType.NameToQueryParameter),
72 db.Parameter("id", id))
73 .ExecuteObject(typeof(BinaryData));
74
75 Assert.IsNotNull(bd);
76 Assert.AreEqual(5, bd.Data. Length);
77 #if FIREBIRD
78 // Stamps are integers in Firebird.
79 //
80 Assert.AreEqual(4, bd.Stamp.Length);
81 #elif ACCESS || SQLCE
82 // Not supported in MS Access
83 //
84 Assert.IsNull(bd.Stamp);
85 #else
86 Assert.AreEqual(8, bd.Stamp.Length);
87 #endif
88
89 db
90 #if FIREBIRD || ACCESS || SQLCE || SQLITE
91 .SetCommand("DELETE FROM BinaryData")
92 #else
93 .SetCommand("TRUNCATE TABLE BinaryData")
94 #endif
95 .ExecuteNonQuery();
96 }
97 }
98 }
99 }