Skip to content

Commit 0e8516e

Browse files
committed
StringTypeWithLengthFixture: Use shorter length on Oracle.
Due to char set we may not be able to use 4000 characters on Oracle in the test environment. Try 2000 instead. Switch StringTypeWithLengthFixture over to mapping-by-code to facility different mapping on different dialects.
1 parent 0117755 commit 0e8516e

File tree

3 files changed

+41
-56
lines changed

3 files changed

+41
-56
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3302,7 +3302,6 @@
33023302
<EmbeddedResource Include="NHSpecificTest\NH2913\Mappings.hbm.xml">
33033303
<SubType>Designer</SubType>
33043304
</EmbeddedResource>
3305-
<EmbeddedResource Include="TypesTest\StringClassWithLength.hbm.xml" />
33063305
<EmbeddedResource Include="NHSpecificTest\NH2846\Mappings.hbm.xml" />
33073306
<EmbeddedResource Include="NHSpecificTest\NH1007\Mappings.hbm.xml" />
33083307
<EmbeddedResource Include="NHSpecificTest\NH2907\Mappings.hbm.xml" />

src/NHibernate.Test/TypesTest/StringClassWithLength.hbm.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/NHibernate.Test/TypesTest/StringTypeWithLengthFixture.cs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
using System;
2-
using System.Collections;
1+
using NHibernate.Cfg.MappingSchema;
32
using NHibernate.Criterion;
43
using NHibernate.Dialect;
54
using NHibernate.Driver;
5+
using NHibernate.Exceptions;
6+
using NHibernate.Mapping.ByCode;
67
using NUnit.Framework;
78

89
namespace NHibernate.Test.TypesTest
910
{
1011
/// <summary>
11-
/// Summary description for StringTypeWithLengthFixture.
12+
/// Various tests regarding handling of size of query parameters.
1213
/// </summary>
1314
[TestFixture]
14-
public class StringTypeWithLengthFixture : TypeFixtureBase
15+
public class StringTypeWithLengthFixture : TestCaseMappingByCode
1516
{
16-
protected override string TypeName
17+
private int GetLongStringMappedLength()
1718
{
18-
get { return "String"; }
19+
if (Dialect is Oracle8iDialect)
20+
return 2000;
21+
else
22+
return 4000;
1923
}
2024

21-
22-
protected override IList Mappings
25+
protected override HbmMapping GetMappings()
2326
{
24-
get
27+
var mapper = new ModelMapper();
28+
mapper.Class<StringClass>(ca =>
2529
{
26-
return new string[]
27-
{
28-
String.Format("TypesTest.{0}ClassWithLength.hbm.xml", TypeName)
29-
};
30-
}
30+
ca.Lazy(false);
31+
ca.Id(x => x.Id, map => map.Generator(Generators.Assigned));
32+
ca.Property(x => x.StringValue, map => map.Length(10));
33+
ca.Property(x => x.LongStringValue, map => map.Length(GetLongStringMappedLength()));
34+
});
35+
36+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
3137
}
3238

3339

@@ -40,7 +46,7 @@ public void NhThrowsOnTooLong()
4046
"where the driver has set an explicit length " +
4147
"on the IDbDataParameter.");
4248

43-
int maxStringLength = 4000;
49+
int maxStringLength = GetLongStringMappedLength();
4450
PropertyValueException ex = Assert.Throws<PropertyValueException>(
4551
() =>
4652
{
@@ -60,23 +66,17 @@ public void NhThrowsOnTooLong()
6066
[Test]
6167
public void DbThrowsOnTooLong()
6268
{
63-
bool dbThrewError = false;
64-
65-
try
66-
{
67-
using (ISession s = OpenSession())
69+
Assert.Throws<GenericADOException>(
70+
() =>
6871
{
69-
StringClass b = new StringClass {StringValue = "0123456789a"};
70-
s.Save(b);
71-
s.Flush();
72-
}
73-
}
74-
catch
75-
{
76-
dbThrewError = true;
77-
}
78-
79-
Assert.That(dbThrewError, "Database did not throw an error when trying to put too large a value into a column");
72+
using (ISession s = OpenSession())
73+
{
74+
StringClass b = new StringClass {StringValue = "0123456789a"};
75+
s.Save(b);
76+
s.Flush();
77+
}
78+
},
79+
"Database did not throw an error when trying to put too large a value into a column.");
8080
}
8181

8282
[Test]
@@ -86,15 +86,15 @@ public void CriteriaLikeParameterCanExceedColumnSize()
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())
89-
using (ITransaction t = s.BeginTransaction())
89+
using (s.BeginTransaction())
9090
{
91-
s.Save(new StringClass() { Id = 1, StringValue = "AAAAAAAAAB" });
92-
s.Save(new StringClass() { Id = 2, StringValue = "BAAAAAAAAA" });
91+
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
92+
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
9393

9494
var aaItems =
9595
s.CreateCriteria<StringClass>()
96-
.Add(Restrictions.Like("StringValue", "%AAAAAAAAA%"))
97-
.List();
96+
.Add(Restrictions.Like("StringValue", "%AAAAAAAAA%"))
97+
.List();
9898

9999
Assert.That(aaItems.Count, Is.EqualTo(2));
100100
}
@@ -107,15 +107,15 @@ public void HqlLikeParameterCanExceedColumnSize()
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())
110-
using (ITransaction t = s.BeginTransaction())
110+
using (s.BeginTransaction())
111111
{
112-
s.Save(new StringClass() { Id = 1, StringValue = "AAAAAAAAAB" });
113-
s.Save(new StringClass() { Id = 2, StringValue = "BAAAAAAAAA" });
112+
s.Save(new StringClass { Id = 1, StringValue = "AAAAAAAAAB" });
113+
s.Save(new StringClass { Id = 2, StringValue = "BAAAAAAAAA" });
114114

115115
var aaItems =
116116
s.CreateQuery("from StringClass s where s.StringValue like :likeValue")
117-
.SetParameter("likeValue", "%AAAAAAAAA%")
118-
.List();
117+
.SetParameter("likeValue", "%AAAAAAAAA%")
118+
.List();
119119

120120
Assert.That(aaItems.Count, Is.EqualTo(2));
121121
}

0 commit comments

Comments
 (0)