@@ -549,6 +549,123 @@ public void GroupByComputedValueInObjectArray()
549549 Assert . AreEqual ( 830 , orderGroups . Sum ( g => g . Count ) ) ;
550550 }
551551
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+
592+ private int constKey ;
593+ [ Test ( Description = "NH-3474" ) ]
594+ public void GroupByKeyWithConstantFromVariable ( )
595+ {
596+ constKey = 1 ;
597+ var q1 = db . Orders . GroupBy ( o => constKey ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
598+ var q1a = db . Orders . GroupBy ( o => "" ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
599+ var q2 = db . Orders . GroupBy ( o => new { A = constKey } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
600+ var q3 = db . Orders . GroupBy ( o => new object [ ] { constKey } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
601+ var q3a = db . Orders . GroupBy ( o => ( IEnumerable < object > ) new object [ ] { constKey } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
602+ var q4 = db . Orders . GroupBy ( o => new { A = constKey , B = o . Shipper . ShipperId } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
603+ var q5 = db . Orders . GroupBy ( o => new [ ] { constKey , o . Shipper . ShipperId } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
604+ var q5a = db . Orders . GroupBy ( o => ( IEnumerable < int > ) new [ ] { constKey , o . Shipper . ShipperId } ) . Select ( g => new { Key = g . Key , Count = g . Count ( ) , Sum = g . Sum ( x => x . Freight ) } ) ;
605+
606+ var r1_1 = q1 . ToList ( ) ;
607+ Assert . That ( r1_1 . Count , Is . EqualTo ( 1 ) ) ;
608+ Assert . That ( r1_1 , Has . All . With . Property ( "Key" ) . EqualTo ( 1 ) ) ;
609+
610+ var r1a_1 = q1a . ToList ( ) ;
611+ Assert . That ( r1a_1 . Count , Is . EqualTo ( 1 ) ) ;
612+ Assert . That ( r1a_1 , Has . All . With . Property ( "Key" ) . EqualTo ( "" ) ) ;
613+
614+ var r2_1 = q2 . ToList ( ) ;
615+ Assert . That ( r2_1 . Count , Is . EqualTo ( 1 ) ) ;
616+ Assert . That ( r2_1 , Has . All . With . Property ( "Key" ) . With . Property ( "A" ) . EqualTo ( 1 ) ) ;
617+
618+ var r3_1 = q3 . ToList ( ) ;
619+ Assert . That ( r3_1 . Count , Is . EqualTo ( 1 ) ) ;
620+ Assert . That ( r3_1 , Has . All . With . Property ( "Key" ) . EquivalentTo ( new object [ ] { 1 } ) ) ;
621+
622+ var r3a_1 = q3a . ToList ( ) ;
623+ Assert . That ( r3a_1 . Count , Is . EqualTo ( 1 ) ) ;
624+ Assert . That ( r3a_1 , Has . All . With . Property ( "Key" ) . EquivalentTo ( new object [ ] { 1 } ) ) ;
625+
626+ var r4_1 = q4 . ToList ( ) ;
627+ Assert . That ( r4_1 . Count , Is . EqualTo ( 3 ) ) ;
628+ Assert . That ( r4_1 , Has . All . With . Property ( "Key" ) . With . Property ( "A" ) . EqualTo ( 1 ) ) ;
629+
630+ var r5_1 = q5 . ToList ( ) ;
631+ Assert . That ( r5_1 . Count , Is . EqualTo ( 3 ) ) ;
632+ Assert . That ( r5_1 , Has . All . With . Property ( "Key" ) . Contains ( 1 ) ) ;
633+
634+ var r6_1 = q5a . ToList ( ) ;
635+ Assert . That ( r6_1 . Count , Is . EqualTo ( 3 ) ) ;
636+ Assert . That ( r6_1 , Has . All . With . Property ( "Key" ) . Contains ( 1 ) ) ;
637+
638+ constKey = 2 ;
639+
640+ var r1_2 = q1 . ToList ( ) ;
641+ Assert . That ( r1_2 . Count , Is . EqualTo ( 1 ) ) ;
642+ Assert . That ( r1_2 , Has . All . With . Property ( "Key" ) . EqualTo ( 2 ) ) ;
643+
644+ var r2_2 = q2 . ToList ( ) ;
645+ Assert . That ( r2_2 . Count , Is . EqualTo ( 1 ) ) ;
646+ Assert . That ( r2_2 , Has . All . With . Property ( "Key" ) . With . Property ( "A" ) . EqualTo ( 2 ) ) ;
647+
648+ var r3_2 = q3 . ToList ( ) ;
649+ Assert . That ( r3_2 . Count , Is . EqualTo ( 1 ) ) ;
650+ Assert . That ( r3_2 , Has . All . With . Property ( "Key" ) . EquivalentTo ( new object [ ] { 2 } ) ) ;
651+
652+ var r3a_2 = q3a . ToList ( ) ;
653+ Assert . That ( r3a_2 . Count , Is . EqualTo ( 1 ) ) ;
654+ Assert . That ( r3a_2 , Has . All . With . Property ( "Key" ) . EquivalentTo ( new object [ ] { 2 } ) ) ;
655+
656+ var r4_2 = q4 . ToList ( ) ;
657+ Assert . That ( r4_2 . Count , Is . EqualTo ( 3 ) ) ;
658+ Assert . That ( r4_2 , Has . All . With . Property ( "Key" ) . With . Property ( "A" ) . EqualTo ( 2 ) ) ;
659+
660+ var r5_2 = q5 . ToList ( ) ;
661+ Assert . That ( r5_2 . Count , Is . EqualTo ( 3 ) ) ;
662+ Assert . That ( r5_2 , Has . All . With . Property ( "Key" ) . Contains ( 2 ) ) ;
663+
664+ var r6_2 = q5 . ToList ( ) ;
665+ Assert . That ( r6_2 . Count , Is . EqualTo ( 3 ) ) ;
666+ Assert . That ( r6_2 , Has . All . With . Property ( "Key" ) . Contains ( 2 ) ) ;
667+ }
668+
552669 [ Test ( Description = "NH-3801" ) ]
553670 public void GroupByComputedValueWithJoinOnObject ( )
554671 {
0 commit comments