Skip to content

About

xunit test extensions

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

268 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SWalter.Testing

License: MIT Target: .NET 10.0

Testing utilities, AutoFixture extensions, custom assertions, and AwesomeAssertions extensions for .NET and Microsoft.Extensions.DependencyInjection.


πŸ“ˆ Quality & Activity

Branch Status & Activity
Main CodeFactor Commit Activity Main Last Commit Main
Develop CodeFactor Commit Activity Develop Last Commit Develop

πŸ“¦ Packages in this Repository

Package Description Sources
SWalter.Testing AutoFixture custom data attributes, GuardClause assertions, and DI assertion extensions. MyGet Codeberg

πŸš€ Package Feeds

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

Add Feed via .NET CLI

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>

πŸ“₯ Installation

Install any package via dotnet add package:

Standard Release

dotnet add package SWalter.Testing

Preview Builds

dotnet add package SWalter.Testing --prerelease

πŸ’‘ Features & Usage

AutoFixture Attributes

NSubstituteOmitAutoPropertiesTrueAutoDataAttribute

A 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
}

NSubstituteOmitAutoPropertiesTrueInlineAutoDataAttribute

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
}

Guard Clause Assertions

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));
}

Assertions for Microsoft.Extensions.DependencyInjection

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();

About

xunit test extensions

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages