Rystem.Test.XUnit
9.0.0-rc.1
See the version list below for details.
dotnet add package Rystem.Test.XUnit --version 9.0.0-rc.1
NuGet\Install-Package Rystem.Test.XUnit -Version 9.0.0-rc.1
<PackageReference Include="Rystem.Test.XUnit" Version="9.0.0-rc.1" />
paket add Rystem.Test.XUnit --version 9.0.0-rc.1
#r "nuget: Rystem.Test.XUnit, 9.0.0-rc.1"
// Install Rystem.Test.XUnit as a Cake Addin #addin nuget:?package=Rystem.Test.XUnit&version=9.0.0-rc.1&prerelease // Install Rystem.Test.XUnit as a Cake Tool #tool nuget:?package=Rystem.Test.XUnit&version=9.0.0-rc.1&prerelease
What is Rystem?
Get Started with Rystem XUnitTest helpers
You have to add a startup class in your test project to initialize the Rystem XUnit helpers.
public class Startup : StartupHelper
{
protected override string? AppSettingsFileName => "appsettings.test.json";
protected override bool HasTestHost => true;
protected override Type? TypeToChooseTheRightAssemblyToRetrieveSecretsForConfiguration => typeof(Startup);
protected override Type? TypeToChooseTheRightAssemblyWithControllersToMap => typeof(ServiceController);
protected override IServiceCollection ConfigureCientServices(IServiceCollection services)
{
services.AddHttpClient("client", x =>
{
x.BaseAddress = new Uri("http://localhost");
});
return services;
}
protected override ValueTask ConfigureServerMiddlewaresAsync(IApplicationBuilder applicationBuilder, IServiceProvider serviceProvider)
{
applicationBuilder.UseTestApplication();
return ValueTask.CompletedTask;
}
protected override ValueTask ConfigureServerServicesAsync(IServiceCollection services, IConfiguration configuration)
{
services.AddTestServices();
return ValueTask.CompletedTask;
}
}
TypeToChooseTheRightAssemblyToRetrieveSecretsForConfiguration
This property is the Type to discover the right assembly to retrieve secrets.\
TypeToChooseTheRightAssemblyWithControllersToMap
This property is the Type to discover the right assembly to map controllers automatically.\
AppSettingsFileName
This property is the name of the appsettings file to load the configuration.
HasTestHost
This property allows the Test server to start. You have to override ConfigureServerMiddlewaresAsync and ConfigureServerServicesAsync.
applicationBuilder.UseTestApplication() is an example of your middlewares from your api project.
public static IApplicationBuilder UseTestApplication(this IApplicationBuilder app)
{
app.UseRuntimeServiceProvider();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(x =>
{
x.MapControllers();
});
return app;
}
and with the same behavior services.AddTestServices(); adds the services from your api project.
public static IServiceCollection AddTestServices(this IServiceCollection services)
{
services.AddRuntimeServiceProvider();
services.AddControllers();
services.AddEndpointsApiExplorer();
services.AddSingleton<SingletonService>();
services.AddSingleton<Singleton2Service>();
services.AddScoped<ScopedService>();
services.AddScoped<Scoped2Service>();
services.AddTransient<TransientService>();
services.AddTransient<Transient2Service>();
return services;
}
ConfigureCientServices
This method configure the DI in your XUnit test project. Usually you need to inject the http client to test your api if you need the test server.
services.AddHttpClient("client", x =>
{
x.BaseAddress = new Uri("http://localhost");
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- Microsoft.AspNetCore.TestHost (>= 9.0.0-rc.2.24474.3)
- Microsoft.NET.Test.Sdk (>= 17.11.1)
- Rystem.Concurrency (>= 9.0.0-rc.1)
- Rystem.DependencyInjection.Web (>= 9.0.0-rc.1)
- xunit (>= 2.9.2)
- Xunit.DependencyInjection (>= 9.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 2,522 | 11/16/2024 |
9.0.0-rc.1 | 76 | 10/18/2024 |
6.2.0 | 218,934 | 10/9/2024 |
6.1.1 | 86 | 10/9/2024 |
6.1.0 | 47,828 | 9/29/2024 |
6.0.24 | 111 | 9/11/2024 |
6.0.23 | 340,067 | 7/18/2024 |
6.0.21 | 108 | 6/18/2024 |
6.0.20 | 727,676 | 6/16/2024 |
6.0.19 | 30,352 | 6/14/2024 |
6.0.18 | 104 | 6/14/2024 |
6.0.17 | 100 | 6/14/2024 |
6.0.16 | 49,950 | 6/10/2024 |
6.0.15 | 98 | 6/10/2024 |