KamiSama.Testing.NSubstitute
10.0.11.9
dotnet add package KamiSama.Testing.NSubstitute --version 10.0.11.9
NuGet\Install-Package KamiSama.Testing.NSubstitute -Version 10.0.11.9
<PackageReference Include="KamiSama.Testing.NSubstitute" Version="10.0.11.9" />
<PackageVersion Include="KamiSama.Testing.NSubstitute" Version="10.0.11.9" />
<PackageReference Include="KamiSama.Testing.NSubstitute" />
paket add KamiSama.Testing.NSubstitute --version 10.0.11.9
#r "nuget: KamiSama.Testing.NSubstitute, 10.0.11.9"
#:package KamiSama.Testing.NSubstitute@10.0.11.9
#addin nuget:?package=KamiSama.Testing.NSubstitute&version=10.0.11.9
#tool nuget:?package=KamiSama.Testing.NSubstitute&version=10.0.11.9
KamiSama.Testing.NSubstitute
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
- KamiSama.Testing.NSubstitute (1 types)
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 | Versions 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.11)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.11)
- MSTest.TestAdapter (>= 4.3.3)
- NSubstitute (>= 6.2.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 |
|---|---|---|
| 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 |