Skip to content

Commit 9ce5cb2

Browse files
Adjust tests and regen async
To be squashed
1 parent 29d0a23 commit 9ce5cb2

File tree

2 files changed

+194
-9
lines changed

2 files changed

+194
-9
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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.Dialect;
15+
using NHibernate.Mapping.ByCode;
16+
using NUnit.Framework;
17+
using NHibernate.Linq;
18+
19+
namespace NHibernate.Test.NHSpecificTest.GH2029
20+
{
21+
using System.Threading.Tasks;
22+
23+
[TestFixture]
24+
public class FixtureAsync : TestCaseMappingByCode
25+
{
26+
protected override HbmMapping GetMappings()
27+
{
28+
var mapper = new ModelMapper();
29+
mapper.Class<TestClass>(rc =>
30+
{
31+
rc.Id(x => x.Id, m => m.Generator(Generators.Native));
32+
rc.Property(x => x.NullableInt32Prop);
33+
rc.Property(x => x.Int32Prop);
34+
rc.Property(x => x.NullableInt64Prop);
35+
rc.Property(x => x.Int64Prop);
36+
});
37+
38+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
39+
}
40+
41+
protected override bool AppliesTo(Dialect.Dialect dialect)
42+
{
43+
return !(dialect is SQLiteDialect);
44+
}
45+
46+
protected override void OnSetUp()
47+
{
48+
using (var session = OpenSession())
49+
using (var tx = session.BeginTransaction())
50+
{
51+
session.Save(new TestClass
52+
{
53+
Int32Prop = int.MaxValue,
54+
NullableInt32Prop = int.MaxValue,
55+
Int64Prop = int.MaxValue,
56+
NullableInt64Prop = int.MaxValue
57+
});
58+
session.Save(new TestClass
59+
{
60+
Int32Prop = int.MaxValue,
61+
NullableInt32Prop = int.MaxValue,
62+
Int64Prop = int.MaxValue,
63+
NullableInt64Prop = int.MaxValue
64+
});
65+
session.Save(new TestClass
66+
{
67+
Int32Prop = int.MaxValue,
68+
NullableInt32Prop = null,
69+
Int64Prop = int.MaxValue,
70+
NullableInt64Prop = null
71+
});
72+
73+
tx.Commit();
74+
}
75+
}
76+
77+
protected override void OnTearDown()
78+
{
79+
using (var session = OpenSession())
80+
using (var tx = session.BeginTransaction())
81+
{
82+
session.CreateQuery("delete from TestClass").ExecuteUpdate();
83+
84+
tx.Commit();
85+
}
86+
}
87+
88+
[Test]
89+
public async Task NullableIntOverflowAsync()
90+
{
91+
using (var session = OpenSession())
92+
using (session.BeginTransaction())
93+
using (var sqlLog = new SqlLogSpy())
94+
{
95+
var groups = await (session.Query<TestClass>()
96+
.GroupBy(i => 1)
97+
.Select(g => new
98+
{
99+
s = g.Sum(i => (long) i.NullableInt32Prop)
100+
})
101+
.ToListAsync());
102+
103+
Assert.That(FindAllOccurrences(sqlLog.GetWholeLog(), "cast"), Is.EqualTo(1));
104+
Assert.That(groups, Has.Count.EqualTo(1));
105+
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 2));
106+
}
107+
}
108+
109+
[Test]
110+
public async Task IntOverflowAsync()
111+
{
112+
using (var session = OpenSession())
113+
using (session.BeginTransaction())
114+
using (var sqlLog = new SqlLogSpy())
115+
{
116+
var groups = await (session.Query<TestClass>()
117+
.GroupBy(i => 1)
118+
.Select(g => new
119+
{
120+
s = g.Sum(i => (long) i.Int32Prop)
121+
})
122+
.ToListAsync());
123+
124+
Assert.That(FindAllOccurrences(sqlLog.GetWholeLog(), "cast"), Is.EqualTo(1));
125+
Assert.That(groups, Has.Count.EqualTo(1));
126+
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 3));
127+
}
128+
}
129+
130+
[Test]
131+
public async Task NullableInt64NoCastAsync()
132+
{
133+
using (var session = OpenSession())
134+
using (session.BeginTransaction())
135+
using (var sqlLog = new SqlLogSpy())
136+
{
137+
var groups = await (session.Query<TestClass>()
138+
.GroupBy(i => 1)
139+
.Select(g => new {
140+
s = g.Sum(i => i.NullableInt64Prop)
141+
})
142+
.ToListAsync());
143+
144+
Assert.That(sqlLog.GetWholeLog(), Does.Not.Contains("cast"));
145+
Assert.That(groups, Has.Count.EqualTo(1));
146+
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 2));
147+
}
148+
}
149+
150+
[Test]
151+
public async Task Int64NoCastAsync()
152+
{
153+
using (var session = OpenSession())
154+
using (session.BeginTransaction())
155+
using (var sqlLog = new SqlLogSpy())
156+
{
157+
var groups = await (session.Query<TestClass>()
158+
.GroupBy(i => 1)
159+
.Select(g => new {
160+
s = g.Sum(i => i.Int64Prop)
161+
})
162+
.ToListAsync());
163+
164+
Assert.That(sqlLog.GetWholeLog(), Does.Not.Contains("cast"));
165+
Assert.That(groups, Has.Count.EqualTo(1));
166+
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 3));
167+
}
168+
}
169+
170+
private int FindAllOccurrences(string source, string substring)
171+
{
172+
if (source == null)
173+
{
174+
return 0;
175+
}
176+
int n = 0, count = 0;
177+
while ((n = source.IndexOf(substring, n, StringComparison.InvariantCulture)) != -1)
178+
{
179+
n += substring.Length;
180+
count++;
181+
}
182+
return count;
183+
}
184+
}
185+
}

