Skip to content

Commit 1f35225

Browse files
NH-3919 - Firebird "fix", to be squashed
1 parent f9cfbac commit 1f35225

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

src/NHibernate.Test/Async/TypesTest/DateTimeTypeFixture.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ public async Task NextAsync()
4040
object current = DateTime.Parse("2004-01-01");
4141
object next = await (type.NextAsync(current, null, CancellationToken.None));
4242

43-
Assert.IsTrue(next is DateTime, "Next should be DateTime");
44-
Assert.IsTrue(
45-
(DateTime) next > (DateTime) current,
46-
"next should be greater than current (could be equal depending on how quickly this occurs)");
43+
Assert.That(next, Is.TypeOf<DateTime>(), "next should be DateTime");
44+
Assert.That(next, Is.GreaterThan(current), "next should be greater than current");
4745
}
4846

4947
[Test]
5048
public async Task SeedAsync()
5149
{
5250
var type = NHibernateUtil.DateTime;
53-
Assert.IsTrue(await (type.SeedAsync(null, CancellationToken.None)) is DateTime, "seed should be DateTime");
51+
Assert.That(await (type.SeedAsync(null, CancellationToken.None)), Is.TypeOf<DateTime>(), "seed should be DateTime");
5452
}
5553
}
5654

@@ -137,7 +135,7 @@ public async Task SaveUseExpectedSqlTypeAsync()
137135
await (t.CommitAsync());
138136
}
139137

140-
AssertSqlType(driver);
138+
AssertSqlType(driver, 3);
141139
}
142140

143141
[Test]
@@ -156,12 +154,15 @@ public async Task UpdateUseExpectedSqlTypeAsync()
156154
await (t.CommitAsync());
157155
}
158156

159-
AssertSqlType(driver);
157+
AssertSqlType(driver, 3);
160158
}
161159

162160
[Test]
163161
public async Task QueryUseExpectedSqlTypeAsync()
164162
{
163+
if (!TestDialect.SupportsNonDataBoundCondition)
164+
Assert.Ignore("Dialect does not support the test query");
165+
165166
var driver = (ClientDriverWithParamsStats) Sfi.ConnectionProvider.Driver;
166167

167168
using (var s = OpenSession())
@@ -182,10 +183,10 @@ public async Task QueryUseExpectedSqlTypeAsync()
182183
await (t.CommitAsync());
183184
}
184185

185-
AssertSqlType(driver);
186+
AssertSqlType(driver, 5);
186187
}
187188

188-
private void AssertSqlType(ClientDriverWithParamsStats driver)
189+
private void AssertSqlType(ClientDriverWithParamsStats driver, int expectedCount)
189190
{
190191
if (NHibernateUtil.DateTime.SqlTypes(Sfi).Any(t => Equals(t, SqlTypeFactory.DateTime2)))
191192
{
@@ -198,7 +199,10 @@ private void AssertSqlType(ClientDriverWithParamsStats driver)
198199
Is.GreaterThan(0),
199200
"Missing SqlTypeFactory.DateTime2 usages.");
200201
Assert.That(driver.GetCount(DbType.DateTime), Is.EqualTo(0), "Found unexpected DbType.DateTime usages.");
201-
Assert.That(driver.GetCount(DbType.DateTime2), Is.GreaterThan(0), "Missing DbType.DateTime2 usages.");
202+
Assert.That(
203+
driver.GetCount(DbType.DateTime2),
204+
Is.EqualTo(expectedCount),
205+
"Unexpected DbType.DateTime2 usage count.");
202206
}
203207
else
204208
{
@@ -211,7 +215,7 @@ private void AssertSqlType(ClientDriverWithParamsStats driver)
211215
Is.GreaterThan(0),
212216
"Missing SqlTypeFactory.DateTime usages.");
213217
Assert.That(driver.GetCount(DbType.DateTime2), Is.EqualTo(0), "Found unexpected DbType.DateTime2 usages.");
214-
Assert.That(driver.GetCount(DbType.DateTime), Is.GreaterThan(0), "Missing DbType.DateTime usages.");
218+
Assert.That(driver.GetCount(DbType.DateTime), Is.EqualTo(expectedCount), "Unexpected DbType.DateTime usage count.");
215219
}
216220
}
217221
}

