Skip to content

Commit e925fca

Browse files
committed
StringTypeWithLengthFixture: Test more operators, and on more SQL dialects.
Most of these tests are now allowed to run on all SQL dialects, by more narrowly excluding only the cases that are really irrelevant. Also, querying with oversized parameter values are relevant also for the equality operator etc, so add tests for this. Related to NH-3403, NH-3036 and NH-2528.
1 parent a6c78c3 commit e925fca

File tree

1 file changed

+64
-15
lines changed

1 file changed

+64
-15
lines changed

src/NHibernate.Test/TypesTest/StringTypeWithLengthFixture.cs

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,31 @@ protected override IList Mappings
3030
}
3131
}
3232

33-
protected override bool AppliesTo(Dialect.Dialect dialect)
34-
{
35-
// this test only works where the driver has set an explicit length on the IDbDataParameter
36-
return dialect is MsSql2008Dialect;
37-
}
3833

3934
[Test]
4035
public void NhThrowsOnTooLong()
4136
{
37+
if (!(Dialect is MsSql2008Dialect))
38+
Assert.Ignore(
39+
"This test only works (and is only relevant) " +
40+
"where the driver has set an explicit length " +
41+
"on the IDbDataParameter.");
42+
4243
int maxStringLength = 4000;
43-
PropertyValueException ex = Assert.Throws<PropertyValueException>(() =>
44+
PropertyValueException ex = Assert.Throws<PropertyValueException>(
45+
() =>
4446
{
4547
using (ISession s = OpenSession())
4648
{
47-
StringClass b = new StringClass();
48-
b.LongStringValue = new string('x', maxStringLength + 1);
49+
StringClass b = new StringClass {LongStringValue = new string('x', maxStringLength + 1)};
4950
s.Save(b);
5051
s.Flush();
5152
}
5253
});
5354

54-
Assert.That(ex.Message, Iz.EqualTo("Error dehydrating property value for NHibernate.Test.TypesTest.StringClass.LongStringValue"));
55-
Assert.That(ex.InnerException, Iz.TypeOf<HibernateException>());
56-
Assert.That(ex.InnerException.Message, Iz.EqualTo("The length of the string value exceeds the length configured in the mapping/parameter."));
55+
Assert.That(ex.Message, Is.EqualTo("Error dehydrating property value for NHibernate.Test.TypesTest.StringClass.LongStringValue"));
56+
Assert.That(ex.InnerException, Is.TypeOf<HibernateException>());
57+
Assert.That(ex.InnerException.Message, Is.EqualTo("The length of the string value exceeds the length configured in the mapping/parameter."));
5758
}
5859

5960
[Test]
@@ -65,8 +66,7 @@ public void DbThrowsOnTooLong()
6566
{
6667
using (ISession s = OpenSession())
6768
{
68-
StringClass b = new StringClass();
69-
b.StringValue = "0123456789a";
69+
StringClass b = new StringClass {StringValue = "0123456789a"};
7070
s.Save(b);
7171
s.Flush();
7272
}
@@ -82,7 +82,7 @@ public void DbThrowsOnTooLong()
8282
[Test]
8383
public void CriteriaLikeParameterCanExceedColumnSize()
8484
{
85-
if (!(sessions.ConnectionProvider.Driver is SqlClientDriver))
85+
if (sessions.ConnectionProvider.Driver is OdbcDriver)
8686
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
8787

8888
using (ISession s = OpenSession())
@@ -103,7 +103,7 @@ public void CriteriaLikeParameterCanExceedColumnSize()
103103
[Test]
104104
public void HqlLikeParameterCanExceedColumnSize()
105105
{
106-
if (!(sessions.ConnectionProvider.Driver is SqlClientDriver))
106+
if (sessions.ConnectionProvider.Driver is OdbcDriver)
107107
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
108108

109109
using (ISession s = OpenSession())
@@ -120,5 +120,54 @@ public void HqlLikeParameterCanExceedColumnSize()
120120
Assert.That(aaItems.Count, Is.EqualTo(2));
121121
}
122122
}
123+
124+
125+
[Test]
126+
public void CriteriaEqualityParameterCanExceedColumnSize()
127+
{
128+
if (sessions.ConnectionProvider.Driver is OdbcDriver)
129+
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
130+
131+
// We should be able to query a column with a value longer than
132+
// the specified column size, to avoid tedious exceptions.
133+
134+
using (ISession s = OpenSession())
135+
using (s.BeginTransaction())
136+
{
137+
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
138+
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
139+
140+
var aaItems =
141+
s.CreateCriteria<StringClass>()
142+
.Add(Restrictions.Eq("StringValue", "AAAAAAAAABx"))
143+
.List();
144+
145+
Assert.That(aaItems.Count, Is.EqualTo(0));
146+
}
147+
}
148+
149+
[Test]
150+
public void HqlEqualityParameterCanExceedColumnSize()
151+
{
152+
if (sessions.ConnectionProvider.Driver is OdbcDriver)
153+
Assert.Ignore("This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column.");
154+
155+
// We should be able to query a column with a value longer than
156+
// the specified column size, to avoid tedious exceptions.
157+
158+
using (ISession s = OpenSession())
159+
using (s.BeginTransaction())
160+
{
161+
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
162+
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
163+
164+
var aaItems =
165+
s.CreateQuery("from StringClass s where s.StringValue = :likeValue")
166+
.SetParameter("likeValue", "AAAAAAAAABx")
167+
.List();
168+
169+
Assert.That(aaItems.Count, Is.EqualTo(0));
170+
}
171+
}
123172
}
124173
}

0 commit comments

Comments
 (0)