@@ -31,23 +31,26 @@ public void Injection()
3131 }
3232 }
3333
34- [ TestMethod , ExpectedException ( typeof ( InvalidOperationException ) ) ]
34+ [ TestMethod ]
3535 public void NoServiceAdapter_InjectionError ( )
3636 {
37- var expectedValue = MapContext . Current . GetService < IMockService > ( ) . GetName ( ) ;
38- var config = ConfigureMapping ( expectedValue ) ;
37+ Should . Throw < InvalidOperationException > ( ( ) =>
38+ {
39+ var expectedValue = MapContext . Current . GetService < IMockService > ( ) . GetName ( ) ;
40+ var config = ConfigureMapping ( expectedValue ) ;
3941
40- IServiceCollection sc = new ServiceCollection ( ) ;
41- sc . AddScoped < IMockService , MockService > ( ) ;
42- sc . AddSingleton ( config ) ;
43- // We should use ServiceMapper in normal code
44- // but for this test we want to be sure the code will generate the InvalidOperationException
45- sc . AddScoped < IMapper , Mapper > ( ) ;
42+ IServiceCollection sc = new ServiceCollection ( ) ;
43+ sc . AddScoped < IMockService , MockService > ( ) ;
44+ sc . AddSingleton ( config ) ;
45+ // We should use ServiceMapper in normal code
46+ // but for this test we want to be sure the code will generate the InvalidOperationException
47+ sc . AddScoped < IMapper , Mapper > ( ) ;
4648
47- var sp = sc . BuildServiceProvider ( ) ;
48- using var scope = sp . CreateScope ( ) ;
49- var mapper = scope . ServiceProvider . GetService < IMapper > ( ) ;
50- MapToDto ( mapper , expectedValue ) ;
49+ var sp = sc . BuildServiceProvider ( ) ;
50+ using var scope = sp . CreateScope ( ) ;
51+ var mapper = scope . ServiceProvider . GetService < IMapper > ( ) ;
52+ MapToDto ( mapper , expectedValue ) ;
53+ } ) ;
5154 }
5255
5356 private static TypeAdapterConfig ConfigureMapping ( string expectedValue )
@@ -103,4 +106,4 @@ public class Dto
103106 public string Id { get ; set ; }
104107 public string Name { get ; set ; }
105108 }
106- }
109+ }
0 commit comments