ConfigDirector.ServerSdk.AspNetCore.Testing 1.7.1

dotnet add package ConfigDirector.ServerSdk.AspNetCore.Testing --version 1.7.1
                    
NuGet\Install-Package ConfigDirector.ServerSdk.AspNetCore.Testing -Version 1.7.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="ConfigDirector.ServerSdk.AspNetCore.Testing" Version="1.7.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConfigDirector.ServerSdk.AspNetCore.Testing" Version="1.7.1" />
                    
Directory.Packages.props
<PackageReference Include="ConfigDirector.ServerSdk.AspNetCore.Testing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConfigDirector.ServerSdk.AspNetCore.Testing --version 1.7.1
                    
#r "nuget: ConfigDirector.ServerSdk.AspNetCore.Testing, 1.7.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.
#:package ConfigDirector.ServerSdk.AspNetCore.Testing@1.7.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConfigDirector.ServerSdk.AspNetCore.Testing&version=1.7.1
                    
Install as a Cake Addin
#tool nuget:?package=ConfigDirector.ServerSdk.AspNetCore.Testing&version=1.7.1
                    
Install as a Cake Tool

ConfigDirector ASP.NET Core Testing

Registers a ConfigDirector test client with an ASP.NET Core application under test, published to NuGet as ConfigDirector.ServerSdk.AspNetCore.Testing. It targets net8.0.

An application wired up with ConfigDirector.ServerSdk.AspNetCore builds its client from configuration and connects during startup. This package replaces that client with the test client's, so the application starts without an SDK key, opens no connection, and reads the values the test seeds.

Installation

The package is released together with ConfigDirector.ServerSdk.Testing and the SDK, at the same version, and brings the testing package along.

dotnet add package ConfigDirector.ServerSdk.AspNetCore.Testing

Test your application

using ConfigDirector.Testing;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;

await using var testClient = ConfigDirectorTesting.CreateTestClient(
    new Dictionary<string, object> { ["new-checkout"] = true });
using var factory = new WebApplicationFactory<Program>().WithWebHostBuilder(host =>
    host.ConfigureTestServices(services => services.AddConfigDirectorTestClient(testClient)));
using var http = factory.CreateClient();

(await http.GetStringAsync("/checkout")).ShouldBe("new");

testClient.SetValue("new-checkout", false);
(await http.GetStringAsync("/checkout")).ShouldBe("classic");

AddConfigDirectorTestClient(testClient):

  • Removes every IConfigDirectorClient registration already in the collection and registers testClient.Client as an instance. It therefore works from ConfigureTestServices, which runs after the application's own AddConfigDirector. The container never disposes an instance registration; the test owns the test client and disposes it.
  • Supplies a placeholder SDK key when none is configured, so the startup validation of the key passes whatever the order of registrations. A configured key is left alone.
  • Leaves the application's startup initialization in place, so the host calls InitializeAsync as in production. With no hold or failure armed, it completes at once with the stored values. With FailInitialization and RequireReadyOnStartup, host startup throws ConfigDirectorConnectionException, as it would in production.
  • With HoldInitialization, host startup waits until CompleteInitialization or the client's timeout. WebApplicationFactory.CreateClient() blocks on host startup, so call CompleteInitialization from another task.

Because the test client is built outside the container, it does not see the application's configuration: ConfigDirector:Connection:Timeout, the host's ILoggerFactory, and the AppName and AppVersion metadata. Pass the timeout and logger factory to CreateTestClient through TestClientOptions.

A factory shared across tests

A WebApplicationFactory shared by a test class through IClassFixture shares one test client across its tests. Keep the test client with the factory, register it once, and call ReplaceValues in each test's setup: it resets the values and disarms any armed hold or failure.

public sealed class CheckoutTests : IClassFixture<CheckoutTests.Factory>
{
    private readonly Factory _factory;

    public CheckoutTests(Factory factory)
    {
        _factory = factory;
        _factory.TestClient.ReplaceValues(new Dictionary<string, object> { ["new-checkout"] = true });
    }

    public sealed class Factory : WebApplicationFactory<Program>
    {
        public TestClient TestClient { get; } = ConfigDirectorTesting.CreateTestClient();

        protected override void ConfigureWebHost(IWebHostBuilder builder) =>
            builder.ConfigureTestServices(services => services.AddConfigDirectorTestClient(TestClient));

        public override async ValueTask DisposeAsync()
        {
            await base.DisposeAsync();
            await TestClient.DisposeAsync();
        }
    }
}

Documentation

Full details are in the official documentation.

What changed in each release is in the changelog.

Getting Help

Reach out to us via https://www.configdirector.com/support

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.7.1 66 10/6/2026
1.7.0 78 10/5/2026
1.6.0 82 10/1/2026