@@ -520,6 +520,65 @@ public async Task CeilingAsync()
520
520
}
521
521
}
522
522
523
+ [ Test ]
524
+ public async Task RoundAsync ( )
525
+ {
526
+ AssumeFunctionSupported ( "round" ) ;
527
+
528
+ using ( var s = OpenSession ( ) )
529
+ {
530
+ var a1 = new Animal ( "a1" , 1.87f ) ;
531
+ await ( s . SaveAsync ( a1 ) ) ;
532
+ var m1 = new MaterialResource ( "m1" , "18" , MaterialResource . MaterialState . Available ) { Cost = 51.76m } ;
533
+ await ( s . SaveAsync ( m1 ) ) ;
534
+ await ( s . FlushAsync ( ) ) ;
535
+ }
536
+ using ( var s = OpenSession ( ) )
537
+ {
538
+ var roundF = await ( s . CreateQuery ( "select round(a.BodyWeight) from Animal a" ) . UniqueResultAsync < float > ( ) ) ;
539
+ Assert . That ( roundF , Is . EqualTo ( 2 ) , "Selecting round(double) failed." ) ;
540
+ var countF =
541
+ await ( s
542
+ . CreateQuery ( "select count(*) from Animal a where round(a.BodyWeight) = :c" )
543
+ . SetInt32 ( "c" , 2 )
544
+ . UniqueResultAsync < long > ( ) ) ;
545
+ Assert . That ( countF , Is . EqualTo ( 1 ) , "Filtering round(double) failed." ) ;
546
+
547
+ roundF = await ( s . CreateQuery ( "select round(a.BodyWeight, 1) from Animal a" ) . UniqueResultAsync < float > ( ) ) ;
548
+ Assert . That ( roundF , Is . EqualTo ( 1.9f ) . Within ( 0.01f ) , "Selecting round(double, 1) failed." ) ;
549
+ countF =
550
+ await ( s
551
+ . CreateQuery ( "select count(*) from Animal a where round(a.BodyWeight, 1) between :c1 and :c2" )
552
+ . SetDouble ( "c1" , 1.89 )
553
+ . SetDouble ( "c2" , 1.91 )
554
+ . UniqueResultAsync < long > ( ) ) ;
555
+ Assert . That ( countF , Is . EqualTo ( 1 ) , "Filtering round(double, 1) failed." ) ;
556
+
557
+ var roundD = await ( s . CreateQuery ( "select round(m.Cost) from MaterialResource m" ) . UniqueResultAsync < decimal ? > ( ) ) ;
558
+ Assert . That ( roundD , Is . EqualTo ( 52 ) , "Selecting round(decimal) failed." ) ;
559
+ var count =
560
+ await ( s
561
+ . CreateQuery ( "select count(*) from MaterialResource m where round(m.Cost) = :c" )
562
+ . SetInt32 ( "c" , 52 )
563
+ . UniqueResultAsync < long > ( ) ) ;
564
+ Assert . That ( count , Is . EqualTo ( 1 ) , "Filtering round(decimal) failed." ) ;
565
+
566
+ roundD = await ( s . CreateQuery ( "select round(m.Cost, 1) from MaterialResource m" ) . UniqueResultAsync < decimal ? > ( ) ) ;
567
+ Assert . That ( roundD , Is . EqualTo ( 51.8m ) , "Selecting round(decimal, 1) failed." ) ;
568
+
569
+ if ( TestDialect . HasBrokenDecimalType )
570
+ // SQLite fails the equality test due to using double instead, wich requires a tolerance.
571
+ return ;
572
+
573
+ count =
574
+ await ( s
575
+ . CreateQuery ( "select count(*) from MaterialResource m where round(m.Cost, 1) = :c" )
576
+ . SetDecimal ( "c" , 51.8m )
577
+ . UniqueResultAsync < long > ( ) ) ;
578
+ Assert . That ( count , Is . EqualTo ( 1 ) , "Filtering round(decimal, 1) failed." ) ;
579
+ }
580
+ }
581
+
523
582
[ Test ]
524
583
public async Task ModAsync ( )
525
584
{
0 commit comments