Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/NHibernate.Test/Async/Linq/ProjectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
using System.Collections.Generic;
using System.Linq;
using NHibernate.DomainModel.Northwind.Entities;
using NUnit.Framework;
using NHibernate.Linq;
using NUnit.Framework;

namespace NHibernate.Test.Linq
{
Expand Down Expand Up @@ -237,6 +237,7 @@ public async Task CanProjectCollectionsInsideAnonymousTypeAsync()
{
var query = db.Orders.Select(o => new { o.OrderId, o.OrderLines });
var result = await (query.ToListAsync());
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result.Count, Is.EqualTo(830));
}

Expand All @@ -250,6 +251,7 @@ public async Task ProjectAnonymousTypeWithCollectionAsync()

var result = await (query.ToListAsync());
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines));
}

Expand All @@ -263,6 +265,7 @@ public async Task ProjectAnonymousTypeWithCollection1Async()

var result = await (query.ToListAsync());
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines));
}

Expand All @@ -275,6 +278,7 @@ public async Task ProjectAnonymousTypeWithCollection2Async()
select new { o.OrderLines, A = 1, B = 2 };

var result = await (query.ToListAsync());
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result.Count, Is.EqualTo(830));
}

Expand All @@ -287,6 +291,7 @@ public async Task ProjectAnonymousTypeWithCollection3Async()
select new { OrderLines = o.OrderLines.ToList() };

var result = await (query.ToListAsync());
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result.Count, Is.EqualTo(830));
}

Expand All @@ -304,9 +309,32 @@ public async Task ProjectKnownTypeWithCollectionAsync()

var result = await (query.ToListAsync());
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].ExpandedElement.OrderLines), Is.False);
Assert.That(NHibernateUtil.IsInitialized(result[0].ProjectedProperty0), Is.True);
Assert.That(result[0].ExpandedElement.OrderLines, Is.EquivalentTo(result[0].ProjectedProperty0));
}


[Test]
public async Task ProjectKnownTypeWithCollectionWithFetchAsync()
{
// NH-3396
// However, due to a double join on Orderlines, this query has 7000+ results
var query = from o in db.Orders.Fetch(x => x.OrderLines)
select new ExpandedWrapper<Order, ISet<OrderLine>>
{
ExpandedElement = o,
ProjectedProperty0 = o.OrderLines,
Description = "OrderLine",
ReferenceDescription = "OrderLine"
};

var result = await (query.ToListAsync());
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].ExpandedElement.OrderLines), Is.True);
Assert.That(NHibernateUtil.IsInitialized(result[0].ProjectedProperty0), Is.True);
Assert.That(result[0].ExpandedElement.OrderLines, Is.EquivalentTo(result[0].ProjectedProperty0));
}

[Test]
public async Task ProjectKnownTypeWithCollection2Async()
{
Expand Down
31 changes: 30 additions & 1 deletion src/NHibernate.Test/Linq/ProjectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using NHibernate.DomainModel.Northwind.Entities;
using NHibernate.Linq;
using NUnit.Framework;

namespace NHibernate.Test.Linq
Expand Down Expand Up @@ -225,6 +226,7 @@ public void CanProjectCollectionsInsideAnonymousType()
{
var query = db.Orders.Select(o => new { o.OrderId, o.OrderLines });
var result = query.ToList();
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result.Count, Is.EqualTo(830));
}

Expand All @@ -238,6 +240,7 @@ public void ProjectAnonymousTypeWithCollection()

var result = query.ToList();
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines));
}

Expand All @@ -251,6 +254,7 @@ public void ProjectAnonymousTypeWithCollection1()

var result = query.ToList();
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result[0].o.OrderLines, Is.EquivalentTo(result[0].OrderLines));
}

Expand All @@ -263,6 +267,7 @@ public void ProjectAnonymousTypeWithCollection2()
select new { o.OrderLines, A = 1, B = 2 };

var result = query.ToList();
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result.Count, Is.EqualTo(830));
}

Expand All @@ -275,6 +280,7 @@ public void ProjectAnonymousTypeWithCollection3()
select new { OrderLines = o.OrderLines.ToList() };

var result = query.ToList();
Assert.That(NHibernateUtil.IsInitialized(result[0].OrderLines), Is.True);
Assert.That(result.Count, Is.EqualTo(830));
}

Expand All @@ -292,9 +298,32 @@ public void ProjectKnownTypeWithCollection()

var result = query.ToList();
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].ExpandedElement.OrderLines), Is.False);
Assert.That(NHibernateUtil.IsInitialized(result[0].ProjectedProperty0), Is.True);
Assert.That(result[0].ExpandedElement.OrderLines, Is.EquivalentTo(result[0].ProjectedProperty0));
}


[Test]
public void ProjectKnownTypeWithCollectionWithFetch()
{
// NH-3396
// However, due to a double join on Orderlines, this query has 7000+ results
var query = from o in db.Orders.Fetch(x => x.OrderLines)
select new ExpandedWrapper<Order, ISet<OrderLine>>
{
ExpandedElement = o,
ProjectedProperty0 = o.OrderLines,
Description = "OrderLine",
ReferenceDescription = "OrderLine"
};

var result = query.ToList();
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].ExpandedElement.OrderLines), Is.True);
Assert.That(NHibernateUtil.IsInitialized(result[0].ProjectedProperty0), Is.True);
Assert.That(result[0].ExpandedElement.OrderLines, Is.EquivalentTo(result[0].ProjectedProperty0));
}

[Test]
public void ProjectKnownTypeWithCollection2()
{
Expand Down