comparison UnitTests/Linq/TestAK107.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 BLToolkit.Data.Linq;
4 using BLToolkit.Data.Sql.SqlProvider;
5 using BLToolkit.DataAccess;
6 using BLToolkit.Mapping;
7
8 using NUnit.Framework;
9
10 namespace Data.Linq
11 {
12 [TestFixture, Category("Oracle")]
13 public class TestAK107 : TestBase
14 {
15 [TableName(Name = "t_test_user")]
16 public sealed class User
17 {
18 [PrimaryKey, Identity]
19 [SequenceName("sq_test_user")]
20 [MapField("user_id")]
21 public long Id { get; set; }
22
23 [NotNull, NonUpdatable(OnInsert = false)]
24 [MapField("name")]
25 public string Name { get; set; }
26 }
27
28 [TableName(Name = "t_test_user_contract")]
29 public sealed class Contract
30 {
31 [PrimaryKey, Identity]
32 [SequenceName("sq_test_user_contract")]
33 [MapField("user_contract_id")]
34 public long Id { get; set; }
35
36 [NotNull, NonUpdatable(OnInsert = false)]
37 [MapField("user_id")]
38 public long UserId { get; set; }
39
40 [Association(ThisKey = "UserId", OtherKey = "Id", CanBeNull = false)]
41 public User User { get; set; }
42
43 [NotNull, NonUpdatable(OnInsert = false)]
44 [MapField("contract_no")]
45 public long ContractNo { get; set; }
46
47 [NotNull]
48 [MapField("name")]
49 public string Name { get; set; }
50 }
51
52 [Test]
53 public void UserInsert([IncludeDataContexts("Oracle")] string context)
54 {
55 using (var db = new TestDbManager(context))
56 {
57 db.BeginTransaction();
58 db.Insert(new User { Name = "user" });
59 }
60 }
61
62 [Test]
63 public void UserInsertWithIdentity([IncludeDataContexts("Oracle")] string context)
64 {
65 using (var db = new TestDbManager(context))
66 {
67 db.BeginTransaction();
68 db.InsertWithIdentity(new User { Name = "user" });
69 }
70 }
71
72 [Test]
73 public void UserLinqInsert([IncludeDataContexts("Oracle")] string context)
74 {
75 using (var db = new TestDbManager(context))
76 {
77 db.BeginTransaction();
78 db.GetTable<User>().Insert(() => new User { Name = "user" });
79 }
80 }
81
82 [Test]
83 public void UserLinqInsertWithIdentity([IncludeDataContexts("Oracle")] string context)
84 {
85 using (var db = new TestDbManager(context))
86 {
87 db.BeginTransaction();
88 db.GetTable<User>().InsertWithIdentity(() => new User { Name = "user" });
89 }
90 }
91
92 [Test]
93 public void ContractInsert([IncludeDataContexts("Oracle")] string context)
94 {
95 using (var db = new TestDbManager(context))
96 {
97 db.BeginTransaction();
98
99 var user = new User { Name = "user" };
100 user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
101
102 db.Insert(new Contract { UserId = user.Id, ContractNo = 1, Name = "contract1" });
103 }
104 }
105
106 [Test]
107 public void ContractInsertWithIdentity([IncludeDataContexts("Oracle")] string context)
108 {
109 using (var db = new TestDbManager(context))
110 {
111 db.BeginTransaction();
112
113 var user = new User { Name = "user" };
114 user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
115
116 db.InsertWithIdentity(new Contract { UserId = user.Id, ContractNo = 1, Name = "contract" });
117 }
118 }
119
120 [SqlExpression("sq_test_user_contract.nextval")]
121 static long ContractSequence { get; set; }
122
123 [Test]
124 public void ContractLinqInsert([IncludeDataContexts("Oracle")] string context)
125 {
126 using (var db = new TestDbManager(context))
127 {
128 db.BeginTransaction();
129
130 var user = new User { Name = "user" };
131 user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
132
133 db.GetTable<Contract>().Insert(() => new Contract
134 {
135 Id = ContractSequence,
136 UserId = user.Id,
137 ContractNo = 1,
138 Name = "contract"
139 });
140 }
141 }
142
143 [Test]
144 public void ContractLinqInsertWithIdentity([IncludeDataContexts("Oracle")] string context)
145 {
146 using (var db = new TestDbManager(context))
147 {
148 db.BeginTransaction();
149
150 var user = new User { Name = "user" };
151 user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
152
153 db.GetTable<Contract>().InsertWithIdentity(() => new Contract { UserId = user.Id, ContractNo = 1, Name = "contract" });
154 }
155 }
156
157 [Test]
158 public void ContractLinqManyInsert([IncludeDataContexts("Oracle")] string context)
159 {
160 using (var db = new TestDbManager(context))
161 {
162 db.BeginTransaction();
163
164 var user = new User { Name = "user" };
165 user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
166
167 db.GetTable<User>().Insert(db.GetTable<Contract>(), x => new Contract { UserId = x.Id, ContractNo = 1, Name = "contract" });
168 }
169 }
170
171 //[Test]
172 public void ContractLinqManyInsertWithIdentity([IncludeDataContexts("Oracle")] string context)
173 {
174 using (var db = new TestDbManager(context))
175 {
176 db.BeginTransaction();
177
178 var user = new User { Name = "user" };
179 user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
180
181 db.GetTable<User>().InsertWithIdentity(db.GetTable<Contract>(), x => new Contract
182 {
183 UserId = x.Id, ContractNo = 1, Name = "contract"
184 });
185 }
186 }
187 }
188 }