src/NHibernate.Test/TestDialect.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public TestDialect(Dialect.Dialect dialect)
5555
/// </summary>
5656
public virtual bool SupportsEmptyInserts => true;
5757

58+
/// <summary>
59+
/// Supports condition not bound to any data, like "where @p1 = @p2".
60+
/// </summary>
61+
public virtual bool SupportsNonDataBoundCondition => true;
62+
5863
public bool SupportsSqlType(SqlType sqlType)
5964
{
6065
try

src/NHibernate.Test/TestDialects/FirebirdTestDialect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public FirebirdTestDialect(Dialect.Dialect dialect) : base(dialect)
77
}
88

99
public override bool SupportsComplexExpressionInGroupBy => false;
10+
public override bool SupportsNonDataBoundCondition => false;
1011
}
1112
}

src/NHibernate.Test/TypesTest/DateTimeTypeFixture.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void SaveUseExpectedSqlType()
148148
t.Commit();
149149
}
150150

151-
AssertSqlType(driver);
151+
AssertSqlType(driver, 3);
152152
}
153153

154154
[Test]
@@ -167,12 +167,15 @@ public void UpdateUseExpectedSqlType()
167167
t.Commit();
168168
}
169169

170-
AssertSqlType(driver);
170+
AssertSqlType(driver, 3);
171171
}
172172

173173
[Test]
174174
public void QueryUseExpectedSqlType()
175175
{
176+
if (!TestDialect.SupportsNonDataBoundCondition)
177+
Assert.Ignore("Dialect does not support the test query");
178+
176179
var driver = (ClientDriverWithParamsStats) Sfi.ConnectionProvider.Driver;
177180

178181
using (var s = OpenSession())
@@ -193,10 +196,10 @@ public void QueryUseExpectedSqlType()
193196
t.Commit();
194197
}
195198

196-
AssertSqlType(driver);
199+
AssertSqlType(driver, 5);
197200
}
198201

199-
private void AssertSqlType(ClientDriverWithParamsStats driver)
202+
private void AssertSqlType(ClientDriverWithParamsStats driver, int expectedCount)
200203
{
201204
if (NHibernateUtil.DateTime.SqlTypes(Sfi).Any(t => Equals(t, SqlTypeFactory.DateTime2)))
202205
{
@@ -209,7 +212,10 @@ private void AssertSqlType(ClientDriverWithParamsStats driver)
209212
Is.GreaterThan(0),
210213
"Missing SqlTypeFactory.DateTime2 usages.");
211214
Assert.That(driver.GetCount(DbType.DateTime), Is.EqualTo(0), "Found unexpected DbType.DateTime usages.");
212-
Assert.That(driver.GetCount(DbType.DateTime2), Is.GreaterThan(0), "Missing DbType.DateTime2 usages.");
215+
Assert.That(
216+
driver.GetCount(DbType.DateTime2),
217+
Is.EqualTo(expectedCount),
218+
"Unexpected DbType.DateTime2 usage count.");
213219
}
214220
else
215221
{
@@ -222,7 +228,7 @@ private void AssertSqlType(ClientDriverWithParamsStats driver)
222228
Is.GreaterThan(0),
223229
"Missing SqlTypeFactory.DateTime usages.");
224230
Assert.That(driver.GetCount(DbType.DateTime2), Is.EqualTo(0), "Found unexpected DbType.DateTime2 usages.");
225-
Assert.That(driver.GetCount(DbType.DateTime), Is.GreaterThan(0), "Missing DbType.DateTime usages.");
231+
Assert.That(driver.GetCount(DbType.DateTime), Is.EqualTo(expectedCount), "Unexpected DbType.DateTime usage count.");
226232
}
227233
}
228234
}

0 commit comments

Comments
 (0)