@@ -5,30 +5,27 @@ namespace Xunit.Microsoft.DependencyInjection.ExampleTests;
55
66public class CalculatorTests : TestBed < CalculatorFixture >
77{
8- private readonly ICalculator _calculator ;
98 private readonly Options _options ;
109
1110 public CalculatorTests ( ITestOutputHelper testOutputHelper , CalculatorFixture fixture )
12- : base ( testOutputHelper , fixture )
13- {
14- _calculator = _fixture . GetService < ICalculator > ( _testOutputHelper ) ! ;
15- _options = _fixture . GetService < IOptions < Options > > ( _testOutputHelper ) ! . Value ;
16- }
11+ : base ( testOutputHelper , fixture ) => _options = _fixture . GetService < IOptions < Options > > ( _testOutputHelper ) ! . Value ;
1712
1813 [ Theory ]
1914 [ InlineData ( 1 , 2 ) ]
20- public async Task Test1Async ( int x , int y )
15+ public async Task TestServiceAsync ( int x , int y )
2116 {
22- var calculatedValue = await _calculator . AddAsync ( x , y ) ;
17+ var calculator = _fixture . GetService < ICalculator > ( _testOutputHelper ) ! ;
18+ var calculatedValue = await calculator . AddAsync ( x , y ) ;
2319 var expected = _options . Rate * ( x + y ) ;
2420 Assert . True ( expected == calculatedValue ) ;
2521 }
2622
2723 [ Theory ]
2824 [ InlineData ( 1 , 2 ) ]
29- public async Task Test2Async ( int x , int y )
25+ public async Task TestScopedServiceAsync ( int x , int y )
3026 {
31- var calculatedValue = await _calculator . AddAsync ( x , y ) ;
27+ var calculator = _fixture . GetScopedService < ICalculator > ( _testOutputHelper ) ! ;
28+ var calculatedValue = await calculator . AddAsync ( x , y ) ;
3229 var expected = _options . Rate * ( x + y ) ;
3330 Assert . True ( expected == calculatedValue ) ;
3431 }
0 commit comments