Skip to content

Commit 9a228c7

Browse files
committed
NH-3816 - Added tests from NH-3818
1 parent 5a1df86 commit 9a228c7

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Linq;
3+
using System.Linq.Dynamic;
4+
using NHibernate.Linq;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.NH3818
8+
{
9+
[TestFixture]
10+
public class Fixture : BugTestCase
11+
{
12+
public override string BugNumber
13+
{
14+
get { return "NH3818"; }
15+
}
16+
17+
[Test]
18+
public void SelectConditionalValuesTest()
19+
{
20+
using (var spy = new SqlLogSpy())
21+
using (var session = OpenSession())
22+
using (session.BeginTransaction())
23+
{
24+
var days = 33;
25+
26+
var cat = new MyLovelyCat
27+
{
28+
GUID = Guid.NewGuid(),
29+
Birthdate = DateTime.Now.AddDays(-days),
30+
Color = "Black",
31+
Name = "Kitty",
32+
Price = 0
33+
};
34+
session.Save(cat);
35+
36+
session.Flush();
37+
38+
var catInfo =
39+
session.Query<MyLovelyCat>()
40+
.Select(o => new
41+
{
42+
o.Color,
43+
AliveDays = (int)(DateTime.Now - o.Birthdate).TotalDays,
44+
o.Name,
45+
o.Price,
46+
})
47+
.Single();
48+
49+
//Console.WriteLine(spy.ToString());
50+
Assert.That(catInfo.AliveDays == days);
51+
52+
var catInfo2 =
53+
session.Query<MyLovelyCat>()
54+
.Select(o => new
55+
{
56+
o.Color,
57+
AliveDays = o.Price > 0 ? (DateTime.Now - o.Birthdate).TotalDays : 0,
58+
o.Name,
59+
o.Price,
60+
})
61+
.Single();
62+
63+
//Console.WriteLine(spy.ToString());
64+
Assert.That(catInfo2.AliveDays == 0);
65+
66+
}
67+
}
68+
69+
}
70+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH3818"
5+
default-lazy="false"
6+
default-access="property">
7+
8+
<class name="MyLovelyCat" table="MyLovelyCat">
9+
<id column="GUID" name="GUID"></id>
10+
<property column="Name" name="Name" not-null="true"/>
11+
<property column="Color" name="Color" not-null="true"/>
12+
<property column="Birthdate" name="Birthdate" not-null="true"/>
13+
<property column="Price" name="Price" not-null="true"/>
14+
</class>
15+
16+
</hibernate-mapping>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.NHSpecificTest.NH3818
7+
{
8+
class MyLovelyCat
9+
{
10+
public virtual Guid GUID { get; set; }
11+
12+
public virtual String Name { get; set; }
13+
public virtual String Color { get; set; }
14+
public virtual DateTime Birthdate { get; set; }
15+
public virtual Decimal Price { get; set; }
16+
}
17+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,8 @@
872872
<Compile Include="NHSpecificTest\NH3727\Entity.cs" />
873873
<Compile Include="NHSpecificTest\NH3727\FixtureByCode.cs" />
874874
<Compile Include="NHSpecificTest\NH3795\Fixture.cs" />
875+
<Compile Include="NHSpecificTest\NH3818\Fixture.cs" />
876+
<Compile Include="NHSpecificTest\NH3818\MyLovelyCat.cs" />
875877
<Compile Include="NHSpecificTest\NH646\Domain.cs" />
876878
<Compile Include="NHSpecificTest\NH646\Fixture.cs" />
877879
<Compile Include="NHSpecificTest\NH3234\Fixture.cs" />
@@ -3145,6 +3147,7 @@
31453147
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
31463148
</ItemGroup>
31473149
<ItemGroup>
3150+
<EmbeddedResource Include="NHSpecificTest\NH3818\Mappings.hbm.xml" />
31483151
<EmbeddedResource Include="NHSpecificTest\NH3666\Mappings.hbm.xml">
31493152
<SubType>Designer</SubType>
31503153
</EmbeddedResource>

0 commit comments

Comments
 (0)