Skip to content

Commit 68c3fde

Browse files
committed
Create test for issue
1 parent af8a46e commit 68c3fde

1 file changed

Lines changed: 221 additions & 0 deletions

File tree

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
// Copyright (C) 2023 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.Model;
11+
using Xtensive.Orm.Tests.Issues.IssueGithub0114_QueryRootReuseCauseNoRefJoinModel;
12+
13+
namespace Xtensive.Orm.Tests.Issues.IssueGithub0114_QueryRootReuseCauseNoRefJoinModel
14+
{
15+
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
16+
public class Promotion : Entity
17+
{
18+
[Field, Key]
19+
public long Id { get; private set; }
20+
21+
[Field]
22+
public string CampainName { get; set; }
23+
24+
[Field]
25+
[Association(PairTo = nameof(Notification.Promotion))]
26+
public EntitySet<Notification> Notifications { get; private set; }
27+
}
28+
29+
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
30+
public class Notification : Entity
31+
{
32+
[Field, Key]
33+
public long Id { get; private set; }
34+
35+
[Field(Nullable = false)]
36+
public Promotion Promotion { get; private set; }
37+
38+
[Field(Nullable = false)]
39+
public Recipient Recipient { get; private set; }
40+
}
41+
42+
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
43+
public class Recipient : Entity
44+
{
45+
[Field, Key]
46+
public long Id { get; private set; }
47+
48+
[Field]
49+
public User User { get; set; }
50+
51+
[Field]
52+
[Association(PairTo = nameof(Notification.Recipient), OnOwnerRemove = OnRemoveAction.Cascade)]
53+
public EntitySet<Notification> Notifications { get; private set; }
54+
}
55+
56+
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
57+
public class User : Entity
58+
{
59+
[Field, Key]
60+
public long Id { get; private set; }
61+
62+
[Field(Length = 50, Nullable = false)]
63+
public string Name { get; set; }
64+
}
65+
}
66+
67+
namespace Xtensive.Orm.Tests.Issues
68+
{
69+
[TestFixture]
70+
public sealed class IssueGithub0114_QueryRootReuseCauseNoRefJoin : AutoBuildTest
71+
{
72+
protected override DomainConfiguration BuildConfiguration()
73+
{
74+
var configuration = base.BuildConfiguration();
75+
configuration.Types.Register(typeof(Promotion));
76+
configuration.Types.Register(typeof(Notification));
77+
configuration.Types.Register(typeof(Recipient));
78+
configuration.Types.Register(typeof(User));
79+
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
80+
return configuration;
81+
}
82+
83+
[Test]
84+
public void PureRootQueryReuse1()
85+
{
86+
using (var session = Domain.OpenSession())
87+
using (var tx = session.OpenTransaction()) {
88+
var query = session.Query.All<Promotion>()
89+
.Select(promo => new {
90+
promo,
91+
notifications = session.Query.All<Notification>()
92+
})
93+
.Select(anon1 => new {
94+
contacted = anon1.notifications.Select(c => c.Recipient.User.Id)
95+
.Except(anon1.notifications.Select(c => c.Recipient.User.Id))
96+
}).ToArray();
97+
}
98+
}
99+
100+
[Test]
101+
public void PureRootQueryReuseWithAllAnonTypeProps()
102+
{
103+
using (var session = Domain.OpenSession())
104+
using (var tx = session.OpenTransaction()) {
105+
var query = session.Query.All<Promotion>()
106+
.Select(promo => new {
107+
promo,
108+
notifications = session.Query.All<Notification>()
109+
})
110+
.Select(anon1 => new {
111+
promo1 = anon1.promo,
112+
contacted = anon1.notifications.Select(c => c.Recipient.User.Id)
113+
.Except(anon1.notifications.Select(c => c.Recipient.User.Id))
114+
}).ToArray();
115+
}
116+
}
117+
118+
[Test]
119+
public void SubqueryReuse1()
120+
{
121+
using (var session = Domain.OpenSession())
122+
using (var tx = session.OpenTransaction()) {
123+
var query = session.Query.All<Promotion>()
124+
.Select(promo => new {
125+
promo,
126+
notifications = session.Query.All<Notification>().Where(n => n.Id < promo.Id)
127+
})
128+
.Select(anon1 => new {
129+
contacted = anon1.notifications.Select(c => c.Recipient.User.Id)
130+
.Except(anon1.notifications.Select(c => c.Recipient.User.Id))
131+
}).ToArray();
132+
}
133+
}
134+
135+
[Test]
136+
public void OnePropOneTrueQueryRoot()
137+
{
138+
using (var session = Domain.OpenSession())
139+
using (var tx = session.OpenTransaction()) {
140+
var query = session.Query.All<Promotion>()
141+
.Select(promo => new {
142+
promo,
143+
notifications = session.Query.All<Notification>()
144+
})
145+
.Select(anon1 => new {
146+
contacted = anon1.notifications.Select(c => c.Recipient.User.Id)
147+
.Except(session.Query.All<Notification>().Select(c => c.Recipient.User.Id))
148+
}).ToArray();
149+
}
150+
}
151+
152+
[Test]
153+
public void NoPropertyQueryRootReuse1()
154+
{
155+
using (var session = Domain.OpenSession())
156+
using (var tx = session.OpenTransaction()) {
157+
var query = session.Query.All<Promotion>()
158+
.Select(promo => new {
159+
promo,
160+
notifications = session.Query.All<Notification>()
161+
})
162+
.Select(anon1 => new {
163+
contacted = session.Query.All<Notification>().Select(c => c.Recipient.User.Id)
164+
.Except(session.Query.All<Notification>().Select(c => c.Recipient.User.Id))
165+
}).ToArray();
166+
}
167+
}
168+
169+
[Test]
170+
public void PropertyQueryRootOneUse1()
171+
{
172+
using (var session = Domain.OpenSession())
173+
using (var tx = session.OpenTransaction()) {
174+
var query = session.Query.All<Promotion>()
175+
.Select(promo => new {
176+
promo,
177+
notifications = session.Query.All<Notification>()
178+
})
179+
.Select(anon1 => new {
180+
contacted = anon1.notifications.Select(c => c.Recipient.User.Id)
181+
.Except(session.Query.All<Notification>().Select(c => c.Recipient.User.Id))
182+
}).ToArray();
183+
}
184+
}
185+
186+
[Test]
187+
public void PropertyQueryRootOneUse2()
188+
{
189+
using (var session = Domain.OpenSession())
190+
using (var tx = session.OpenTransaction()) {
191+
var query = session.Query.All<Promotion>()
192+
.Select(promo => new {
193+
promo,
194+
notifications = session.Query.All<Notification>()
195+
})
196+
.Select(anon1 => new {
197+
contacted = session.Query.All<Notification>().Select(c => c.Recipient.User.Id)
198+
.Except(anon1.notifications.Select(c => c.Recipient.User.Id))
199+
}).ToArray();
200+
}
201+
}
202+
203+
[Test]
204+
public void SeparatePropertyForQueryRoot()
205+
{
206+
using (var session = Domain.OpenSession())
207+
using (var tx = session.OpenTransaction()) {
208+
var query = session.Query.All<Promotion>()
209+
.Select(promo => new {
210+
promo,
211+
notifications1 = session.Query.All<Notification>(),
212+
notifications2 = session.Query.All<Notification>()
213+
})
214+
.Select(anon1 => new {
215+
contacted = anon1.notifications1.Select(c => c.Recipient.User.Id)
216+
.Except(anon1.notifications2.Select(c => c.Recipient.User.Id))
217+
}).ToArray();
218+
}
219+
}
220+
}
221+
}

0 commit comments

Comments
 (0)