diff --git a/README.md b/README.md index 9016e72..dd0267d 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ![Nuget](https://img.shields.io/nuget/v/Xunit.Microsoft.DependencyInjection) ![Nuget](https://img.shields.io/nuget/dt/Xunit.Microsoft.DependencyInjection) -# Xunit Dependency Injection framework - .NET 9.0 +# Xunit Dependency Injection framework -Xunit does not support any built-in dependency injection features, therefore developers have to come up with a solution to recruit their favourite dependency injection framework in their tests. +Xunit does not support any built-in dependency injection features, therefore developers have had to come up with a solution to recruit their favourite dependency injection framework in their tests. -This library brings in Microsoft's dependency injection container to Xunit by leveraging Xunit's fixture. +This library brings Microsoft's dependency injection container to Xunit by leveraging Xunit's fixture. ## Getting started @@ -20,7 +20,7 @@ Install-Package Xunit.Microsoft.DependencyInjection ### Setup your fixture -The abstract class of `Xunit.Microsoft.DependencyInjection.Abstracts.TestBedFixture` contains the necessary functionalities to add services and configurations to Microsoft's dependency injection container. Your concrete test fixture class must derive from this abstract class and implement the following two abstract methods: +The abstract class of `Xunit.Microsoft.DependencyInjection.Abstracts.TestBedFixture` contains the necessary functionality to add services and configurations to Microsoft's dependency injection container. Your concrete test fixture class must derive from this abstract class and implement the following two abstract methods: ```csharp protected abstract IEnumerable GetConfigurationFiles(); @@ -52,7 +52,7 @@ To access async scopes simply call the following method in the abstract fixture public AsyncServiceScope GetAsyncScope(ITestOutputHelper testOutputHelper) ``` -### Accessing the keyed wired up services in .NET 8.0 +### Accessing the keyed wired up services in .NET 8.0+ You can call the following method to access the keyed already-wired up services: diff --git a/azure-pipeline-PR.yml b/azure-pipeline-PR.yml index 3abfb56..4672557 100644 --- a/azure-pipeline-PR.yml +++ b/azure-pipeline-PR.yml @@ -14,7 +14,7 @@ pool: steps: - script: echo Build Number $(name) - task: UseDotNet@2 - displayName: 'Use .NET 8.0 sdk' + displayName: 'Use .NET 9.0 sdk' inputs: packageType: sdk version: 9.0.100 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 42c2a91..1fd9c13 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -22,7 +22,7 @@ pool: steps: - script: echo Build Number $(name) - task: UseDotNet@2 - displayName: 'Use .NET 8.0 sdk' + displayName: 'Use .NET 9.0 sdk' inputs: packageType: sdk version: 9.0.100 diff --git a/src/Abstracts/TestBedFixture.cs b/src/Abstracts/TestBedFixture.cs index d687a70..3032c01 100644 --- a/src/Abstracts/TestBedFixture.cs +++ b/src/Abstracts/TestBedFixture.cs @@ -28,7 +28,7 @@ public ServiceProvider GetServiceProvider(ITestOutputHelper testOutputHelper) { return _serviceProvider; } - if(!_servicesAdded) + if (!_servicesAdded) { AddServices(_services, Configuration); _services.AddLogging(loggingBuilder => AddLoggingProvider(loggingBuilder, new OutputLoggerProvider(testOutputHelper))); @@ -54,8 +54,10 @@ public AsyncServiceScope GetAsyncScope(ITestOutputHelper testOutputHelper) public T? GetService(ITestOutputHelper testOutputHelper) => GetServiceProvider(testOutputHelper).GetService(); +#if NET8_0_OR_GREATER public T? GetKeyedService([DisallowNull] string key, ITestOutputHelper testOutputHelper) => GetServiceProvider(testOutputHelper).GetKeyedService(key); +#endif // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources // ~AbstractDependencyInjectionFixture() @@ -83,12 +85,15 @@ public async ValueTask DisposeAsync() } protected abstract void AddServices(IServiceCollection services, IConfiguration? configuration); + protected abstract IEnumerable GetTestAppSettings(); protected virtual ILoggingBuilder AddLoggingProvider(ILoggingBuilder loggingBuilder, ILoggerProvider loggerProvider) => loggingBuilder.AddProvider(loggerProvider); - protected virtual void AddUserSecrets(IConfigurationBuilder configurationBuilder) { } + protected virtual void AddUserSecrets(IConfigurationBuilder configurationBuilder) + { + } private IConfigurationRoot? GetConfigurationRoot() { @@ -130,4 +135,4 @@ protected virtual void Dispose(bool disposing) } protected abstract ValueTask DisposeAsyncCore(); -} +} \ No newline at end of file diff --git a/src/Xunit.Microsoft.DependencyInjection.csproj b/src/Xunit.Microsoft.DependencyInjection.csproj index daccdea..4963748 100644 --- a/src/Xunit.Microsoft.DependencyInjection.csproj +++ b/src/Xunit.Microsoft.DependencyInjection.csproj @@ -1,22 +1,56 @@  - net9.0 + net6.0;net7.0;net8.0;net9.0 latest enable enable README.md + True + Xunit.Microsoft.DependencyInjection + Microsoft Dependency Injection utility for Xunit + 9.0 + Arash Sabet + Umplify Technologies Inc. + ..\LICENSE + https://umplify.github.io/xunit-dependency-injection/ + http://umplify.com/wp-content/uploads/2017/11/umplify_logo.png + True + This package contains the necessary classes and features to leverage Xunit's fixture class for Microsoft dependency inection framework. + 2024 - All rights reserved, Umplify Technologies Inc. + xunit dependency-injection microsoft-dependency-injection xunit-dependency-injection + + + + + + + + 6 + + + + 7 + + + + 8 + + + + 9 + - - - - - - - + + + + + + + diff --git a/src/package.nuspec b/src/package.nuspec deleted file mode 100644 index 8d61f94..0000000 --- a/src/package.nuspec +++ /dev/null @@ -1,17 +0,0 @@ - - - - Xunit.Microsoft.DependencyInjection - Microsoft Dependency Injection utility for Xunit - 8.0 - Arash Sabet - Umplify Technologies Inc. - https://github.com/Umplify/xunit-dependency-injection/blob/main/LICENSE - https://umplify.github.io/xunit-dependency-injection/ - http://umplify.com/wp-content/uploads/2017/11/umplify_logo.png - true - This package contains the necessary classes and features to leverage Xunit's fixture class for Microsoft dependency inection framework. - 2024 - All rights reserved, Umplify Technologies Inc. - xunit dependency-injection microsoft-dependency-injection xunit-dependency-injection - -