@@ -549,6 +549,46 @@ public void GroupByComputedValueInObjectArray()
549
549
Assert . AreEqual ( 830 , orderGroups . Sum ( g => g . Count ) ) ;
550
550
}
551
551
552
+ [ Test ( Description = "NH-3474" ) ]
553
+ public void GroupByConstant ( )
554
+ {
555
+ var totals = db . Orders . GroupBy ( o => 1 ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) . ToList ( ) ;
556
+ Assert . That ( totals . Count , Is . EqualTo ( 1 ) ) ;
557
+ Assert . That ( totals , Has . All . With . Property ( "Key" ) . EqualTo ( 1 ) ) ;
558
+ }
559
+
560
+ [ Test ( Description = "NH-3474" ) ]
561
+ public void GroupByConstantAnonymousType ( )
562
+ {
563
+ var totals = db . Orders . GroupBy ( o => new { A = 1 } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) . ToList ( ) ;
564
+ Assert . That ( totals . Count , Is . EqualTo ( 1 ) ) ;
565
+ Assert . That ( totals , Has . All . With . Property ( "Key" ) . With . Property ( "A" ) . EqualTo ( 1 ) ) ;
566
+ }
567
+
568
+ [ Test ( Description = "NH-3474" ) ]
569
+ public void GroupByConstantArray ( )
570
+ {
571
+ var totals = db . Orders . GroupBy ( o => new object [ ] { 1 } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) . ToList ( ) ;
572
+ Assert . That ( totals . Count , Is . EqualTo ( 1 ) ) ;
573
+ Assert . That ( totals , Has . All . With . Property ( "Key" ) . EqualTo ( new object [ ] { 1 } ) ) ;
574
+ }
575
+
576
+ [ Test ( Description = "NH-3474" ) ]
577
+ public void GroupByKeyWithConstantInAnonymousType ( )
578
+ {
579
+ var totals = db . Orders . GroupBy ( o => new { A = 1 , B = o . Shipper . ShipperId } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) . ToList ( ) ;
580
+ Assert . That ( totals . Count , Is . EqualTo ( 3 ) ) ;
581
+ Assert . That ( totals , Has . All . With . Property ( "Key" ) . With . Property ( "A" ) . EqualTo ( 1 ) ) ;
582
+ }
583
+
584
+ [ Test ( Description = "NH-3474" ) ]
585
+ public void GroupByKeyWithConstantInArray ( )
586
+ {
587
+ var totals = db . Orders . GroupBy ( o => new [ ] { 1 , o . Shipper . ShipperId } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) . ToList ( ) ;
588
+ Assert . That ( totals . Count , Is . EqualTo ( 3 ) ) ;
589
+ Assert . That ( totals , Has . All . With . Property ( "Key" ) . Contains ( 1 ) ) ;
590
+ }
591
+
552
592
private static void CheckGrouping < TKey , TElement > ( IEnumerable < IGrouping < TKey , TElement > > groupedItems , Func < TElement , TKey > groupBy )
553
593
{
554
594
var used = new HashSet < object > ( ) ;
0 commit comments