10
10
11
11
using System . Linq ;
12
12
using NHibernate . Criterion ;
13
+ using NHibernate . Linq ;
13
14
using NHibernate . Transform ;
15
+ using NHibernate . Type ;
14
16
using NUnit . Framework ;
15
- using NHibernate . Linq ;
16
17
17
18
namespace NHibernate . Test . NHSpecificTest . NH3787
18
19
{
19
20
using System . Threading . Tasks ;
20
21
[ TestFixture ]
21
22
public class TestFixtureAsync : BugTestCase
22
23
{
23
- private const decimal _testRate = 12345.123456789M ;
24
+ private const decimal _testRate = 12345.1234567890123M ;
25
+
26
+ protected override bool AppliesTo ( Dialect . Dialect dialect )
27
+ {
28
+ return ! TestDialect . HasBrokenDecimalType ;
29
+ }
24
30
25
31
protected override void OnSetUp ( )
26
32
{
@@ -33,7 +39,7 @@ protected override void OnSetUp()
33
39
{
34
40
UsePreviousRate = true ,
35
41
PreviousRate = _testRate ,
36
- Rate = 54321.123456789M
42
+ Rate = 54321.1234567890123M
37
43
} ;
38
44
s . Save ( testEntity ) ;
39
45
t . Commit ( ) ;
@@ -76,7 +82,7 @@ public async Task TestLinqProjectionAsync()
76
82
var queryResult = await ( ( from test in s . Query < TestEntity > ( )
77
83
select new RateDto { Rate = test . UsePreviousRate ? test . PreviousRate : test . Rate } ) . ToListAsync ( ) ) ;
78
84
79
- // Check it has not been truncated to the default 5 positions of NHibernate.
85
+ // Check it has not been truncated to the default scale (10) of NHibernate.
80
86
Assert . That ( queryResult [ 0 ] . Rate , Is . EqualTo ( _testRate ) ) ;
81
87
await ( t . CommitAsync ( ) ) ;
82
88
}
@@ -90,9 +96,11 @@ public async Task TestLinqQueryOnExpressionAsync()
90
96
{
91
97
var queryResult = await ( s
92
98
. Query < TestEntity > ( )
93
- . Where ( e => ( e . UsePreviousRate ? e . PreviousRate : e . Rate ) == _testRate )
99
+ . Where (
100
+ // Without MappedAs, the test fails for SQL Server because it would restrict its parameter to the dialect's default scale.
101
+ e => ( e . UsePreviousRate ? e . PreviousRate : e . Rate ) == _testRate . MappedAs ( TypeFactory . Basic ( "decimal(18,13)" ) ) )
94
102
. ToListAsync ( ) ) ;
95
-
103
+
96
104
Assert . That ( queryResult . Count , Is . EqualTo ( 1 ) ) ;
97
105
Assert . That ( queryResult [ 0 ] . PreviousRate , Is . EqualTo ( _testRate ) ) ;
98
106
await ( t . CommitAsync ( ) ) ;
@@ -113,13 +121,14 @@ public async Task TestQueryOverProjectionAsync()
113
121
var query = s
114
122
. QueryOver ( ( ) => testEntity )
115
123
. Select (
116
- Projections . Alias (
117
- Projections . Conditional (
118
- Restrictions . Eq ( Projections . Property ( ( ) => testEntity . UsePreviousRate ) , true ) ,
119
- Projections . Property ( ( ) => testEntity . PreviousRate ) ,
120
- Projections . Property ( ( ) => testEntity . Rate ) ) ,
121
- "Rate" )
122
- . WithAlias ( ( ) => rateDto . Rate ) ) ;
124
+ Projections
125
+ . Alias (
126
+ Projections . Conditional (
127
+ Restrictions . Eq ( Projections . Property ( ( ) => testEntity . UsePreviousRate ) , true ) ,
128
+ Projections . Property ( ( ) => testEntity . PreviousRate ) ,
129
+ Projections . Property ( ( ) => testEntity . Rate ) ) ,
130
+ "Rate" )
131
+ . WithAlias ( ( ) => rateDto . Rate ) ) ;
123
132
124
133
var queryResult = await ( query . TransformUsing ( Transformers . AliasToBean < RateDto > ( ) ) . ListAsync < RateDto > ( ) ) ;
125
134
0 commit comments