src/NHibernate.Test/NHSpecificTest/GH2029/Fixture.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ public void NullableIntOverflow()
9494
{
9595
s = g.Sum(i => (long) i.NullableInt32Prop)
9696
})
97-
.ToArray();
97+
.ToList();
9898

9999
Assert.That(FindAllOccurrences(sqlLog.GetWholeLog(), "cast"), Is.EqualTo(1));
100-
Assert.That(groups, Has.Length.EqualTo(1));
100+
Assert.That(groups, Has.Count.EqualTo(1));
101101
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 2));
102102
}
103103
}
@@ -115,10 +115,10 @@ public void IntOverflow()
115115
{
116116
s = g.Sum(i => (long) i.Int32Prop)
117117
})
118-
.ToArray();
118+
.ToList();
119119

120120
Assert.That(FindAllOccurrences(sqlLog.GetWholeLog(), "cast"), Is.EqualTo(1));
121-
Assert.That(groups, Has.Length.EqualTo(1));
121+
Assert.That(groups, Has.Count.EqualTo(1));
122122
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 3));
123123
}
124124
}
@@ -135,10 +135,10 @@ public void NullableInt64NoCast()
135135
.Select(g => new {
136136
s = g.Sum(i => i.NullableInt64Prop)
137137
})
138-
.ToArray();
138+
.ToList();
139139

140140
Assert.That(sqlLog.GetWholeLog(), Does.Not.Contains("cast"));
141-
Assert.That(groups, Has.Length.EqualTo(1));
141+
Assert.That(groups, Has.Count.EqualTo(1));
142142
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 2));
143143
}
144144
}
@@ -155,10 +155,10 @@ public void Int64NoCast()
155155
.Select(g => new {
156156
s = g.Sum(i => i.Int64Prop)
157157
})
158-
.ToArray();
158+
.ToList();
159159

160160
Assert.That(sqlLog.GetWholeLog(), Does.Not.Contains("cast"));
161-
Assert.That(groups, Has.Length.EqualTo(1));
161+
Assert.That(groups, Has.Count.EqualTo(1));
162162
Assert.That(groups[0].s, Is.EqualTo((long) int.MaxValue * 3));
163163
}
164164
}
@@ -173,7 +173,7 @@ private int FindAllOccurrences(string source, string substring)
173173
while ((n = source.IndexOf(substring, n, StringComparison.InvariantCulture)) != -1)
174174
{
175175
n += substring.Length;
176-
++count;
176+
count++;
177177
}
178178
return count;
179179
}

0 commit comments

Comments
 (0)