Mercurial > pub > bltoolkit
comparison UnitTests/Linq/ProviderSpecific/Oracle.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.Data.Linq.Mapping; | |
3 using System.Linq; | |
4 | |
5 using BLToolkit.Data; | |
6 using BLToolkit.Data.DataProvider; | |
7 using BLToolkit.Data.Linq; | |
8 using BLToolkit.DataAccess; | |
9 using BLToolkit.Mapping; | |
10 | |
11 using NUnit.Framework; | |
12 | |
13 using UnitTests.Linq.Interface.Model; | |
14 | |
15 namespace Data.Linq.ProviderSpecific | |
16 { | |
17 using Model; | |
18 | |
19 [TestFixture, Category("Oracle")] | |
20 public class Oracle : TestBase | |
21 { | |
22 #region Sequence | |
23 | |
24 [Test] | |
25 public void SequenceInsert([IncludeDataContexts("Oracle")] string context) | |
26 { | |
27 using (var db = new TestDbManager(context)) | |
28 { | |
29 db.GetTable<OracleSpecific.SequenceTest>().Where(_ => _.Value == "SeqValue").Delete(); | |
30 db.Insert(new OracleSpecific.SequenceTest { Value = "SeqValue" }); | |
31 | |
32 var id = db.GetTable<OracleSpecific.SequenceTest>().Single(_ => _.Value == "SeqValue").ID; | |
33 | |
34 db.GetTable<OracleSpecific.SequenceTest>().Where(_ => _.ID == id).Delete(); | |
35 | |
36 Assert.AreEqual(0, db.GetTable<OracleSpecific.SequenceTest>().Count(_ => _.Value == "SeqValue")); | |
37 } | |
38 } | |
39 | |
40 [Test] | |
41 public void SequenceInsertWithIdentity([IncludeDataContexts("Oracle")] string context) | |
42 { | |
43 using (var db = new TestDbManager(context)) | |
44 { | |
45 db.GetTable<OracleSpecific.SequenceTest>().Where(_ => _.Value == "SeqValue").Delete(); | |
46 | |
47 var id1 = Convert.ToInt32(db.InsertWithIdentity(new OracleSpecific.SequenceTest { Value = "SeqValue" })); | |
48 var id2 = db.GetTable<OracleSpecific.SequenceTest>().Single(_ => _.Value == "SeqValue").ID; | |
49 | |
50 Assert.AreEqual(id1, id2); | |
51 | |
52 db.GetTable<OracleSpecific.SequenceTest>().Where(_ => _.ID == id1).Delete(); | |
53 | |
54 Assert.AreEqual(0, db.GetTable<OracleSpecific.SequenceTest>().Count(_ => _.Value == "SeqValue")); | |
55 } | |
56 } | |
57 | |
58 #endregion | |
59 | |
60 #region InsertBatch | |
61 | |
62 [Table(Name = "stg_trade_information")] | |
63 public class Trade | |
64 { | |
65 [MapField("STG_TRADE_ID")] public int ID { get; set; } | |
66 [MapField("STG_TRADE_VERSION")] public int Version { get; set; } | |
67 [MapField("INFORMATION_TYPE_ID")] public int TypeID { get; set; } | |
68 [MapField("INFORMATION_TYPE_NAME")] public string TypeName { get; set; } | |
69 [MapField("value")] public string Value { get; set; } | |
70 [MapField("value_as_integer")] public int? ValueAsInteger { get; set; } | |
71 [MapField("value_as_date")] public DateTime? ValueAsDate { get; set; } | |
72 } | |
73 | |
74 [Test] | |
75 public void InsertBatch1([IncludeDataContexts("Oracle")] string context) | |
76 { | |
77 var data = new[] | |
78 { | |
79 new Trade { ID = 375, Version = 1, TypeID = 20224, TypeName = "Gas Month", }, | |
80 new Trade { ID = 328, Version = 1, TypeID = 20224, TypeName = "Gas Month", }, | |
81 new Trade { ID = 348, Version = 1, TypeID = 20224, TypeName = "Gas Month", }, | |
82 new Trade { ID = 357, Version = 1, TypeID = 20224, TypeName = "Gas Month", }, | |
83 new Trade { ID = 371, Version = 1, TypeID = 20224, TypeName = "Gas Month", }, | |
84 new Trade { ID = 333, Version = 1, TypeID = 20224, TypeName = "Gas Month", ValueAsInteger = 1, ValueAsDate = new DateTime(2011, 1, 5) }, | |
85 new Trade { ID = 353, Version = 1, TypeID = 20224, TypeName = "Gas Month", ValueAsInteger = 1000000000, }, | |
86 new Trade { ID = 973, Version = 1, TypeID = 20160, TypeName = "EU Allowances", }, | |
87 }; | |
88 | |
89 using (var db = new TestDbManager(context)) | |
90 { | |
91 db.InsertBatch(5, data); | |
92 } | |
93 } | |
94 | |
95 [Test] | |
96 public void InsertBatch2([IncludeDataContexts("Oracle")] string context) | |
97 { | |
98 using (var db = new TestDbManager(context)) | |
99 { | |
100 db.Types2.Delete(_ => _.ID > 1000); | |
101 | |
102 db.InsertBatch(2, new[] | |
103 { | |
104 new LinqDataTypes2 { ID = 1003, MoneyValue = 0m, DateTimeValue = null, BoolValue = true, GuidValue = new Guid("ef129165-6ffe-4df9-bb6b-bb16e413c883"), SmallIntValue = null, IntValue = null }, | |
105 new LinqDataTypes2 { ID = 1004, MoneyValue = 0m, DateTimeValue = DateTime.Now, BoolValue = false, GuidValue = null, SmallIntValue = 2, IntValue = 1532334 }, | |
106 new LinqDataTypes2 { ID = 1005, MoneyValue = 1m, DateTimeValue = DateTime.Now, BoolValue = false, GuidValue = null, SmallIntValue = 5, IntValue = null }, | |
107 new LinqDataTypes2 { ID = 1006, MoneyValue = 2m, DateTimeValue = DateTime.Now, BoolValue = false, GuidValue = null, SmallIntValue = 6, IntValue = 153 }, | |
108 }); | |
109 | |
110 db.Types2.Delete(_ => _.ID > 1000); | |
111 } | |
112 } | |
113 | |
114 #endregion | |
115 | |
116 #region Transaction | |
117 | |
118 [TableName("demo_product_info")] | |
119 public new class Product | |
120 { | |
121 [MapField("PRODUCT_ID"), PrimaryKey, NonUpdatable] | |
122 public int Id; | |
123 | |
124 [MapField("PRODUCT_NAME")] | |
125 public string Name; | |
126 | |
127 [MapField("PRODUCT_DESCRIPTION")] | |
128 public string Description; | |
129 } | |
130 | |
131 public abstract class ProductEntityAccesor : DataAccessor<Product> | |
132 { | |
133 public abstract int Insert(Product product); | |
134 public abstract void Delete(int id); | |
135 public abstract Product SelectByKey(int id); | |
136 public abstract Product SelectByKey(DbManager db, int id); | |
137 } | |
138 | |
139 //[Test] | |
140 public void CanInsertProductWithAccessorTest([IncludeDataContexts("Oracle")] string context) | |
141 { | |
142 using (var dbManager = new TestDbManager(context)) | |
143 { | |
144 var productEntityAccesor = DataAccessor.CreateInstance<ProductEntityAccesor>(dbManager); | |
145 | |
146 productEntityAccesor.BeginTransaction(); | |
147 | |
148 var id = productEntityAccesor.Insert(new Product { Name = "product name test", Description = "product description test" }); | |
149 //This assert fails bacause id == 0 and it does not insert until the CommitTransaction is called. | |
150 Assert.AreNotEqual(0, id); | |
151 | |
152 Product product = productEntityAccesor.SelectByKey(id); | |
153 Assert.IsNotNull(product); | |
154 | |
155 productEntityAccesor.Delete(id); | |
156 | |
157 productEntityAccesor.CommitTransaction(); | |
158 } | |
159 } | |
160 | |
161 #endregion | |
162 } | |
163 } |