Skip to content

Commit ce1169f

Browse files
committed
StringTypeWithLengthFixture: Ignore some well-known failures on Firebird.
Apparently we're supposed to add casts around the SQL parameters otherwise Firebird seems to grab the type from the other operand. But that is a separate issue.
1 parent 081a446 commit ce1169f

File tree

1 file changed

+120
-52
lines changed

1 file changed

+120
-52
lines changed

src/NHibernate.Test/TypesTest/StringTypeWithLengthFixture.cs

Lines changed: 120 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -133,92 +133,160 @@ private void AssertFailedInsertExceptionDetailsAndEmptyTable(Exception ex)
133133
[Test]
134134
public void CriteriaLikeParameterCanExceedColumnSize()
135135
{
136-
if (sessions.ConnectionProvider.Driver is OdbcDriver)
137-
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
136+
Exception exception = CatchException<Exception>(
137+
() =>
138+
{
139+
using (ISession s = OpenSession())
140+
using (s.BeginTransaction())
141+
{
142+
s.Save(new StringClass {Id = 1, StringValue = "AAAAAAAAAB"});
143+
s.Save(new StringClass {Id = 2, StringValue = "BAAAAAAAAA"});
138144

139-
using (ISession s = OpenSession())
140-
using (s.BeginTransaction())
141-
{
142-
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
143-
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
145+
var aaItems =
146+
s.CreateCriteria<StringClass>()
147+
.Add(Restrictions.Like("StringValue", "%AAAAAAAAA%"))
148+
.List();
149+
150+
Assert.That(aaItems.Count, Is.EqualTo(2));
151+
}
152+
});
144153

145-
var aaItems =
146-
s.CreateCriteria<StringClass>()
147-
.Add(Restrictions.Like("StringValue", "%AAAAAAAAA%"))
148-
.List();
149154

150-
Assert.That(aaItems.Count, Is.EqualTo(2));
151-
}
155+
// This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.
156+
AssertExpectedFailureOrNoException(
157+
exception,
158+
(sessions.ConnectionProvider.Driver is OdbcDriver));
152159
}
153160

154161
[Test]
155162
public void HqlLikeParameterCanExceedColumnSize()
156163
{
157-
if (sessions.ConnectionProvider.Driver is OdbcDriver)
158-
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
164+
Exception exception = CatchException<Exception>(
165+
() =>
166+
{
167+
using (ISession s = OpenSession())
168+
using (s.BeginTransaction())
169+
{
170+
s.Save(new StringClass {Id = 1, StringValue = "AAAAAAAAAB"});
171+
s.Save(new StringClass {Id = 2, StringValue = "BAAAAAAAAA"});
159172

160-
using (ISession s = OpenSession())
161-
using (s.BeginTransaction())
162-
{
163-
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
164-
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
173+
var aaItems =
174+
s.CreateQuery("from StringClass s where s.StringValue like :likeValue")
175+
.SetParameter("likeValue", "%AAAAAAAAA%")
176+
.List();
165177

166-
var aaItems =
167-
s.CreateQuery("from StringClass s where s.StringValue like :likeValue")
168-
.SetParameter("likeValue", "%AAAAAAAAA%")
169-
.List();
178+
Assert.That(aaItems.Count, Is.EqualTo(2));
179+
}
180+
});
170181

171-
Assert.That(aaItems.Count, Is.EqualTo(2));
172-
}
182+
183+
// This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.
184+
AssertExpectedFailureOrNoException(
185+
exception,
186+
(sessions.ConnectionProvider.Driver is OdbcDriver));
173187
}
174188

175189

