GnomeStack.Xunit.Core 0.1.0

dotnet add package GnomeStack.Xunit.Core --version 0.1.0
NuGet\Install-Package GnomeStack.Xunit.Core -Version 0.1.0
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="GnomeStack.Xunit.Core" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GnomeStack.Xunit.Core --version 0.1.0
#r "nuget: GnomeStack.Xunit.Core, 0.1.0"
#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.
// Install GnomeStack.Xunit.Core as a Cake Addin
#addin nuget:?package=GnomeStack.Xunit.Core&version=0.1.0

// Install GnomeStack.Xunit.Core as a Cake Tool
#tool nuget:?package=GnomeStack.Xunit.Core&version=0.1.0

GnomeStack.Xunit.Core

Provides dependency injection for Xunit test class constructors and test methods that use attributes from GnomeStack.Xunit.Attributes.

To enable DI, the Xunit.GnomeStackTestFramework must be added to your test assembly so that Xunit knows which test framework is responsible for test execution.

The attribute may be added through a csproj file using the following:

<ItemGroup>
    <AssemblyAttribute Include="Xunit.GnomeStackTestFramework" />
</ItemGroup>

The package comes with its own simple dependency injector that wires up an IAssert instance and ITestOutputHelper. The benefits of using IAssert is adding extension methods.

[UnitTest]
public void Verify_TestDependencyInjection_ForTestOutputHelper(
    IAssert assert, 
    ITestOutputHelper writer)
{
        writer.WriteLine("Console output!");
        const int h = 0, i = 18;
        assert.NotEqual(h, i);
}

A test class or a test case may use the UseServiceProviderFactoryAttribute to replace the built in simple dependency injector with its own implementation. The attribute requires an type that implements ITestServiceProviderFactory and it must return an object that implements IServiceProvider.

internal class DIFactoryA : ITestServiceProviderFactory
{
    public IServiceProvider CreateServiceProvider()
    {
        // SimpleServiceProvider auto adds IAssert and ITestOutputHelper
        var services = new SimpleServiceProvider();
        services.AddTransient(typeof(ICustomService), _ => new MyCustomService());

        return services;
    }
}

public class MyTest
{
    [UnitTest]
    [UseServiceProviderFactory(typeof(DIFactoryA))]
    public void Verify_TestDependencyInjection_CustomFactory(
        IAssert assert, 
        ICustomService myService)
    {
        assert.NotNull(myService);
        assert.Equal("My", myService.Name);
    }
}

These ideas are not new and come from other existing projects like Xunit Skippable Fact & dotnet arcade. Huge shoutout to Xunit for enabling extension points.

MIT License (project).

Apache License (code from Xunit).

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.1.0 463 10/15/2023
0.0.0-build.14 66 10/15/2023
0.0.0-build.13 60 10/15/2023
0.0.0-build.1 54 10/15/2023
0.0.0-build 79 10/15/2023

# CHANGE LOG

## 0.1.0 initial creation

- created.