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