Skip to content

Commit

Permalink
Add tests for NH-3018 - support for having clause in LINQ query
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Jan 19, 2012
1 parent 63367a8 commit 8a06276
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
124 changes: 124 additions & 0 deletions src/NHibernate.Test/Linq/ByMethod/GroupByHavingTests.cs
@@ -0,0 +1,124 @@
using System;
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Test.Linq.ByMethod
{
[TestFixture]
public class GroupByHavingTests : LinqTestCase
{
protected override void Configure(Cfg.Configuration configuration)
{
base.Configure(configuration);
configuration.SetProperty(Cfg.Environment.ShowSql, "true");
}

[Test]
public void HavingCountSelectCount()
{
var list = (from o in db.Orders
group o by o.OrderDate
into g
where g.Count() > 4
select g.Count()).ToList();

Assert.That(list.Count, Is.EqualTo(1));
Assert.That(list.Single(), Is.EqualTo(5));
}

[Test]
public void HavingCountSelectCountWithInnerWhere()
{
var list = (from o in db.Orders
where o.RequiredDate < DateTime.Now
group o by o.OrderDate
into g
where g.Count() > 4
select g.Count()).ToList();

Assert.That(list.Count, Is.EqualTo(1));
Assert.That(list.Single(), Is.EqualTo(5));
}

[Test]
public void HavingCountSelectKey()
{
var list = (from o in db.Orders
group o by o.OrderDate
into g
where g.Count() > 4
select g.Key).ToList();

Assert.That(list.Count, Is.EqualTo(1));
}

[Test]
public void HavingCountSelectKeyWithInnerWhere()
{
var list = (from o in db.Orders
where o.RequiredDate < DateTime.Now
group o by o.OrderDate
into g
where g.Count() > 4
select g.Key).ToList();

Assert.That(list.Count, Is.EqualTo(1));
}

[Test]
public void HavingCountSelectTupleKeyCount()
{
var list = (from o in db.Orders
group o by o.OrderDate
into g
where g.Count() > 4
select new {g.Key, Count = g.Count()}).ToList();

Assert.That(list.Count, Is.EqualTo(1));
Assert.That(list.Single().Count, Is.EqualTo(5));
}

[Test]
public void HavingCountSelectTupleKeyCountOfOrders()
{
var list = (from o in db.Orders
group o by o.OrderDate
into g
where g.Count() > 4
select new {g.Key, Count = g.Select(x => x.OrderId).Count()}).ToList();

Assert.That(list.Count, Is.EqualTo(1));
Assert.That(list.Single().Count, Is.EqualTo(5));
}

[Test]
public void HavingCountSelectTupleKeyCountOfOrderLines()
{
var list = (from o in db.Orders
group o by o.OrderDate
into g
where g.Count() > 4
select new
{
g.Key,
Count = g.SelectMany(x => x.OrderLines).Count()
}).ToList();

Assert.That(list.Count, Is.EqualTo(1));
Assert.That(list.Single().Count, Is.EqualTo(5));
}

[Test]
public void ComplexQuery()
{
var list = (from o in db.Orders
where o.RequiredDate < DateTime.Now
group o by o.OrderDate
into g
where g.Count() > 4 && g.Key < DateTime.Now
select g.Count()).ToList();

Assert.AreEqual(1, list.Count);
}
}
}
1 change: 1 addition & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Expand Up @@ -493,6 +493,7 @@
<Compile Include="Linq\BinaryExpressionOrdererTests.cs" />
<Compile Include="Linq\BooleanMethodExtensionExample.cs" />
<Compile Include="Linq\ByMethod\CastTests.cs" />
<Compile Include="Linq\ByMethod\GroupByHavingTests.cs" />
<Compile Include="Linq\ByMethod\GroupByTests.cs" />
<Compile Include="Linq\CasingTest.cs" />
<Compile Include="Linq\CollectionAssert.cs" />
Expand Down

0 comments on commit 8a06276

Please sign in to comment.