Skip to content

Commit c87a031

Browse files
authored
Merge pull request #127 from DataObjects-NET/6.0-reprocessing-same-session-bug
Reprocessing extension without session activations inside
2 parents d440d3e + 377a28c commit c87a031

File tree

9 files changed

+329
-189
lines changed

9 files changed

+329
-189
lines changed

ChangeLog/6.0.6_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[main] Fixed possible cases of broken serialization due to comparers

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

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System.Linq;
1+
using System.Linq;
22
using System.Transactions;
33
using NUnit.Framework;
44
using TestCommon.Model;
55
using Xtensive.Orm.Configuration;
6-
using Xtensive.Orm.Reprocessing.Configuration;
76

87
namespace Xtensive.Orm.Reprocessing.Tests
98
{
@@ -13,27 +12,25 @@ private class TestExecuteStrategy : HandleUniqueConstraintViolationStrategy
1312
{
1413
#region Non-public methods
1514

16-
protected override bool OnError(ExecuteErrorEventArgs context)
17-
{
18-
return context.Attempt < 2;
19-
}
15+
protected override bool OnError(ExecuteErrorEventArgs context) => context.Attempt < 2;
2016

2117
#endregion
2218
}
2319

2420
[Test]
2521
public void ExecuteStrategy()
2622
{
27-
int i = 0;
23+
var i = 0;
2824
try {
29-
ReprocessingConfiguration config = Domain.GetReprocessingConfiguration();
25+
var config = Domain.GetReprocessingConfiguration();
3026
config.DefaultExecuteStrategy = typeof (TestExecuteStrategy);
3127
Domain.Execute(
3228
session => {
33-
new Foo(session) {Name = "test"};
29+
_ = new Foo(session) {Name = "test"};
3430
i++;
35-
if (i < 5)
36-
new Foo(session) {Name = "test"};
31+
if (i < 5) {
32+
_ = new Foo(session) {Name = "test"};
33+
}
3734
});
3835
}
3936
catch {
@@ -55,41 +52,40 @@ public void NestedNewSession()
5552
[Test]
5653
public void NestedSessionReuse()
5754
{
58-
Domain.Execute(session1 => Domain.Execute(session2 => Assert.That(session1, Is.SameAs(session2))));
55+
Domain.Execute(session1 =>
56+
Domain.WithSession(session1)
57+
.Execute(session2 => Assert.That(session1, Is.SameAs(session2))));
5958
}
6059

6160
[Test]
6261
public void Test()
6362
{
6463
Domain.Execute(session => {
65-
new Foo(session);
64+
_ = new Foo(session);
6665
});
6766
Domain.Execute(session => {
68-
session.Query.All<Foo>().ToArray();
67+
_ = session.Query.All<Foo>().ToArray();
6968
Domain.WithIsolationLevel(IsolationLevel.Serializable).Execute(session2 => {
70-
session2.Query.All<Foo>().ToArray();
69+
_ = session2.Query.All<Foo>().ToArray();
7170
});
7271
});
7372
}
7473

7574
[Test]
7675
public void ParentIsDisconnectedState()
7776
{
78-
Domain.Execute(session =>
79-
{
80-
new Bar(session);
81-
});
77+
Domain.Execute(session => {
78+
_ = new Bar(session);
79+
});
8280
using (var session = Domain.OpenSession(new SessionConfiguration(SessionOptions.ClientProfile)))
83-
using(session.Activate())
84-
{
81+
using(session.Activate()) {
8582
var bar = session.Query.All<Bar>().FirstOrDefault();
86-
bar=new Bar(session);
83+
bar = new Bar(session);
8784
session.SaveChanges();
88-
Domain.Execute(session1 =>
89-
{
90-
bar = session1.Query.All<Bar>().FirstOrDefault();
91-
bar=new Bar(session1);
92-
});
85+
Domain.WithSession(session).Execute(session1 => {
86+
bar = session1.Query.All<Bar>().FirstOrDefault();
87+
bar = new Bar(session1);
88+
});
9389
session.SaveChanges();
9490
}
9591
Domain.Execute(session => Assert.That(session.Query.All<Bar>().Count(), Is.EqualTo(3)));

0 commit comments

Comments
 (0)