10
10
11
11
using NHibernate . Cfg . MappingSchema ;
12
12
using NHibernate . Criterion ;
13
+ using NHibernate . Dialect ;
13
14
using NHibernate . Mapping . ByCode ;
14
15
using NUnit . Framework ;
15
16
16
17
namespace NHibernate . Test . NHSpecificTest . GH1180
17
18
{
18
19
using System . Threading . Tasks ;
19
- [ KnownBug ( " NH-3847 (GH-1180)" ) ]
20
+ // NH-3847
20
21
[ TestFixture ]
21
22
public class ByCodeFixtureAsync : TestCaseMappingByCode
22
23
{
@@ -27,7 +28,7 @@ protected override HbmMapping GetMappings()
27
28
mapper . Class < Entity > ( rc =>
28
29
{
29
30
rc . Id ( x => x . Id , m => m . Generator ( Generators . GuidComb ) ) ;
30
- rc . Property ( x => x . Name , m => { m . Length ( 10 ) ; } ) ;
31
+ rc . Property ( x => x . Name , m => { m . Type ( NHibernateUtil . AnsiString ) ; m . Length ( 5 ) ; } ) ;
31
32
rc . Property ( x => x . Amount , m => { m . Precision ( 8 ) ; m . Scale ( 2 ) ; } ) ;
32
33
} ) ;
33
34
@@ -47,6 +48,12 @@ protected override void OnTearDown()
47
48
[ Test ]
48
49
public async Task StringTypesAsync ( )
49
50
{
51
+ var whenFalse =
52
+ Dialect is Oracle8iDialect
53
+ //Most dialects allow to return DbType.String and DbType.AnsiString in case statement
54
+ //But Oracle throws 'ORA-12704: character set mismatch'
55
+ ? Projections . Constant ( "otherstring" , NHibernateUtil . AnsiString )
56
+ : Projections . Constant ( "otherstring" ) ;
50
57
using ( var session = OpenSession ( ) )
51
58
using ( var transaction = session . BeginTransaction ( ) )
52
59
{
@@ -58,88 +65,92 @@ public async Task StringTypesAsync()
58
65
await ( transaction . CommitAsync ( ) ) ;
59
66
}
60
67
61
- // whenTrue is constant, whenFalse is property -> works even before the fix
68
+ // whenTrue is constant, whenFalse is property
62
69
using ( var session = OpenSession ( ) )
63
70
{
64
71
ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
65
72
66
73
var conditionalProjection = Projections . Conditional (
67
74
Restrictions . Not (
68
75
Restrictions . Like ( nameof ( Entity . Name ) , "B%" ) ) ,
69
- Projections . Constant ( "other" ) ,
76
+ //Property - ansi string length 5; contstant - string, length 10
77
+ whenFalse ,
70
78
Projections . Property ( nameof ( Entity . Name ) ) ) ;
71
79
tagCriteria . SetProjection ( conditionalProjection ) ;
72
80
73
81
// run query
74
82
var results = await ( tagCriteria . ListAsync ( ) ) ;
75
83
76
- Assert . That ( results , Is . EquivalentTo ( new [ ] { "other " , "Beta" , "other " } ) ) ;
84
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { "otherstring " , "Beta" , "otherstring " } ) ) ;
77
85
}
78
86
79
- // whenTrue is property, whenFalse is constant -> fails before the fix
87
+ // whenTrue is property, whenFalse is constant
80
88
using ( var session = OpenSession ( ) )
81
89
{
82
90
ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
83
91
84
92
var conditionalProjection = Projections . Conditional (
85
93
Restrictions . Like ( nameof ( Entity . Name ) , "B%" ) ,
86
94
Projections . Property ( nameof ( Entity . Name ) ) ,
87
- Projections . Constant ( "other" ) ) ;
95
+ whenFalse ) ;
88
96
tagCriteria . SetProjection ( conditionalProjection ) ;
89
97
90
98
// run query
91
99
var results = await ( tagCriteria . ListAsync ( ) ) ;
92
100
93
- Assert . That ( results , Is . EquivalentTo ( new [ ] { "other " , "Beta" , "other " } ) ) ;
101
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { "otherstring " , "Beta" , "otherstring " } ) ) ;
94
102
}
95
103
}
96
104
97
105
[ Test ]
98
106
public async Task DecimalTypesAsync ( )
99
107
{
108
+ //On some dialects (SQLite) Scale mapping is ignored
109
+ var propertyResult = TestDialect . HasBrokenDecimalType ? 42.131m : 42.13m ;
100
110
using ( var session = OpenSession ( ) )
101
111
using ( var transaction = session . BeginTransaction ( ) )
102
112
{
103
- await ( session . SaveAsync ( new Entity { Amount = 3.14m } ) ) ;
104
- await ( session . SaveAsync ( new Entity { Amount = 42.13m } ) ) ;
105
- await ( session . SaveAsync ( new Entity { Amount = 17.99m } ) ) ;
113
+ await ( session . SaveAsync ( new Entity { Amount = 3.141m } ) ) ;
114
+ await ( session . SaveAsync ( new Entity { Amount = 42.131m } ) ) ;
115
+ await ( session . SaveAsync ( new Entity { Amount = 17.991m } ) ) ;
106
116
107
117
await ( transaction . CommitAsync ( ) ) ;
108
118
}
109
119
110
- // whenTrue is constant, whenFalse is property -> works even before the fix
120
+ // whenTrue is constant, whenFalse is property
111
121
using ( var session = OpenSession ( ) )
112
122
{
113
123
ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
114
124
115
125
var conditionalProjection = Projections . Conditional (
116
126
Restrictions . Not (
117
127
Restrictions . Ge ( nameof ( Entity . Amount ) , 20m ) ) ,
118
- Projections . Constant ( 20m ) ,
128
+ //Property scale is 2, make sure constant scale 3 is not lost
129
+ Projections . Constant ( 20.123m ) ,
119
130
Projections . Property ( nameof ( Entity . Amount ) ) ) ;
120
131
tagCriteria . SetProjection ( conditionalProjection ) ;
121
132
122
133
// run query
123
134
var results = await ( tagCriteria . ListAsync ( ) ) ;
124
135
125
- Assert . That ( results , Is . EquivalentTo ( new [ ] { 20m , 42.13m , 20m } ) ) ;
136
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { 20.123m , propertyResult , 20.123m } ) ) ;
126
137
}
127
138
128
- // whenTrue is property, whenFalse is constant -> fails before the fix
139
+ // whenTrue is property, whenFalse is constant
129
140
using ( var session = OpenSession ( ) )
130
141
{
131
142
ICriteria tagCriteria = session . CreateCriteria ( typeof ( Entity ) ) ;
132
143
133
144
var conditionalProjection = Projections . Conditional (
134
145
Restrictions . Ge ( nameof ( Entity . Amount ) , 20m ) ,
135
146
Projections . Property ( nameof ( Entity . Amount ) ) ,
136
- Projections . Constant ( 20m ) ) ;
147
+ Projections . Constant ( 20.123m ) ) ;
137
148
tagCriteria . SetProjection ( conditionalProjection ) ;
138
149
139
150
// run query
140
151
var results = await ( tagCriteria . ListAsync ( ) ) ;
141
152
142
- Assert . That ( results , Is . EquivalentTo ( new [ ] { 20m , 42.13m , 20m } ) ) ;
153
+ Assert . That ( results , Is . EquivalentTo ( new [ ] { 20.123m , propertyResult , 20.123m } ) ) ;
143
154
}
144
155
}
145
156
}
0 commit comments