-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathIssueJira0565_IgnoringTakeMethodOnTranslation.cs
314 lines (289 loc) · 11.6 KB
/
IssueJira0565_IgnoringTakeMethodOnTranslation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// Copyright (C) 2015 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexey Kulakov
// Created: 2015.02.06
using NUnit.Framework;
using TestCommon.Model;
using Xtensive.Orm.Providers;
using Xtensive.Orm.Tests;
namespace Xtensive.Orm.BulkOperations.Tests.Issues
{
public class IssueJira0565_IgnoringTakeMethodOnTranslation : BulkOperationBaseTest
{
[Test]
public void UpdateOperationWithoutLimitation01()
{
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>();
var expectedUpdatedCount = baseQuery.Count();
var updatedCount = baseQuery.Set(el => el.Description, "UpdatedAgain").Update();
Assert.That(updatedCount, Is.EqualTo(expectedUpdatedCount));
var updatedList = baseQuery.Where(el => el.Description == "UpdatedAgain").ToList();
Assert.That(updatedList.Count, Is.EqualTo(expectedUpdatedCount));
}
}
[Test]
public void UpdateOperationWithoutLimitation02()
{
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>().Where(el => el.Id < 51).Union(session.Query.All<Bar>().Where(el => el.Id > 200));
var expectedUpdatedCount = baseQuery.Count();
var updatedCount = baseQuery.Set(el => el.Description, "UpdatedAgain").Update();
Assert.That(updatedCount, Is.EqualTo(expectedUpdatedCount));
var updatedList = session.Query.All<Bar>().Where(el => el.Description == "UpdatedAgain").ToList();
Assert.That(updatedList.Count, Is.EqualTo(expectedUpdatedCount));
}
}
[Test]
public void DeleteOperationWithoutLimitation01()
{
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>();
var expectedDeletedCount = baseQuery.Count();
var deletedCount = baseQuery.Delete();
Assert.That(deletedCount, Is.EqualTo(expectedDeletedCount));
var updatedList = baseQuery.ToList();
Assert.That(updatedList.Count, Is.EqualTo(0));
}
}
[Test]
public void DeleteOperationWithoutLimitation02()
{
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>().Where(el => el.Id < 51)
.Union(session.Query.All<Bar>().Where(el => el.Id > 200));
var expectedDeletedCount = baseQuery.Count();
var deletedCount = baseQuery.Delete();
Assert.That(deletedCount, Is.EqualTo(expectedDeletedCount));
}
}
[Test]
public void UpdateOperationWithLimitation01()
{
SupportsUpdateLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>().Take(200);
var expectedUpdatedCount = baseQuery.Count();
var updatedCount = baseQuery.Set(el => el.Description, "UpdatedAgain").Update();
Assert.That(updatedCount, Is.EqualTo(expectedUpdatedCount));
var updatedList = session.Query.All<Bar>().Where(el => el.Description == "UpdatedAgain").ToList();
Assert.That(updatedList.Count, Is.EqualTo(expectedUpdatedCount));
}
}
[Test]
public void UpdateOperationWithLimitation02()
{
SupportsUpdateLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>().Where(el => el.Id < 100).Take(50)
.Union(session.Query.All<Bar>().Where(el => el.Id > 100).Take(50));
var expectedUpdatedCount = baseQuery.Count();
var updatedCount = baseQuery.Set(el => el.Description, "UpdatedAgain").Update();
Assert.That(updatedCount, Is.EqualTo(expectedUpdatedCount));
var updatedList = session.Query.All<Bar>().Where(el => el.Description == "UpdatedAgain").ToList();
Assert.That(updatedCount, Is.EqualTo(expectedUpdatedCount));
}
}
[Test]
public void UpdateOperationWithLimitation03()
{
SupportsUpdateLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>().Where(el => el.Id < 100)
.Union(session.Query.All<Bar>().Where(el => el.Id > 100)).Take(100);
var expectedUpdatedCount = baseQuery.Count();
var updated = baseQuery.Set(el => el.Description, "UpdatedAgain").Update();
Assert.That(updated, Is.EqualTo(expectedUpdatedCount));
var updatedList = session.Query.All<Bar>().Where(el => el.Description == "UpdatedAgain").ToList();
Assert.That(updatedList.Count, Is.EqualTo(100));
}
}
[Test]
public void UpdateOperationWithLimitation04()
{
DoesNotSupportsUpdateLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()){
_ = Assert.Throws<NotSupportedException>(
() =>session.Query.All<Bar>().Take(200).Set(el => el.Description, "UpdatedAgain").Update());
}
}
[Test]
public void UpdateOperationWithLimitation05()
{
DoesNotSupportsUpdateLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
_ = Assert.Throws<NotSupportedException>(
() => session.Query.All<Bar>().Where(el => el.Id < 100)
.Union(session.Query.All<Bar>().Where(el => el.Id > 100))
.Take(100)
.Set(el => el.Description, "UpdatedAgain")
.Update()
);
}
}
[Test]
public void DeleteOperationWithLimitation01()
{
SupportsDeleteLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var updated = session.Query.All<Bar>().Take(100).Delete();
Assert.AreEqual(100, updated);
var updatedList = session.Query.All<Bar>().ToList();
Assert.AreEqual(150, updatedList.Count);
}
}
[Test]
public void DeleteOperationWithLimitation02()
{
SupportsDeleteLimitation();
Require.ProviderIsNot(StorageProvider.Firebird, "FireBird ignores Take X in delete statement");
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>()
.Where(el => el.Id < 100)
.Take(50)
.Union(session.Query.All<Bar>().Where(el => el.Id > 100).Take(50));
var expectedDeletedCount = baseQuery.Count();
var updatedCount = baseQuery.Delete();
Assert.That(updatedCount, Is.EqualTo(expectedDeletedCount));
}
}
[Test]
public void DeleteOperationWithLimitation03()
{
SupportsDeleteLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var baseQuery = session.Query.All<Bar>()
.Where(el => el.Id < 100)
.Union(session.Query.All<Bar>().Where(el => el.Id > 100))
.Take(100);
var expectedDeletedCount = baseQuery.Count();
var updated = baseQuery.Delete();
Assert.That(updated, Is.EqualTo(expectedDeletedCount));
}
}
[Test]
public void DeleteOperationWithLimitation04()
{
DoesNotSupportsDeleteLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
_ = Assert.Throws<NotSupportedException>(()=>session.Query.All<Bar>().Take(100).Delete());
}
}
[Test]
public void DeleteOperationWithLimitation05()
{
DoesNotSupportsDeleteLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
_ = Assert.Throws<NotSupportedException>(
() => session.Query.All<Bar>()
.Where(el => el.Id < 100)
.Union(session.Query.All<Bar>().Where(el => el.Id > 100))
.Take(100)
.Delete()
);
}
}
[Test]
public void UpdateOperationTableAsSource()
{
SupportsUpdateLimitation();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
var list = session.Query.All<Bar>().Take(200).ToList();
Assert.AreEqual(200, list.Count);
var updated = session.Query.All<Bar>().Take(200).Set(el => el.Description, "Updated").Update();
Assert.AreEqual(200, updated);
var updatedList = session.Query.All<Bar>().Where(el => el.Description == "Updated").ToList();
Assert.AreEqual(200, updatedList.Count);
updated = session.Query.All<Bar>().Set(el => el.Description, "UpdatedAgain").Update();
Assert.AreEqual(250, updated);
updatedList = session.Query.All<Bar>().Where(el => el.Description == "UpdatedAgain").ToList();
Assert.AreEqual(250, updatedList.Count);
}
}
protected override void PopulateData()
{
base.PopulateData();
using (var session = Domain.OpenSession())
using (session.Activate())
using (var transaction = session.OpenTransaction()) {
for (var i = 0; i< 250; i++) {
_ = new Bar(session);
}
transaction.Complete();
}
}
protected override Configuration.DomainConfiguration BuildConfiguration()
{
var configuration = base.BuildConfiguration();
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
return configuration;
}
private void SupportsUpdateLimitation()
{
if (!Domain.StorageProviderInfo.Supports(ProviderFeatures.UpdateLimit)
&& !Domain.StorageProviderInfo.Supports(ProviderFeatures.UpdateFrom)) {
IgnoreMe("This provider does not support limitation of affecred rows on update.", null);
}
}
private void DoesNotSupportsUpdateLimitation()
{
if (Domain.StorageProviderInfo.Supports(ProviderFeatures.UpdateLimit)
|| Domain.StorageProviderInfo.Supports(ProviderFeatures.UpdateFrom)) {
IgnoreMe("This provider supports update limitation", null);
}
}
private void SupportsDeleteLimitation()
{
if (!Domain.StorageProviderInfo.Supports(ProviderFeatures.DeleteLimit)
&& !Domain.StorageProviderInfo.Supports(ProviderFeatures.DeleteFrom)) {
IgnoreMe("This provider does not support limitation of affecred rows on delet.", null);
}
}
private void DoesNotSupportsDeleteLimitation()
{
if (Domain.StorageProviderInfo.Supports(ProviderFeatures.DeleteLimit)
|| Domain.StorageProviderInfo.Supports(ProviderFeatures.DeleteFrom)) {
IgnoreMe("This provider support delete limitation", null);
}
}
private static void IgnoreMe(string format, object argument, string reason = null)
{
var message = string.Format(format, argument);
if (!string.IsNullOrEmpty(reason)) {
message = $"{message}. Reason: {reason}";
}
throw new IgnoreException(message);
}
}
}