Skip to content

Commit 26472ed

Browse files
committed
Fix CustomType cast for Linq provider
1 parent cf32e05 commit 26472ed

File tree

10 files changed

+793
-0
lines changed

10 files changed

+793
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Linq;
13+
using NHibernate.Cfg.MappingSchema;
14+
using NHibernate.Mapping.ByCode;
15+
using NUnit.Framework;
16+
using NHibernate.Linq;
17+
18+
namespace NHibernate.Test.NHSpecificTest.GH2437
19+
{
20+
using System.Threading.Tasks;
21+
[TestFixture]
22+
public class FixtureAsync : TestCaseMappingByCode
23+
{
24+
protected override HbmMapping GetMappings()
25+
{
26+
var mapper = new ModelMapper();
27+
mapper.AddMapping<UserMapping>();
28+
mapper.AddMapping<UserSessionMapping>();
29+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
30+
}
31+
32+
protected override void OnSetUp()
33+
{
34+
using (var session = OpenSession())
35+
using (var transaction = session.BeginTransaction())
36+
{
37+
User user = new User() { UserCode = "gokhanabatay", IsOpen = true, UserName = "Gökhan Abatay" };
38+
session.Save(user);
39+
40+
for (int i = 0; i < 10; i++)
41+
{
42+
UserSession userSession = new UserSession()
43+
{
44+
Claims = "My Claims",
45+
ExpireDateTime = DateTime.Now.AddDays(1),
46+
MbrId = 1,
47+
OpenDate = DateTime.Now,
48+
LocalIpAddress = "192.168.1.1",
49+
RemoteIpAddress = "127.0.0.1",
50+
LocalPort = 80 + i.ToString(),
51+
RemotePort = 80 + i.ToString(),
52+
DeviceId = "None",
53+
UserCode = "gokhanabatay",
54+
IsOpen = true
55+
};
56+
57+
session.Save(userSession);
58+
}
59+
60+
transaction.Commit();
61+
}
62+
}
63+
64+
protected override void OnTearDown()
65+
{
66+
using (var session = OpenSession())
67+
using (var transaction = session.BeginTransaction())
68+
{
69+
session.CreateQuery("delete from UserSession").ExecuteUpdate();
70+
session.CreateQuery("delete from User").ExecuteUpdate();
71+
72+
transaction.Commit();
73+
}
74+
}
75+
76+
[Test]
77+
public async Task Get_DateCustomType_NullableDateValueEqualsAsync()
78+
{
79+
using (var session = OpenSession())
80+
using (var transaction = session.BeginTransaction())
81+
{
82+
Assert.That((await (session.Query<UserSession>()
83+
.Where(x => x.OpenDate.Value == DateTime.Now)
84+
.ToListAsync())).Count == 10);
85+
}
86+
}
87+
88+
[Test]
89+
public async Task Get_DateTimeCustomType_NullableDateValueEqualsAsync()
90+
{
91+
using (var session = OpenSession())
92+
using (var transaction = session.BeginTransaction())
93+
{
94+
Assert.That((await (session.Query<UserSession>()
95+
.Where(x => x.ExpireDateTime.Value > DateTime.Now)
96+
.ToListAsync())).Count == 10);
97+
}
98+
}
99+
100+
[Test]
101+
public async Task Get_DateCustomType_DateEqualsAsync()
102+
{
103+
using (var session = OpenSession())
104+
using (var transaction = session.BeginTransaction())
105+
{
106+
Assert.That((await (session.Query<UserSession>()
107+
.Where(x => x.OpenDate == DateTime.Now)
108+
.ToListAsync())).Count == 10);
109+
}
110+
}
111+
112+
[Test]
113+
public async Task Get_DateTimeCustomType_DateEqualsAsync()
114+
{
115+
using (var session = OpenSession())
116+
using (var transaction = session.BeginTransaction())
117+
{
118+
Assert.That((await (session.Query<UserSession>()
119+
.Where(x => x.ExpireDateTime > DateTime.Now)
120+
.ToListAsync())).Count == 10);
121+
}
122+
}
123+
124+
[Test]
125+
public async Task Get_BooleanCustomTypeAsync()
126+
{
127+
128+
using (var session = OpenSession())
129+
using (var transaction = session.BeginTransaction())
130+
{
131+
Assert.That(
132+
(await (session.Query<UserSession>()
133+
.Where(x => x.OpenDate == DateTime.Now)
134+
.Select(x => new NullableBooleanResult() {IsOpen = x.User.IsOpen})
135+
.ToListAsync())).Count == 10);
136+
}
137+
}
138+
139+
public class NullableBooleanResult
140+
{
141+
public bool? IsOpen { get; set; }
142+
}
143+
}
144+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System;
2+
using System.Linq;
3+
using NHibernate.Cfg.MappingSchema;
4+
using NHibernate.Mapping.ByCode;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.GH2437
8+
{
9+
[TestFixture]
10+
public class Fixture : TestCaseMappingByCode
11+
{
12+
protected override HbmMapping GetMappings()
13+
{
14+
var mapper = new ModelMapper();
15+
mapper.AddMapping<UserMapping>();
16+
mapper.AddMapping<UserSessionMapping>();
17+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
18+
}
19+
20+
protected override void OnSetUp()
21+
{
22+
using (var session = OpenSession())
23+
using (var transaction = session.BeginTransaction())
24+
{
25+
User user = new User() { UserCode = "gokhanabatay", IsOpen = true, UserName = "Gökhan Abatay" };
26+
session.Save(user);
27+
28+
for (int i = 0; i < 10; i++)
29+
{
30+
UserSession userSession = new UserSession()
31+
{
32+
Claims = "My Claims",
33+
ExpireDateTime = DateTime.Now.AddDays(1),
34+
MbrId = 1,
35+
OpenDate = DateTime.Now,
36+
LocalIpAddress = "192.168.1.1",
37+
RemoteIpAddress = "127.0.0.1",
38+
LocalPort = 80 + i.ToString(),
39+
RemotePort = 80 + i.ToString(),
40+
DeviceId = "None",
41+
UserCode = "gokhanabatay",
42+
IsOpen = true
43+
};
44+
45+
session.Save(userSession);
46+
}
47+
48+
transaction.Commit();
49+
}
50+
}
51+
52+
protected override void OnTearDown()
53+
{
54+
using (var session = OpenSession())
55+
using (var transaction = session.BeginTransaction())
56+
{
57+
session.CreateQuery("delete from UserSession").ExecuteUpdate();
58+
session.CreateQuery("delete from User").ExecuteUpdate();
59+
60+
transaction.Commit();
61+
}
62+
}
63+
64+
[Test]
65+
public void Get_DateCustomType_NullableDateValueEquals()
66+
{
67+
using (var session = OpenSession())
68+
using (var transaction = session.BeginTransaction())
69+
{
70+
Assert.That(session.Query<UserSession>()
71+
.Where(x => x.OpenDate.Value == DateTime.Now)
72+
.ToList().Count == 10);
73+
}
74+
}
75+
76+
[Test]
77+
public void Get_DateTimeCustomType_NullableDateValueEquals()
78+
{
79+
using (var session = OpenSession())
80+
using (var transaction = session.BeginTransaction())
81+
{
82+
Assert.That(session.Query<UserSession>()
83+
.Where(x => x.ExpireDateTime.Value > DateTime.Now)
84+
.ToList().Count == 10);
85+
}
86+
}
87+
88+
[Test]
89+
public void Get_DateCustomType_DateEquals()
90+
{
91+
using (var session = OpenSession())
92+
using (var transaction = session.BeginTransaction())
93+
{
94+
Assert.That(session.Query<UserSession>()
95+
.Where(x => x.OpenDate == DateTime.Now)
96+
.ToList().Count == 10);
97+
}
98+
}
99+
100+
[Test]
101+
public void Get_DateTimeCustomType_DateEquals()
102+
{
103+
using (var session = OpenSession())
104+
using (var transaction = session.BeginTransaction())
105+
{
106+
Assert.That(session.Query<UserSession>()
107+
.Where(x => x.ExpireDateTime > DateTime.Now)
108+
.ToList().Count == 10);
109+
}
110+
}
111+
112+
[Test]
113+
public void Get_BooleanCustomType()
114+
{
115+
using (var session = OpenSession())
116+
using (var transaction = session.BeginTransaction())
117+
{
118+
Assert.That(
119+
session.Query<UserSession>()
120+
.Where(x => x.OpenDate == DateTime.Now)
121+
.Select(x => new NullableBooleanResult() {IsOpen = x.User.IsOpen})
122+
.ToList().Count == 10);
123+
}
124+
}
125+
126+
public class NullableBooleanResult
127+
{
128+
public bool? IsOpen { get; set; }
129+
}
130+
}
131+
}

0 commit comments

Comments
 (0)