Rystem.Test.XUnit 6.0.21

dotnet add package Rystem.Test.XUnit --version 6.0.21
NuGet\Install-Package Rystem.Test.XUnit -Version 6.0.21
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rystem.Test.XUnit" Version="6.0.21" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rystem.Test.XUnit --version 6.0.21
#r "nuget: Rystem.Test.XUnit, 6.0.21"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rystem.Test.XUnit as a Cake Addin
#addin nuget:?package=Rystem.Test.XUnit&version=6.0.21

// Install Rystem.Test.XUnit as a Cake Tool
#tool nuget:?package=Rystem.Test.XUnit&version=6.0.21

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 Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
6.0.21 46 6/18/2024
6.0.20 80,594 6/16/2024
6.0.19 30,323 6/14/2024
6.0.18 70 6/14/2024
6.0.17 66 6/14/2024
6.0.16 49,918 6/10/2024
6.0.15 66 6/10/2024