KamiSama.Testing.NSubstitute 10.0.11.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package KamiSama.Testing.NSubstitute --version 10.0.11.1
                    
NuGet\Install-Package KamiSama.Testing.NSubstitute -Version 10.0.11.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="KamiSama.Testing.NSubstitute" Version="10.0.11.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KamiSama.Testing.NSubstitute" Version="10.0.11.1" />
                    
Directory.Packages.props
<PackageReference Include="KamiSama.Testing.NSubstitute" />
                    
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 KamiSama.Testing.NSubstitute --version 10.0.11.1
                    
#r "nuget: KamiSama.Testing.NSubstitute, 10.0.11.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 KamiSama.Testing.NSubstitute@10.0.11.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=KamiSama.Testing.NSubstitute&version=10.0.11.1
                    
Install as a Cake Addin
#tool nuget:?package=KamiSama.Testing.NSubstitute&version=10.0.11.1
                    
Install as a Cake Tool

KamiSama.Testing.NSubstitute

Back to package index

Version: 10.0.0

Description

A DI-first test builder that registers configured substitutes and creates NSubstitute doubles for missing constructor dependencies. Use it to build focused service tests through a scoped Microsoft.Extensions.DependencyInjection container.

How to use

dotnet add package KamiSama.Testing.NSubstitute --version 10.0.0

Derive a scenario-specific builder, expose configured substitutes, build the target once, and resolve generated dependencies from the resulting scope:

using KamiSama.Testing.NSubstitute;
using NSubstitute;

public sealed class ProductServiceTestsBuilder : TesterBuilderBase
{
    public IProductRepository Repository { get; };

    public ProductServiceTestsBuilder()
    {
        Repository = AddScoped<IProductRepository>();
        AddOption<ProductOptions>(options => options.PageSize = 20);
    }

    public ProductService Build() => BuildService<ProductService>();
}

var builder = new ProductServiceTestsBuilder();
builder.Repository.Find(42).Returns(new Product(42, "Keyboard"));
ProductService service = builder.Build();
ILogger<ProductService> logger = builder.For<ILogger<ProductService>>();

BuildService<TService> inspects only the first public constructor returned by reflection and substitutes only unresolved parameters from that constructor. NSubstitute still requires proxyable interfaces or classes with overridable members. AddScoped and AddTransient capture one substitute, so their registrations do not create fresh doubles per scope or resolution. Registrations accumulate across builds. The builder does not dispose its temporary providers or scopes, its final provider, replaced scopes, or scoped/transient disposables; keep builders short-lived and do not use this helper when disposal verification matters. Call For<T> only after a successful build.

Namespaces

Types

  • KamiSama.Testing.NSubstitute.TesterBuilderBase - Builds a target service in a DI scope and substitutes unresolved parameters from the first public constructor. Registrations accumulate, captured substitutes do not follow normal scoped or transient instance semantics, and created providers and scopes are not disposed.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
10.0.11.9 81 8/24/2026
10.0.11.8 79 8/22/2026
10.0.11.7 85 8/21/2026
10.0.11.6 91 8/19/2026
10.0.11.5 75 8/18/2026
10.0.11.4 91 8/18/2026
10.0.11.3 81 8/18/2026
10.0.11.2 86 8/18/2026
10.0.11.1 92 8/15/2026
10.0.11 95 8/11/2026
10.0.10.2 100 8/4/2026
10.0.10.1 108 7/31/2026
10.0.10 103 7/30/2026
10.0.9 115 6/20/2026
10.0.7 121 5/1/2026
10.0.6 119 4/16/2026
10.0.1 248 11/26/2025
10.0.0 256 11/22/2025
3.1.6 237 11/7/2025
3.1.5 237 11/6/2025
Loading failed