Skip to content

Commit 6bb3004

Browse files
committed
Add more tests
1 parent a775f9c commit 6bb3004

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

Orm/Xtensive.Orm.Tests/Issues/IssueGithub0114_QueryRootReuseCauseNoRefJoin.cs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,140 @@ protected override void PopulateData()
163163
tx.Complete();
164164
}
165165

166+
[Test]
167+
public void MembersAsAliasForSubqhery1()
168+
{
169+
using (var session = Domain.OpenSession())
170+
using (var tx = session.OpenTransaction()) {
171+
var query = session.Query.All<Promotion>()
172+
.Select(promo => new {
173+
promo,
174+
notifications = session.Query.All<Notification>()
175+
})
176+
.Select(anon => new {
177+
anon,
178+
anon.promo,
179+
notificationsAlias1 = anon.notifications,
180+
notificationsAlias2 = anon.notifications,
181+
})
182+
.Select(anon => new {
183+
contacted = anon.notificationsAlias1.Select(c => c.Recipient.User.Id)
184+
.Union(anon.notificationsAlias2.Select(c => c.Recipient.User.Id)),
185+
promo = anon.promo
186+
}).ToArray();
187+
188+
var expected = session.Query.All<Promotion>()
189+
.Select(promo => new { promo })
190+
.Select(anon => new {
191+
contacted = session.Query.All<Notification>().Select(c => c.Recipient.User.Id)
192+
.Union(session.Query.All<Notification>().Select(c => c.Recipient.User.Id)),
193+
promo = anon.promo
194+
}).ToArray();
195+
196+
Assert.That(query.Length, Is.EqualTo(expected.Length));
197+
198+
for (var i = 0; i < expected.Length; i++) {
199+
var a1 = expected[0];
200+
var a2 = query[0];
201+
var a1contacted = a1.contacted.ToArray();
202+
var a2contacted = a2.contacted.ToArray();
203+
204+
Assert.That(a1.promo.Id, Is.EqualTo(a2.promo.Id));
205+
Assert.That(a1contacted.SequenceEqual(a2contacted));
206+
Assert.That(a1contacted.Length, Is.Not.Zero);
207+
}
208+
}
209+
}
210+
211+
[Test]
212+
public void MembersAsAliasForSubqhery2()
213+
{
214+
using (var session = Domain.OpenSession())
215+
using (var tx = session.OpenTransaction()) {
216+
var query = session.Query.All<Promotion>()
217+
.Select(promo => new {
218+
promo,
219+
notifications = session.Query.All<Notification>()
220+
})
221+
.Select(anon => new {
222+
anon,
223+
anon.promo,
224+
notificationsAlias1 = anon.notifications,
225+
notificationsAlias2 = anon.notifications,
226+
})
227+
.Select(anon => new {
228+
contacted = anon.anon.notifications.Select(c => c.Recipient.User.Id)
229+
.Union(anon.notificationsAlias1.Select(c => c.Recipient.User.Id)),
230+
promo = anon.promo
231+
}).ToArray();
232+
233+
var expected = session.Query.All<Promotion>()
234+
.Select(promo => new { promo })
235+
.Select(anon => new {
236+
contacted = session.Query.All<Notification>().Select(c => c.Recipient.User.Id)
237+
.Union(session.Query.All<Notification>().Select(c => c.Recipient.User.Id)),
238+
promo = anon.promo
239+
}).ToArray();
240+
241+
Assert.That(query.Length, Is.EqualTo(expected.Length));
242+
243+
for (var i = 0; i < expected.Length; i++) {
244+
var a1 = expected[0];
245+
var a2 = query[0];
246+
var a1contacted = a1.contacted.ToArray();
247+
var a2contacted = a2.contacted.ToArray();
248+
249+
Assert.That(a1.promo.Id, Is.EqualTo(a2.promo.Id));
250+
Assert.That(a1contacted.SequenceEqual(a2contacted));
251+
Assert.That(a1contacted.Length, Is.Not.Zero);
252+
}
253+
}
254+
}
255+
256+
[Test]
257+
public void MembersAsAliasForSubqhery3()
258+
{
259+
using (var session = Domain.OpenSession())
260+
using (var tx = session.OpenTransaction()) {
261+
var query = session.Query.All<Promotion>()
262+
.Select(promo => new {
263+
promo,
264+
notifications = session.Query.All<Notification>()
265+
})
266+
.Select(anon => new {
267+
anon,
268+
anon.promo,
269+
notificationsAlias1 = anon.notifications,
270+
notificationsAlias2 = anon.notifications,
271+
})
272+
.Select(anon => new {
273+
contacted = anon.notificationsAlias1.Select(c => c.Recipient.User.Id)
274+
.Union(anon.anon.notifications.Select(c => c.Recipient.User.Id)),
275+
promo = anon.promo
276+
}).ToArray();
277+
278+
var expected = session.Query.All<Promotion>()
279+
.Select(promo => new { promo })
280+
.Select(anon => new {
281+
contacted = session.Query.All<Notification>().Select(c => c.Recipient.User.Id)
282+
.Union(session.Query.All<Notification>().Select(c => c.Recipient.User.Id)),
283+
promo = anon.promo
284+
}).ToArray();
285+
286+
Assert.That(query.Length, Is.EqualTo(expected.Length));
287+
288+
for (var i = 0; i < expected.Length; i++) {
289+
var a1 = expected[0];
290+
var a2 = query[0];
291+
var a1contacted = a1.contacted.ToArray();
292+
var a2contacted = a2.contacted.ToArray();
293+
294+
Assert.That(a1.promo.Id, Is.EqualTo(a2.promo.Id));
295+
Assert.That(a1contacted.SequenceEqual(a2contacted));
296+
Assert.That(a1contacted.Length, Is.Not.Zero);
297+
}
298+
}
299+
}
166300

167301
[Test]
168302
public void BaseQueryReuseWithExcept()

0 commit comments

Comments
 (0)