1111namespace SubSonic . Tests . DAL . ExtensionMethod
1212{
1313 using Extensions . Test ;
14+ using SubSonic . Extensions . Test . Models ;
1415
1516 [ TestFixture ]
1617 public class ExtensionMethodTests
@@ -24,10 +25,18 @@ protected override void SetSelectBehaviors()
2425 person_min = @"SELECT MIN([T1].[ID])
2526FROM [dbo].[Person] AS [T1]" ,
2627 person_max = @"SELECT MAX([T1].[ID])
27- FROM [dbo].[Person] AS [T1]" ;
28+ FROM [dbo].[Person] AS [T1]" ,
29+ renter_sum = @"SELECT SUM([T1].[Rent])
30+ FROM [dbo].[Renter] AS [T1]
31+ WHERE ([T1].[PersonID] = @personid_1)" ,
32+ renter_avg = @"SELECT AVG([T1].[Rent])
33+ FROM [dbo].[Renter] AS [T1]
34+ WHERE ([T1].[PersonID] = @personid_1)" ;
2835
2936 Context . Database . Instance . AddCommandBehavior ( person_max , cmd => People . Max ( x => x . ID ) ) ;
3037 Context . Database . Instance . AddCommandBehavior ( person_min , cmd => People . Min ( x => x . ID ) ) ;
38+ Context . Database . Instance . AddCommandBehavior ( renter_sum , cmd => Renters . Where ( x => x . PersonID == cmd . Parameters [ "@personid_1" ] . GetValue < int > ( ) ) . Sum ( x => x . Rent ) ) ;
39+ Context . Database . Instance . AddCommandBehavior ( renter_avg , cmd => Renters . Where ( x => x . PersonID == cmd . Parameters [ "@personid_1" ] . GetValue < int > ( ) ) . Average ( x => x . Rent ) ) ;
3140 }
3241
3342
@@ -54,5 +63,21 @@ public void TheMaxMethodIsSupported()
5463 {
5564 Context . People . Max ( x => x . ID ) . Should ( ) . Be ( People . Count ) ;
5665 }
66+
67+ [ Test ]
68+ public void TheSumMethodIsSupported ( )
69+ {
70+ Person person = Context . People . Single ( x => x . ID == 1 ) ;
71+
72+ person . Renters . Sum ( x => x . Rent ) . Should ( ) . Be ( Renters . Where ( x => x . PersonID == person . ID ) . Sum ( x => x . Rent ) ) ;
73+ }
74+
75+ [ Test ]
76+ public void TheAverageMethodIsSupported ( )
77+ {
78+ Person person = Context . People . Single ( x => x . ID == 1 ) ;
79+
80+ person . Renters . Average ( x => x . Rent ) . Should ( ) . Be ( Renters . Where ( x => x . PersonID == person . ID ) . Average ( x => x . Rent ) ) ;
81+ }
5782 }
5883}
0 commit comments