@@ -55,6 +55,14 @@ public async Task ShouldBeAbleToGetSingleAsync()
5555 person . ID . Should ( ) . Be ( 1 ) ;
5656 }
5757
58+ [ Test ]
59+ public async Task ShouldBeAbleToGetSingleAsyncWithPredicate ( )
60+ {
61+ Person person = await Context . People . SingleAsync ( x => x . ID == 1 ) ;
62+
63+ person . ID . Should ( ) . Be ( 1 ) ;
64+ }
65+
5866 [ Test ]
5967 public void ShouldBeAbleToThrowWhenSingleAsyncHasMoreThanOne ( )
6068 {
@@ -63,7 +71,44 @@ public void ShouldBeAbleToThrowWhenSingleAsyncHasMoreThanOne()
6371 await Context . People . Where ( x => x . ID > 0 )
6472 . AsAsyncEnumerable ( )
6573 . SingleAsync ( ) ;
66- } ) . Should ( ) . Throw < InvalidOperationException > ( ) ;
74+ } ) . Should ( )
75+ . Throw < InvalidOperationException > ( )
76+ . WithMessage ( SubSonicErrorMessages . MethodFoundMoreThanOneResult . Format ( nameof ( SubSonicAsyncQueryable . SingleAsync ) ) ) ; ;
77+ }
78+
79+ [ Test ]
80+ public void ShouldBeAbleToThrowWhenSingleOrDefaultAsyncHasMoreThanOne ( )
81+ {
82+ FluentActions . Invoking ( async ( ) =>
83+ {
84+ await Context . People . Where ( x => x . ID > 0 )
85+ . AsAsyncEnumerable ( )
86+ . SingleOrDefaultAsync ( ) ;
87+ } ) . Should ( )
88+ . Throw < InvalidOperationException > ( )
89+ . WithMessage ( SubSonicErrorMessages . MethodFoundMoreThanOneResult . Format ( nameof ( SubSonicAsyncQueryable . SingleOrDefaultAsync ) ) ) ; ;
90+ }
91+
92+ [ Test ]
93+ public void ShouldBeAbleToThrowWhenSingleAsyncHasMoreThanOneWithPredicate ( )
94+ {
95+ FluentActions . Invoking ( async ( ) =>
96+ {
97+ await Context . People . SingleAsync ( x => x . ID > 0 ) ;
98+ } ) . Should ( )
99+ . Throw < InvalidOperationException > ( )
100+ . WithMessage ( SubSonicErrorMessages . MethodFoundMoreThanOneResult . Format ( nameof ( SubSonicAsyncQueryable . SingleAsync ) ) ) ; ;
101+ }
102+
103+ [ Test ]
104+ public void ShouldBeAbleToThrowWhenSingleOrDefaultAsyncHasMoreThanOneWithPredicate ( )
105+ {
106+ FluentActions . Invoking ( async ( ) =>
107+ {
108+ await Context . People . SingleOrDefaultAsync ( x => x . ID > 0 ) ;
109+ } ) . Should ( )
110+ . Throw < InvalidOperationException > ( )
111+ . WithMessage ( SubSonicErrorMessages . MethodFoundMoreThanOneResult . Format ( nameof ( SubSonicAsyncQueryable . SingleOrDefaultAsync ) ) ) ; ;
67112 }
68113
69114 [ Test ]
@@ -74,7 +119,20 @@ public void ShouldBeAbleToThrowSingleAsyncOnNull()
74119 await Context . People . Where ( x => x . ID == - 1 )
75120 . AsAsyncEnumerable ( )
76121 . SingleAsync ( ) ;
77- } ) . Should ( ) . Throw < InvalidOperationException > ( ) ;
122+ } ) . Should ( )
123+ . Throw < InvalidOperationException > ( )
124+ . WithMessage ( SubSonicErrorMessages . MethodDoesNotAllowNullValue . Format ( nameof ( SubSonicAsyncQueryable . SingleAsync ) ) ) ;
125+ }
126+
127+ [ Test ]
128+ public void ShouldBeAbleToThrowSingleAsyncOnNullWithPredicate ( )
129+ {
130+ FluentActions . Invoking ( async ( ) =>
131+ {
132+ await Context . People . SingleAsync ( x => x . ID == - 1 ) ;
133+ } ) . Should ( )
134+ . Throw < InvalidOperationException > ( )
135+ . WithMessage ( SubSonicErrorMessages . MethodDoesNotAllowNullValue . Format ( nameof ( SubSonicAsyncQueryable . SingleAsync ) ) ) ;
78136 }
79137
80138 [ Test ]
@@ -87,6 +145,14 @@ public async Task ShouldBeAbleToGetSingleOrDefaultAsync()
87145 person . ID . Should ( ) . Be ( 1 ) ;
88146 }
89147
148+ [ Test ]
149+ public async Task ShouldBeAbleToGetSingleOrDefaultAsyncWithPredicate ( )
150+ {
151+ Person person = await Context . People . SingleOrDefaultAsync ( x => x . ID == 1 ) ;
152+
153+ person . ID . Should ( ) . Be ( 1 ) ;
154+ }
155+
90156 [ Test ]
91157 public void ShouldBeAbleToNotThrowSingleOrDefaultAsyncOnNull ( )
92158 {
@@ -101,6 +167,18 @@ public void ShouldBeAbleToNotThrowSingleOrDefaultAsyncOnNull()
101167 } ) . Should ( ) . NotThrow ( ) ;
102168 }
103169
170+ [ Test ]
171+ public void ShouldBeAbleToNotThrowSingleOrDefaultAsyncOnNullWithPredicate ( )
172+ {
173+ FluentActions . Invoking ( async ( ) =>
174+ {
175+ Person person = await Context . People . SingleOrDefaultAsync ( x => x . ID == - 1 ) ;
176+
177+ person . Should ( ) . BeNull ( ) ;
178+
179+ } ) . Should ( ) . NotThrow ( ) ;
180+ }
181+
104182 [ Test ]
105183 public async Task ShouldBeAbleToGetFirstAsync ( )
106184 {
@@ -111,6 +189,14 @@ public async Task ShouldBeAbleToGetFirstAsync()
111189 person . ID . Should ( ) . Be ( 1 ) ;
112190 }
113191
192+ [ Test ]
193+ public async Task ShouldBeAbleToGetFirstAsyncWithPredicate ( )
194+ {
195+ Person person = await Context . People . FirstAsync ( x => x . ID > 0 ) ;
196+
197+ person . ID . Should ( ) . Be ( 1 ) ;
198+ }
199+
114200 [ Test ]
115201 public void ShouldBeAbleToThrowFirstAsyncOnNull ( )
116202 {
@@ -119,7 +205,21 @@ public void ShouldBeAbleToThrowFirstAsyncOnNull()
119205 await Context . People . Where ( x => x . ID < 1 )
120206 . AsAsyncEnumerable ( )
121207 . FirstAsync ( ) ;
122- } ) . Should ( ) . Throw < InvalidOperationException > ( ) ;
208+ } )
209+ . Should ( )
210+ . Throw < InvalidOperationException > ( )
211+ . WithMessage ( SubSonicErrorMessages . MethodDoesNotAllowNullValue . Format ( nameof ( SubSonicAsyncQueryable . FirstAsync ) ) ) ;
212+ }
213+
214+ [ Test ]
215+ public void ShouldBeAbleToThrowFirstAsyncOnNullWithPredicate ( )
216+ {
217+ FluentActions . Invoking ( async ( ) =>
218+ {
219+ await Context . People . FirstAsync ( x => x . ID < 1 ) ;
220+ } ) . Should ( )
221+ . Throw < InvalidOperationException > ( )
222+ . WithMessage ( SubSonicErrorMessages . MethodDoesNotAllowNullValue . Format ( nameof ( SubSonicAsyncQueryable . FirstAsync ) ) ) ; ;
123223 }
124224
125225 [ Test ]
@@ -133,13 +233,19 @@ public async Task ShouldBeAbleToGetFirstOrDefaultAsync()
133233 }
134234
135235 [ Test ]
136- public void ShouldBeAbleToNotThrowFirstOrDefaultAsyncOnNull ( )
236+ public async Task ShouldBeAbleToGetFirstOrDefaultAsyncWithPredicate ( )
237+ {
238+ Person person = await Context . People . FirstOrDefaultAsync ( x => x . ID > 2 ) ;
239+
240+ person . ID . Should ( ) . Be ( 3 ) ;
241+ }
242+
243+ [ Test ]
244+ public void ShouldBeAbleToNotThrowFirstOrDefaultAsyncOnNullWithPredicate ( )
137245 {
138246 FluentActions . Invoking ( async ( ) =>
139247 {
140- Person person = await Context . People . Where ( x => x . ID < 1 )
141- . AsAsyncEnumerable ( )
142- . FirstOrDefaultAsync ( ) ;
248+ Person person = await Context . People . FirstOrDefaultAsync ( x => x . ID < 1 ) ;
143249
144250 person . Should ( ) . BeNull ( ) ;
145251
@@ -153,12 +259,11 @@ public void ShouldBeAbleToLoadResultSet()
153259 {
154260 var cts = new CancellationTokenSource ( ) ;
155261
156- var people = await Context . People
157- . AsAsyncEnumerable ( )
158- . LoadAsync ( cts . Token ) ;
159-
160262 int cnt = 0 ;
161263
264+ #if NETCOREAPP2_2 || NETCOREAPP2_1 || NETCOREAPP2_0
265+ var people = await Context . People . LoadAsync ( cts . Token ) ;
266+
162267 await foreach ( Person person in people
163268 . WithCancellation ( cts . Token )
164269 . ConfigureAwait ( true ) )
@@ -169,6 +274,16 @@ public void ShouldBeAbleToLoadResultSet()
169274
170275 cnt ++ ;
171276 }
277+ #elif NETCOREAPP3_0 || NETCOREAPP3_1
278+ await foreach ( var person in Context . People . LoadAsync ( cts . Token ) )
279+ {
280+ person . FullName . Should ( ) . Be ( String . Format ( "{0}, {1}{2}" ,
281+ person . FamilyName , person . FirstName ,
282+ string . IsNullOrEmpty ( person . MiddleInitial ? . Trim ( ) ) ? "" : $ " { person . MiddleInitial } .") ) ;
283+
284+ cnt ++ ;
285+ }
286+ #endif
172287
173288 cnt . Should ( ) . Be ( Context . People . Count ( ) ) ;
174289
0 commit comments