@@ -14,6 +14,7 @@ protected TestBedFixture()
1414 {
1515 _services = new ServiceCollection ( ) ;
1616 ConfigurationBuilder = new ConfigurationBuilder ( ) . SetBasePath ( Directory . GetCurrentDirectory ( ) ) ;
17+ AddUserSecrets ( ConfigurationBuilder ) ;
1718 Configuration = GetConfigurationRoot ( ) ;
1819 _servicesAdded = false ;
1920 }
@@ -30,9 +31,10 @@ public ServiceProvider GetServiceProvider(ITestOutputHelper testOutputHelper)
3031 if ( ! _servicesAdded )
3132 {
3233 AddServices ( _services , Configuration ) ;
34+ _services . AddLogging ( loggingBuilder => AddLoggingProvider ( loggingBuilder , new OutputLoggerProvider ( testOutputHelper ) ) ) ;
35+ _services . AddOptions ( ) ;
3336 _servicesAdded = true ;
3437 }
35- _services . AddLogging ( loggingBuilder => AddLoggingProvider ( loggingBuilder , new OutputLoggerProvider ( testOutputHelper ) ) ) ;
3638 return _serviceProvider = _services . BuildServiceProvider ( ) ;
3739 }
3840
@@ -55,12 +57,38 @@ public AsyncServiceScope GetAsyncScope(ITestOutputHelper testOutputHelper)
5557 public T ? GetKeyedService < T > ( [ DisallowNull ] string key , ITestOutputHelper testOutputHelper )
5658 => GetServiceProvider ( testOutputHelper ) . GetKeyedService < T > ( key ) ;
5759
60+ // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
61+ // ~AbstractDependencyInjectionFixture()
62+ // {
63+ // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
64+ // Dispose(disposing: false);
65+ // }
66+
67+ public void Dispose ( )
68+ {
69+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
70+ Dispose ( disposing : true ) ;
71+ GC . SuppressFinalize ( this ) ;
72+ }
73+
74+ public async ValueTask DisposeAsync ( )
75+ {
76+ if ( ! _disposedAsync )
77+ {
78+ await DisposeAsyncCore ( ) ;
79+ Dispose ( ) ;
80+ _disposedAsync = true ;
81+ }
82+ }
83+
5884 protected abstract void AddServices ( IServiceCollection services , IConfiguration ? configuration ) ;
5985 protected abstract IEnumerable < TestAppSettings > GetTestAppSettings ( ) ;
6086
6187 protected virtual ILoggingBuilder AddLoggingProvider ( ILoggingBuilder loggingBuilder , ILoggerProvider loggerProvider )
6288 => loggingBuilder . AddProvider ( loggerProvider ) ;
6389
90+ protected virtual void AddUserSecrets ( IConfigurationBuilder configurationBuilder ) { }
91+
6492 private IConfigurationRoot ? GetConfigurationRoot ( )
6593 {
6694 var testAppSettings = GetTestAppSettings ( ) ;
@@ -100,29 +128,5 @@ protected virtual void Dispose(bool disposing)
100128 }
101129 }
102130
103- // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
104- // ~AbstractDependencyInjectionFixture()
105- // {
106- // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
107- // Dispose(disposing: false);
108- // }
109-
110- public void Dispose ( )
111- {
112- // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
113- Dispose ( disposing : true ) ;
114- GC . SuppressFinalize ( this ) ;
115- }
116-
117- public async ValueTask DisposeAsync ( )
118- {
119- if ( ! _disposedAsync )
120- {
121- await DisposeAsyncCore ( ) ;
122- Dispose ( ) ;
123- _disposedAsync = true ;
124- }
125- }
126-
127131 protected abstract ValueTask DisposeAsyncCore ( ) ;
128132}
0 commit comments