1
- using System ;
2
- using System . Collections ;
1
+ using NHibernate . Cfg . MappingSchema ;
3
2
using NHibernate . Criterion ;
4
3
using NHibernate . Dialect ;
5
4
using NHibernate . Driver ;
5
+ using NHibernate . Exceptions ;
6
+ using NHibernate . Mapping . ByCode ;
6
7
using NUnit . Framework ;
7
8
8
9
namespace NHibernate . Test . TypesTest
9
10
{
10
11
/// <summary>
11
- /// Summary description for StringTypeWithLengthFixture .
12
+ /// Various tests regarding handling of size of query parameters .
12
13
/// </summary>
13
14
[ TestFixture ]
14
- public class StringTypeWithLengthFixture : TypeFixtureBase
15
+ public class StringTypeWithLengthFixture : TestCaseMappingByCode
15
16
{
16
- protected override string TypeName
17
+ private int GetLongStringMappedLength ( )
17
18
{
18
- get { return "String" ; }
19
+ if ( Dialect is Oracle8iDialect )
20
+ return 2000 ;
21
+ else
22
+ return 4000 ;
19
23
}
20
24
21
-
22
- protected override IList Mappings
25
+ protected override HbmMapping GetMappings ( )
23
26
{
24
- get
27
+ var mapper = new ModelMapper ( ) ;
28
+ mapper . Class < StringClass > ( ca =>
25
29
{
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 ( ) ;
31
37
}
32
38
33
39
@@ -40,7 +46,7 @@ public void NhThrowsOnTooLong()
40
46
"where the driver has set an explicit length " +
41
47
"on the IDbDataParameter." ) ;
42
48
43
- int maxStringLength = 4000 ;
49
+ int maxStringLength = GetLongStringMappedLength ( ) ;
44
50
PropertyValueException ex = Assert . Throws < PropertyValueException > (
45
51
( ) =>
46
52
{
@@ -60,23 +66,17 @@ public void NhThrowsOnTooLong()
60
66
[ Test ]
61
67
public void DbThrowsOnTooLong ( )
62
68
{
63
- bool dbThrewError = false ;
64
-
65
- try
66
- {
67
- using ( ISession s = OpenSession ( ) )
69
+ Assert . Throws < GenericADOException > (
70
+ ( ) =>
68
71
{
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." ) ;
80
80
}
81
81
82
82
[ Test ]
@@ -86,15 +86,15 @@ public void CriteriaLikeParameterCanExceedColumnSize()
86
86
Assert . Ignore ( "This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column." ) ;
87
87
88
88
using ( ISession s = OpenSession ( ) )
89
- using ( ITransaction t = s . BeginTransaction ( ) )
89
+ using ( s . BeginTransaction ( ) )
90
90
{
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" } ) ;
93
93
94
94
var aaItems =
95
95
s . CreateCriteria < StringClass > ( )
96
- . Add ( Restrictions . Like ( "StringValue" , "%AAAAAAAAA%" ) )
97
- . List ( ) ;
96
+ . Add ( Restrictions . Like ( "StringValue" , "%AAAAAAAAA%" ) )
97
+ . List ( ) ;
98
98
99
99
Assert . That ( aaItems . Count , Is . EqualTo ( 2 ) ) ;
100
100
}
@@ -107,15 +107,15 @@ public void HqlLikeParameterCanExceedColumnSize()
107
107
Assert . Ignore ( "This test fails against the ODBC driver. The driver would need to be override to allow longer parameter sizes than the column." ) ;
108
108
109
109
using ( ISession s = OpenSession ( ) )
110
- using ( ITransaction t = s . BeginTransaction ( ) )
110
+ using ( s . BeginTransaction ( ) )
111
111
{
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" } ) ;
114
114
115
115
var aaItems =
116
116
s . CreateQuery ( "from StringClass s where s.StringValue like :likeValue" )
117
- . SetParameter ( "likeValue" , "%AAAAAAAAA%" )
118
- . List ( ) ;
117
+ . SetParameter ( "likeValue" , "%AAAAAAAAA%" )
118
+ . List ( ) ;
119
119
120
120
Assert . That ( aaItems . Count , Is . EqualTo ( 2 ) ) ;
121
121
}
0 commit comments