176190
[Test]
177191
public void CriteriaEqualityParameterCanExceedColumnSize()
178192
{
179-
if (sessions.ConnectionProvider.Driver is OdbcDriver)
180-
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
181-
182193
// We should be able to query a column with a value longer than
183194
// the specified column size, to avoid tedious exceptions.
184195

185-
using (ISession s = OpenSession())
186-
using (s.BeginTransaction())
187-
{
188-
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
189-
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
196+
Exception exception = CatchException<Exception>(
197+
() =>
198+
{
199+
using (ISession s = OpenSession())
200+
using (s.BeginTransaction())
201+
{
202+
s.Save(new StringClass {Id = 1, StringValue = "AAAAAAAAAB"});
203+
s.Save(new StringClass {Id = 2, StringValue = "BAAAAAAAAA"});
190204

191-
var aaItems =
192-
s.CreateCriteria<StringClass>()
193-
.Add(Restrictions.Eq("StringValue", "AAAAAAAAABx"))
194-
.List();
205+
var aaItems =
206+
s.CreateCriteria<StringClass>()
207+
.Add(Restrictions.Eq("StringValue", "AAAAAAAAABx"))
208+
.List();
195209

196-
Assert.That(aaItems.Count, Is.EqualTo(0));
197-
}
210+
Assert.That(aaItems.Count, Is.EqualTo(0));
211+
}
212+
});
213+
214+
// Doesn't work on Firebird due to Firebird not figuring out parameter types on its own.
215+
// This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.
216+
AssertExpectedFailureOrNoException(
217+
exception,
218+
(Dialect is FirebirdDialect) || (sessions.ConnectionProvider.Driver is OdbcDriver));
198219
}
199220

221+
200222
[Test]
201223
public void HqlEqualityParameterCanExceedColumnSize()
202224
{
203-
if (sessions.ConnectionProvider.Driver is OdbcDriver)
204-
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
205-
206225
// We should be able to query a column with a value longer than
207226
// the specified column size, to avoid tedious exceptions.
208227

209-
using (ISession s = OpenSession())
210-
using (s.BeginTransaction())
228+
Exception exception = CatchException<Exception>(
229+
() =>
230+
{
231+
using (ISession s = OpenSession())
232+
using (s.BeginTransaction())
233+
{
234+
s.Save(new StringClass {Id = 1, StringValue = "AAAAAAAAAB"});
235+
s.Save(new StringClass {Id = 2, StringValue = "BAAAAAAAAA"});
236+
237+
var aaItems =
238+
s.CreateQuery("from StringClass s where s.StringValue = :likeValue")
239+
.SetParameter("likeValue", "AAAAAAAAABx")
240+
.List();
241+
242+
Assert.That(aaItems.Count, Is.EqualTo(0));
243+
}
244+
});
245+
246+
// Doesn't work on Firebird due to Firebird not figuring out parameter types on its own.
247+
// This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.
248+
AssertExpectedFailureOrNoException(
249+
exception,
250+
(Dialect is FirebirdDialect) || (sessions.ConnectionProvider.Driver is OdbcDriver));
251+
}
252+
253+
254+
/// <summary>
255+
/// Some test cases doesn't work during some scenarios for well-known reasons. If the test
256+
/// fails under these circumstances, mark it as IGNORED. If it _stops_ failing, mark it
257+
/// as a FAILURE so that it can be investigated.
258+
/// </summary>
259+
private void AssertExpectedFailureOrNoException(Exception exception, bool requireExceptionAndIgnoreTest)
260+
{
261+
if (requireExceptionAndIgnoreTest)
211262
{
212-
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
213-
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
263+
Assert.NotNull(
264+
exception,
265+
"Test was expected to have a well-known, but ignored, failure for the current configuration. If " +
266+
"that expected failure no longer occurs, it may now be possible to remove this exception.");
267+
268+
Assert.Ignore("This test is known to fail for the current configuration.");
269+
}
270+
271+
// If the above didn't ignore the exception, it's for real - rethrow to trigger test failure.
272+
if (exception != null)
273+
throw new Exception("Wrapped exception.", exception);
274+
}
214275

215-
var aaItems =
216-
s.CreateQuery("from StringClass s where s.StringValue = :likeValue")
217-
.SetParameter("likeValue", "AAAAAAAAABx")
218-
.List();
219276

220-
Assert.That(aaItems.Count, Is.EqualTo(0));
277+
private TException CatchException<TException>(System.Action action)
278+
where TException : Exception
279+
{
280+
try
281+
{
282+
action();
221283
}
284+
catch (TException exception)
285+
{
286+
return exception;
287+
}
288+
289+
return null;
222290
}
223291
}
224292
}

0 commit comments

Comments
 (0)