@@ -261,8 +261,10 @@ public async Task Exception_not_thrown_for_more_than_one_row_returned_for_single
261
261
Assert . Equal ( 42 , entry [ entry . EntityType . FindProperty ( "Id" ) ] ) ;
262
262
}
263
263
264
- [ ConditionalFact ]
265
- public async Task Exception_thrown_if_rows_returned_for_command_without_store_generated_values_is_not_1 ( )
264
+ [ ConditionalTheory ]
265
+ [ InlineData ( false ) ]
266
+ [ InlineData ( true ) ]
267
+ public async Task Exception_thrown_if_rows_returned_for_command_without_store_generated_values_is_not_1 ( bool async )
266
268
{
267
269
var entry = CreateEntry ( EntityState . Added ) ;
268
270
@@ -276,14 +278,17 @@ public async Task Exception_thrown_if_rows_returned_for_command_without_store_ge
276
278
var batch = new ModificationCommandBatchFake ( ) ;
277
279
batch . AddCommand ( command ) ;
278
280
279
- Assert . Equal (
280
- RelationalStrings . UpdateConcurrencyException ( 1 , 42 ) ,
281
- ( await Assert . ThrowsAsync < DbUpdateConcurrencyException > (
282
- async ( ) => await batch . ExecuteAsync ( connection ) ) ) . Message ) ;
281
+ var exception = async
282
+ ? await Assert . ThrowsAsync < DbUpdateConcurrencyException > ( ( ) => batch . ExecuteAsync ( connection ) )
283
+ : Assert . Throws < DbUpdateConcurrencyException > ( ( ) => batch . Execute ( connection ) ) ;
284
+
285
+ Assert . Equal ( RelationalStrings . UpdateConcurrencyException ( 1 , 42 ) , exception . Message ) ;
283
286
}
284
287
285
- [ ConditionalFact ]
286
- public async Task Exception_thrown_if_no_rows_returned_for_command_with_store_generated_values ( )
288
+ [ ConditionalTheory ]
289
+ [ InlineData ( false ) ]
290
+ [ InlineData ( true ) ]
291
+ public async Task Exception_thrown_if_no_rows_returned_for_command_with_store_generated_values ( bool async )
287
292
{
288
293
var entry = CreateEntry ( EntityState . Added , generateKeyValues : true ) ;
289
294
entry . SetTemporaryValue ( entry . EntityType . FindPrimaryKey ( ) . Properties [ 0 ] , - 1 ) ;
@@ -297,10 +302,65 @@ public async Task Exception_thrown_if_no_rows_returned_for_command_with_store_ge
297
302
var batch = new ModificationCommandBatchFake ( ) ;
298
303
batch . AddCommand ( command ) ;
299
304
300
- Assert . Equal (
301
- RelationalStrings . UpdateConcurrencyException ( 1 , 0 ) ,
302
- ( await Assert . ThrowsAsync < DbUpdateConcurrencyException > (
303
- async ( ) => await batch . ExecuteAsync ( connection ) ) ) . Message ) ;
305
+ var exception = async
306
+ ? await Assert . ThrowsAsync < DbUpdateConcurrencyException > ( ( ) => batch . ExecuteAsync ( connection ) )
307
+ : Assert . Throws < DbUpdateConcurrencyException > ( ( ) => batch . Execute ( connection ) ) ;
308
+
309
+ Assert . Equal ( RelationalStrings . UpdateConcurrencyException ( 1 , 0 ) , exception . Message ) ;
310
+ }
311
+
312
+ [ ConditionalTheory ]
313
+ [ InlineData ( false ) ]
314
+ [ InlineData ( true ) ]
315
+ public async Task DbException_is_wrapped_with_DbUpdateException ( bool async )
316
+ {
317
+ var entry = CreateEntry ( EntityState . Added , generateKeyValues : true ) ;
318
+
319
+ var command = CreateModificationCommand ( "T1" , null , new ParameterNameGenerator ( ) . GenerateNext , true , null ) ;
320
+ command . AddEntry ( entry , true ) ;
321
+
322
+ var originalException = new FakeDbException ( ) ;
323
+
324
+ var connection = CreateConnection (
325
+ new FakeCommandExecutor (
326
+ executeReaderAsync : ( c , b , ct ) => throw originalException ,
327
+ executeReader : ( c , b ) => throw originalException ) ) ;
328
+
329
+ var batch = new ModificationCommandBatchFake ( ) ;
330
+ batch . AddCommand ( command ) ;
331
+
332
+ var actualException = async
333
+ ? await Assert . ThrowsAsync < DbUpdateException > ( ( ) => batch . ExecuteAsync ( connection ) )
334
+ : Assert . Throws < DbUpdateException > ( ( ) => batch . Execute ( connection ) ) ;
335
+
336
+ Assert . Same ( originalException , actualException . InnerException ) ;
337
+ }
338
+
339
+ [ ConditionalTheory ]
340
+ [ InlineData ( false ) ]
341
+ [ InlineData ( true ) ]
342
+ public async Task OperationCanceledException_is_not_wrapped_with_DbUpdateException ( bool async )
343
+ {
344
+ var entry = CreateEntry ( EntityState . Added , generateKeyValues : true ) ;
345
+
346
+ var command = CreateModificationCommand ( "T1" , null , new ParameterNameGenerator ( ) . GenerateNext , true , null ) ;
347
+ command . AddEntry ( entry , true ) ;
348
+
349
+ var originalException = new OperationCanceledException ( ) ;
350
+
351
+ var connection = CreateConnection (
352
+ new FakeCommandExecutor (
353
+ executeReaderAsync : ( c , b , ct ) => throw originalException ,
354
+ executeReader : ( c , b ) => throw originalException ) ) ;
355
+
356
+ var batch = new ModificationCommandBatchFake ( ) ;
357
+ batch . AddCommand ( command ) ;
358
+
359
+ var actualException = async
360
+ ? await Assert . ThrowsAsync < OperationCanceledException > ( ( ) => batch . ExecuteAsync ( connection ) )
361
+ : Assert . Throws < OperationCanceledException > ( ( ) => batch . Execute ( connection ) ) ;
362
+
363
+ Assert . Same ( originalException , actualException ) ;
304
364
}
305
365
306
366
[ ConditionalFact ]
@@ -605,21 +665,18 @@ private class FakeDbContext : DbContext
605
665
606
666
private const string ConnectionString = "Fake Connection String" ;
607
667
668
+ private static FakeRelationalConnection CreateConnection ( FakeCommandExecutor executor )
669
+ => CreateConnection (
670
+ CreateOptions (
671
+ new FakeRelationalOptionsExtension ( ) . WithConnection (
672
+ new FakeDbConnection ( ConnectionString , executor ) ) ) ) ;
673
+
608
674
private static FakeRelationalConnection CreateConnection ( DbDataReader dbDataReader )
609
- {
610
- var fakeDbConnection = new FakeDbConnection (
611
- ConnectionString ,
675
+ => CreateConnection (
612
676
new FakeCommandExecutor (
613
677
executeReaderAsync : ( c , b , ct ) => Task . FromResult ( dbDataReader ) ,
614
678
executeReader : ( c , b ) => dbDataReader ) ) ;
615
679
616
- var optionsExtension = new FakeRelationalOptionsExtension ( ) . WithConnection ( fakeDbConnection ) ;
617
-
618
- var options = CreateOptions ( optionsExtension ) ;
619
-
620
- return CreateConnection ( options ) ;
621
- }
622
-
623
680
private static FakeRelationalConnection CreateConnection ( IDbContextOptions options = null )
624
681
=> new ( options ?? CreateOptions ( ) ) ;
625
682
0 commit comments