elideus-dot-net-framework-tests 2.1.0

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

Elideus | DotNet Framework Tests

Tests is a subpackage of the Elideus-DotNet-Framework, and it sets up the boilerplate for testing a project developed with the framework.


Setup

To start, create a builder that implements the ElideusDotNetFrameworkTestsBuilder:

[assembly: AssemblyFixture(typeof(MyAppTestsBuilder))]
namespace MyApp.Tests
{
    public class MyAppTestsBuilder : ElideusDotNetFrameworkTestsBuilder
    {
        public MyAppTestsBuilder() : base()
        {
        }  
    }
}

This builder has an annotation that tells xUnit to share it across all tests in the same assembly. Only one instance of the builder will be created. The builder�s main role is to initialize dependencies and mocks.


Application Context Mock

You need to mock the ApplicationContext, which holds app configurations and AutoMapper profiles.

The tests package provides ApplicationContextMock, which handles basic mocking. You just need to override the Configurations and MapperProfiles properties:

public class MyAppContextMock : ApplicationContextMock
{
    protected override Dictionary<string, string?> Configurations { get; set; } = new Dictionary<string, string?>
    {
        { $"{Database}:{ConnectionString}", "1234connectionstring5678" },
    };

    protected override List<Profile> MapperProfiles { get; set; } = new List<Profile>
    {
        new UserMapperProfile(),
    };
}

Now override Initialize in the builder to apply this mock:

protected override void Initialize()
{
    base.Initialize();

    ApplicationContextMock = new MyAppContextMock().Mock();
}

Mocking Dependencies

You can also mock dependencies in the Initialize method. For example, you can mock an authentication service:

public class MyAuthDependencyMock : IMyAuthDependency
{
    public async Task<bool> Authenticate(MyMethodInput input)
    {
        return true;
    }
}

And then register it like this:

ApplicationContextMock!.AddTestDependency(new MyAuthDependencyMock());

Now, IMyAuthDependency will always resolve to your mock implementation.


Writing Tests

To write a test, create a class that inherits from OperationTest. You need to specify the Operation, Input, and Output types.

In the constructor, use the ApplicationContextMock from your test builder and instantiate the operation to test:

public class GetUsersOperationTests : OperationTest<GetUsersOperation, GetUsersInput, GetUsersOutput>
{
    public GetUsersOperationTests(MyAppTestsBuilder _testBuilder) : base(_testBuilder)
    {
        OperationToTest = new GetUsersOperation(_testBuilder.ApplicationContextMock!, string.Empty);
    }
}

Use the SimulateOperationToTestCall method to call the operation in a test:

[Fact]
public async Task ShouldBe_Success()
{
    var response = await SimulateOperationToTestCall(new GetUsersInput
    {
        OnlyAdminUsers = true,
    });

    Assert.True(response.Error == null);
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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
2.1.0 179 4/10/2025