Solidus.Test 0.1.0

dotnet add package Solidus.Test --version 0.1.0
                    
NuGet\Install-Package Solidus.Test -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="Solidus.Test" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Solidus.Test" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Solidus.Test" />
                    
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 Solidus.Test --version 0.1.0
                    
#r "nuget: Solidus.Test, 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.
#:package Solidus.Test@0.1.0
                    
#: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=Solidus.Test&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Solidus.Test&version=0.1.0
                    
Install as a Cake Tool

Solidus.Test

Build and Test NuGet Version

The test base package that covers common test project boilerplate.

Setup test project

  • Reference NuGet package

    dotnet add package Solidus.Test
    
  • Add global usings for convenience

    global using Solidus.Test;
    

Environment Variables usage example

.\.github\workflows\dotnet.yml

...
    - name: Test
      env:
        TEST_HOUSE_NAME: ${{ secrets.TEST_HOUSE_NAME }}
        TEST_HOUSE_CONFIGURATION: ${{ vars.TEST_HOUSE_CONFIGURATION }}
      run: dotnet test --no-build --verbosity normal
...

.\UnitTests\HouseTest.cs

public class HouseTest : TestBase
{
    [Test]
    public void HappyPath()
    {
        // Arrange.
        var houseConfiguration = env.ReadJsonFromEnvironmentVariable<HouseConfiguration>("TEST_HOUSE_CONFIGURATION");
        var sut = new House();
        sut.Name = env.ReadEnvironmentVariable("TEST_HOUSE_NAME");
        sut.RoomCount = houseConfiguration.RoomCount;

        // Act/Assert.
        ...
    }
}

Mother Factory usage example

.\MotherFactory\PersonMotherFactory.cs

public static class PersonMotherFactory
{
    public static object CreatePerson(this MotherFactory mf, ISpecialty specialty = null, IEmployment employment = null)
    {
        specialty ??= Mock.Of<ISpecialty>();
        employment ??= Mock.Of<IEmployment>();
        return new(
            specialty: specialty,
            employment: employment);
    }
}

.\UnitTests\HouseEnterTests.cs

public class HouseEnterTests : TestBase
{
    [Test]
    public void PersonEntersHouse_HousePersonsContainPerson()
    {
        // Arrange.
        var sut = new House();
        var person = mf.CreatePerson();

        // Act.
        sut.Enter(person);

        // Assert.
        sut.Person.Should().Contain(person);
    }
}

Test Data Generator usage example

By default Test Data Generator will use AutoFixture to create test data value.

AutoFixture it's a third-party project. Repository located at: https://github.com/AutoFixture/AutoFixture

Simple code snippet that demonstrates a basic string data initialization, that avoids use of magic strings and abstracts test from unnecessary explicit data specification:

public class PersonTest : TestBase
{
    [Test]
    public void SetName_NameChanged()
    {
        // Arrange.
        var sut = new Person();
        sut.Name = gen.Create<string>();

        var expected = gen.Create<string>();

        // Act.
        sut.Name = expected;

        // Assert.
        sut.Name.Should().Be(expected);
    }
}

To change default Test Data Generator over all tests call

    DefaultTestDataGenerator.SetDefaultTestDataGenerator(() => ...);

To change Test Data Generator for specific test class

public class SomeTest : TestBase
{
    protected override ITestDataGenerator CreateTestDataGenerator()
    {
        return ...
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
0.1.0 546 2/24/2024