Skip to content

Commit 6ceacff

Browse files
committed
Minor changes of test classes
Test renames, some test structure improvements
1 parent 2ff86bd commit 6ceacff

2 files changed

Lines changed: 55 additions & 63 deletions

File tree

Extensions/Xtensive.Orm.BulkOperations.Tests/Other.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using NUnit.Framework;
@@ -244,7 +244,7 @@ public void In()
244244
}
245245

246246
[Test]
247-
public void InWithCombinationWithFieldUsageinUpdate()
247+
public void InWithCombinationWithFieldUsageUpdate()
248248
{
249249
using (Session session = Domain.OpenSession())
250250
using (TransactionScope trx = session.OpenTransaction()) {

Orm/Xtensive.Orm.Tests/Issues/IssueJira0793_FieldValidationTriggersLazyLoadFieldsFetch.cs

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,39 @@ public class Chapter : Entity
7070
[NotNullOrEmptyConstraint(ValidateOnlyIfModified = true)]// should validate only if changed
7171
public string Description { get; set; }
7272
}
73-
}
7473

75-
namespace Xtensive.Orm.Tests.Issues
76-
{
77-
public class IssueJira0793_FieldValidationTriggersLazyLoadFieldsFetch : AutoBuildTest
74+
public class QueryCounter
7875
{
79-
private class QueryCounter
80-
{
81-
public int Count { get; private set; }
76+
public int Count { get; private set; }
8277

83-
public Disposable Attach(Session session)
84-
{
85-
session.Events.DbCommandExecuted += Encount;
86-
return new Disposable((disposing) => session.Events.DbCommandExecuted -= Encount);
87-
}
78+
public Disposable Attach(Session session)
79+
{
80+
session.Events.DbCommandExecuted += Encount;
81+
return new Disposable((disposing) => session.Events.DbCommandExecuted -= Encount);
82+
}
8883

89-
public void Reset()
90-
{
91-
Count = 0;
92-
}
84+
public void Reset() => Count = 0;
9385

94-
private void Encount(object sender, DbCommandEventArgs eventArgs)
95-
{
96-
Count++;
97-
}
86+
private void Encount(object sender, DbCommandEventArgs eventArgs) => Count++;
9887

99-
public QueryCounter()
100-
{
101-
Count = 0;
102-
}
88+
public QueryCounter()
89+
{
90+
Count = 0;
10391
}
92+
}
93+
}
10494

95+
namespace Xtensive.Orm.Tests.Issues
96+
{
97+
public class IssueJira0793_FieldValidationTriggersLazyLoadFieldsFetch : AutoBuildTest
98+
{
10599
private Key oblomovKey;
106100
private Key goncharovKey;
107101

108102
protected override DomainConfiguration BuildConfiguration()
109103
{
110104
var configuration = base.BuildConfiguration();
111-
configuration.Types.Register(typeof (Book).Assembly, typeof (Book).Namespace);
105+
configuration.Types.Register(typeof(Book).Assembly, typeof(Book).Namespace);
112106
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
113107
return configuration;
114108
}
@@ -117,10 +111,13 @@ protected override void PopulateData()
117111
{
118112
using (var session = Domain.OpenSession())
119113
using (var transaction = session.OpenTransaction()) {
120-
var author = new Author() { FirstName = "Ivan", LastName = "Goncharov", Biography = "Some biography of Ivan Alexandrovich" };
114+
var author = new Author() {
115+
FirstName = "Ivan",
116+
LastName = "Goncharov",
117+
Biography = "Some biography of Ivan Alexandrovich" };
121118
var book = new Book() {
122119
Title = "Oblomov",
123-
Description = "A drama story of how human lazyness and absence of strenght within may cause his life.",
120+
Description = "A drama about how human's lazyness and absence of strenght may affect his life.",
124121
BookFile = new byte[] { 3, 3, 3, 3, 3, 3, 3 },
125122
Author = author
126123
};
@@ -139,14 +136,13 @@ protected override void PopulateData()
139136
[Test]
140137
public void LazyFieldHasNoConstraintTest()
141138
{
139+
var counter = new QueryCounter();
142140
using (var session = Domain.OpenSession()) {
143-
var counter = new QueryCounter();
144-
using (counter.Attach(session)) {
145-
using (var transaction = session.OpenTransaction()) {
146-
var oblomov = session.Query.Single<Book>(oblomovKey);
147-
oblomov.Title = "Oblomov by Goncharov";
148-
transaction.Complete();
149-
}
141+
using (counter.Attach(session))
142+
using (var transaction = session.OpenTransaction()) {
143+
var oblomov = session.Query.Single<Book>(oblomovKey);
144+
oblomov.Title = "Oblomov by Goncharov";
145+
transaction.Complete();
150146
}
151147
Assert.That(counter.Count, Is.EqualTo(2));
152148
counter.Reset();
@@ -156,14 +152,13 @@ public void LazyFieldHasNoConstraintTest()
156152
[Test]
157153
public void LazyFieldHasCheckAlwaysConstraintTest()
158154
{
155+
var counter = new QueryCounter();
159156
using (var session = Domain.OpenSession()) {
160-
var counter = new QueryCounter();
161-
using (counter.Attach(session)) {
162-
using (var transaction = session.OpenTransaction()) {
163-
var goncharov = session.Query.Single<Author>(goncharovKey);
164-
goncharov.FirstName = goncharov.FirstName + "modified"; // should prefetch lazy load field
165-
transaction.Complete();
166-
}
157+
using (counter.Attach(session))
158+
using (var transaction = session.OpenTransaction()) {
159+
var goncharov = session.Query.Single<Author>(goncharovKey);
160+
goncharov.FirstName = goncharov.FirstName + "modified"; // should prefetch lazy load field
161+
transaction.Complete();
167162
}
168163
Assert.That(counter.Count, Is.EqualTo(3));
169164
counter.Reset();
@@ -173,34 +168,31 @@ public void LazyFieldHasCheckAlwaysConstraintTest()
173168
[Test]
174169
public void LazyFieldHasCheckIfModifiedConstraintTest()
175170
{
171+
var counter = new QueryCounter();
176172
using (var session = Domain.OpenSession()) {
177-
var counter = new QueryCounter();
178-
using (counter.Attach(session)) {
179-
using (var transaction = session.OpenTransaction()) {
180-
foreach (var chapter in session.Query.All<Chapter>()) {
181-
chapter.Title = chapter.Title + " modified";
182-
}
183-
transaction.Complete();
173+
using (counter.Attach(session))
174+
using (var transaction = session.OpenTransaction()) {
175+
foreach (var chapter in session.Query.All<Chapter>()) {
176+
chapter.Title = chapter.Title + " modified";
184177
}
185-
Assert.That(counter.Count, Is.EqualTo(2));
186-
counter.Reset();
178+
transaction.Complete();
187179
}
180+
Assert.That(counter.Count, Is.EqualTo(2));
181+
counter.Reset();
188182
}
189183

190184
using (var session = Domain.OpenSession()) {
191-
var counter = new QueryCounter();
192-
using (counter.Attach(session)) {
193-
int updatedItems = 0;
194-
using (var transaction = session.OpenTransaction()) {
195-
foreach(var chapter in session.Query.All<Chapter>()) {
196-
chapter.Description = chapter.Description + " modified";
197-
updatedItems++;
198-
}
199-
transaction.Complete();
185+
int updatedItems = 0;
186+
using (counter.Attach(session))
187+
using (var transaction = session.OpenTransaction()) {
188+
foreach(var chapter in session.Query.All<Chapter>()) {
189+
chapter.Description = chapter.Description + " modified";
190+
updatedItems++;
200191
}
201-
Assert.That(counter.Count, Is.EqualTo(5)); // query + fetches + update
202-
counter.Reset();
192+
transaction.Complete();
203193
}
194+
Assert.That(counter.Count, Is.EqualTo(5)); // query + fetches + update
195+
counter.Reset();
204196
}
205197
}
206198
}

0 commit comments

Comments
 (0)