Testing utilities, AutoFixture extensions, custom assertions, and AwesomeAssertions extensions for .NET and Microsoft.Extensions.DependencyInjection.
| Branch | Status & Activity |
|---|---|
| Package | Description | Sources |
|---|---|---|
SWalter.Testing |
AutoFixture custom data attributes, GuardClause assertions, and DI assertion extensions. |
All packages (Release and Preview builds) are published to MyGet and Codeberg. You only need to configure one of these feeds.
| Registry | Feed URL |
|---|---|
| MyGet | https://www.myget.org/F/swalterlabs/api/v3/index.json |
| Codeberg | https://codeberg.org/api/packages/evilbaschdi/nuget/index.json |
Choose either MyGet or Codeberg:
# Option A: MyGet (recommended)
dotnet nuget add source https://www.myget.org/F/swalterlabs/api/v3/index.json -n "SWalter Labs"
# Option B: Codeberg
dotnet nuget add source https://codeberg.org/api/packages/evilbaschdi/nuget/index.json -n "EvilBaschdi Codeberg"Sample NuGet.Config with Package Source Mapping
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="SWalter Labs" value="https://www.myget.org/F/swalterlabs/api/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="SWalter Labs">
<package pattern="SWalter.*" />
</packageSource>
</packageSourceMapping>
</configuration>Install any package via dotnet add package:
dotnet add package SWalter.Testingdotnet add package SWalter.Testing --prereleaseA custom xUnit [Theory] attribute combining AutoFixture's AutoDataAttribute with NSubstitute automatic mocking and OmitAutoProperties = true.
using SWalter.Testing;
using Xunit;
[Theory, NSubstituteOmitAutoPropertiesTrueAutoData]
public void MyTest(IMyService service, MyDependency dependency)
{
// service and dependency are automatically created and injected
// properties are not auto-populated - configure them as needed
}Combines InlineAutoDataAttribute with NSubstitute automatic mocking and OmitAutoProperties = true.
using SWalter.Testing;
using Xunit;
[Theory]
[NSubstituteOmitAutoPropertiesTrueInlineAutoData("value1", 42)]
public void MyTest(string inlineValue, int inlineNumber, IMyService service)
{
// inlineValue and inlineNumber come from the attribute parameters
// service is automatically created by the fixture
}Verifies that public asynchronous methods on a type have proper null guards for reference parameters:
using SWalter.Testing.Extensions;
using AutoFixture.Xunit3;
[Theory, NSubstituteOmitAutoPropertiesTrueAutoData]
public void VerifyAllAsyncMethodsHaveNullGuards(GuardClauseAssertion assertion)
{
assertion.VerifyTask<MyAsyncService>(
typeof(MyAsyncService).GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance));
}Assert service registrations with lifetime and implementation validations:
using SWalter.Testing;
using AwesomeAssertions;
using Microsoft.Extensions.DependencyInjection;
using SWalter.Testing.Assertions.Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddSingleton<ISomeService, SomeService>();
services.AddTransient<ITransient, Transient>();
services.AddScoped<IScoped, Scoped>();
// Assert registration, implementation, and lifetime
services.Should()
.HaveService<ISomeService>()
.WithImplementation<SomeService>()
.AsSingleton();