Skip to content

Commit 36e983c

Browse files
authored
Merge pull request #96 from DataObjects-NET/open-reader-bugfix-2
Close underlying Data Reader on reaching the end of a sequence
2 parents 1215bf1 + f4fa0c7 commit 36e983c

File tree

4 files changed

+251
-70
lines changed

4 files changed

+251
-70
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright (C) 2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using NUnit.Framework;
9+
using Xtensive.Orm.Configuration;
10+
using Xtensive.Orm.Tests.Issues.IssueGitHub071_DataReaderRemainsOpenModel;
11+
12+
namespace Xtensive.Orm.Tests.Issues.IssueGitHub071_DataReaderRemainsOpenModel
13+
{
14+
[HierarchyRoot]
15+
[KeyGenerator(KeyGeneratorKind.None)]
16+
public class Item : Entity
17+
{
18+
[Field, Key]
19+
public Guid Id { get; private set; }
20+
21+
public Item(Session session, Guid id)
22+
: base(session, id)
23+
{ }
24+
}
25+
}
26+
27+
namespace Xtensive.Orm.Tests.Issues
28+
{
29+
[TestFixture]
30+
public sealed class IssueGitHub071_DataReaderRemainsOpen : AutoBuildTest
31+
{
32+
protected override DomainConfiguration BuildConfiguration()
33+
{
34+
var config = base.BuildConfiguration();
35+
config.Types.Register(typeof(Item));
36+
return config;
37+
}
38+
39+
[Test]
40+
public void ConcatOfEmptySequencesTest1()
41+
{
42+
using (var session = Domain.OpenSession())
43+
using (var tx = session.OpenTransaction()) {
44+
var list = new List<Guid>();
45+
var sequence = Enumerable.Empty<Guid>().Concat(session.Query.All<Item>()
46+
.Where(item => item.Id == Guid.Empty)
47+
.Select(item => item.Id));
48+
foreach (var guid in sequence) {
49+
list.Add(guid);
50+
}
51+
52+
Assert.AreEqual(0, list.Count);
53+
tx.Complete();
54+
}
55+
}
56+
57+
[Test]
58+
public void ConcatOfEmptySequencesTest2()
59+
{
60+
using (var session = Domain.OpenSession())
61+
using (var tx = session.OpenTransaction()) {
62+
var list = new List<Guid>();
63+
var sequence = session.Query.All<Item>()
64+
.Where(item => item.Id == Guid.Empty)
65+
.Select(item => item.Id).AsEnumerable().Concat(Enumerable.Empty<Guid>());
66+
foreach (var guid in sequence) {
67+
list.Add(guid);
68+
}
69+
70+
Assert.AreEqual(0, list.Count);
71+
tx.Complete();
72+
}
73+
}
74+
75+
[Test]
76+
public void UnionOfEmptySequencesTest1()
77+
{
78+
using (var session = Domain.OpenSession())
79+
using (var tx = session.OpenTransaction()) {
80+
var list = new List<Guid>();
81+
var sequence = Enumerable.Empty<Guid>().Union(session.Query.All<Item>()
82+
.Where(item => item.Id == Guid.Empty)
83+
.Select(item => item.Id));
84+
foreach (var guid in sequence) {
85+
list.Add(guid);
86+
}
87+
88+
Assert.AreEqual(0, list.Count);
89+
tx.Complete();
90+
}
91+
}
92+
93+
[Test]
94+
public void UnionOfEmptySequencesTest2()
95+
{
96+
using (var session = Domain.OpenSession())
97+
using (var tx = session.OpenTransaction()) {
98+
var list = new List<Guid>();
99+
var sequence = session.Query.All<Item>()
100+
.Where(item => item.Id == Guid.Empty)
101+
.Select(item => item.Id).AsEnumerable().Union(Enumerable.Empty<Guid>());
102+
foreach (var guid in sequence) {
103+
list.Add(guid);
104+
}
105+
106+
Assert.AreEqual(0, list.Count);
107+
tx.Complete();
108+
}
109+
}
110+
111+
[Test]
112+
public void JustEmptyQueryResult()
113+
{
114+
using (var session = Domain.OpenSession())
115+
using (var tx = session.OpenTransaction()) {
116+
var list = new List<Guid>();
117+
var sequence = session.Query.All<Item>()
118+
.Where(item => item.Id == Guid.Empty)
119+
.Select(item => item.Id);
120+
foreach (var guid in sequence) {
121+
list.Add(guid);
122+
}
123+
124+
Assert.AreEqual(0, list.Count);
125+
tx.Complete();
126+
}
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)