1010
1111using System . Linq ;
1212using NHibernate . Criterion ;
13+ using NHibernate . Linq ;
1314using NHibernate . Transform ;
15+ using NHibernate . Type ;
1416using NUnit . Framework ;
15- using NHibernate . Linq ;
1617
1718namespace NHibernate . Test . NHSpecificTest . NH3787
1819{
1920 using System . Threading . Tasks ;
2021 [ TestFixture ]
2122 public class TestFixtureAsync : BugTestCase
2223 {
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+ }
2430
2531 protected override void OnSetUp ( )
2632 {
@@ -33,7 +39,7 @@ protected override void OnSetUp()
3339 {
3440 UsePreviousRate = true ,
3541 PreviousRate = _testRate ,
36- Rate = 54321.123456789M
42+ Rate = 54321.1234567890123M
3743 } ;
3844 s . Save ( testEntity ) ;
3945 t . Commit ( ) ;
@@ -76,7 +82,7 @@ public async Task TestLinqProjectionAsync()
7682 var queryResult = await ( ( from test in s . Query < TestEntity > ( )
7783 select new RateDto { Rate = test . UsePreviousRate ? test . PreviousRate : test . Rate } ) . ToListAsync ( ) ) ;
7884
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.
8086 Assert . That ( queryResult [ 0 ] . Rate , Is . EqualTo ( _testRate ) ) ;
8187 await ( t . CommitAsync ( ) ) ;
8288 }
@@ -90,9 +96,11 @@ public async Task TestLinqQueryOnExpressionAsync()
9096 {
9197 var queryResult = await ( s
9298 . 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)" ) ) )
94102 . ToListAsync ( ) ) ;
95-
103+
96104 Assert . That ( queryResult . Count , Is . EqualTo ( 1 ) ) ;
97105 Assert . That ( queryResult [ 0 ] . PreviousRate , Is . EqualTo ( _testRate ) ) ;
98106 await ( t . CommitAsync ( ) ) ;
@@ -113,13 +121,14 @@ public async Task TestQueryOverProjectionAsync()
113121 var query = s
114122 . QueryOver ( ( ) => testEntity )
115123 . 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 ) ) ;
123132
124133 var queryResult = await ( query . TransformUsing ( Transformers . AliasToBean < RateDto > ( ) ) . ListAsync < RateDto > ( ) ) ;
125134
0 commit comments