Rystem.Test.XUnit 6.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rystem.Test.XUnit --version 6.1.1                
NuGet\Install-Package Rystem.Test.XUnit -Version 6.1.1                
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.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rystem.Test.XUnit --version 6.1.1                
#r "nuget: Rystem.Test.XUnit, 6.1.1"                
#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.1.1

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

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
9.0.1 78 11/23/2024
9.0.0 54,027 11/16/2024
9.0.0-rc.1 78 10/18/2024
6.2.0 218,940 10/9/2024
6.1.1 92 10/9/2024
6.1.0 47,832 9/29/2024
6.0.24 115 9/11/2024
6.0.23 340,070 7/18/2024
6.0.21 112 6/18/2024
6.0.20 727,680 6/16/2024
6.0.19 30,356 6/14/2024
6.0.18 108 6/14/2024
6.0.17 104 6/14/2024
6.0.16 49,954 6/10/2024
6.0.15 102 6/10/2024