Mockurai 1.0.0

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

Mockurai

A source-generator-based mocking library for .NET.

Mockurai writes the mock for you. Decorate your test base with [MockuraiGenerate], declare partial IMock<T> properties for the dependencies you need, and let the generator produce strongly-typed Setup* and Verify* methods at compile time — no reflection, no proxies, no runtime IL.

💎 Why Mockurai

  • Type-safe setup & verify. Every mocked member gets a dedicated method (SetupGet, SetupReturnWithParameter, VerifyInvoke, …). Refactor a method signature and the compiler points you at every test that needs updating.
  • Optional setup parameters. Omit parameters you don’t care about (don't use It<T>.Any()) and focus only on those that matter.
  • Verification in sequence. Assert that calls happened in the expected order across one or many mocks with VerifyInSequence.
  • Auto-generated VerifyNoOtherCalls. A single call asserts every recorded invocation across every mock has been verified — no manual bookkeeping.
  • Generics & ref-style parameters. First-class support for generic interfaces, in, out, ref, and ref readonly parameters via dedicated matchers (ItIn<T>, ItOut<T>, ItRef<T>, ItRefReadOnly<T>).

🚀 Install

dotnet add package Mockurai

⚙️ How it works

Add [MockuraiGenerate] to a partial test base class and declare IMock<T> properties for each dependency. The generator fills in the implementations and produces the matching setup/verify extension methods.

[MockuraiGenerate]
public abstract partial class CustomerServiceTestsBase
{
    protected partial IMock<ICustomerRepository> RepositoryMock { get; }
    protected partial IMock<IClock> ClockMock { get; }

    protected ICustomerService CreateFixture() =>
        new CustomerService(RepositoryMock.Object, ClockMock.Object);
}

✅ Setup, verify, and VerifyNoOtherCalls

public sealed class GetCustomerShould : CustomerServiceTestsBase
{
    [Fact]
    public void ReturnCustomerFromRepository()
    {
        const string customerId = "C-001";
        var expected = new Customer(customerId, "Issei");

        RepositoryMock
            .SetupGetById(customerId)
            .Returns(expected);

        var actual = CreateFixture().GetCustomer(customerId);

        Assert.Equal(expected, actual);

        RepositoryMock.VerifyGetById(customerId, Times.Once);
        VerifyNoOtherCalls();
    }
}

VerifyNoOtherCalls() covers every mock declared on the base class — if any invocation slips through unverified, the test fails with a precise message pointing at it.

🔢 Verify in sequence

[Fact]
public void SaveBeforeNotifying()
{
    var customer = new Customer("C-001", "Issei");

    CreateFixture().Register(customer);

    VerifyInSequence(static ctx =>
    {
        ctx.RepositoryMock.Save(It<Customer>.Equivalent(customer));
        ctx.ClockMock.UtcNow();
        ctx.RepositoryMock.MarkRegistered("C-001");
    });
    VerifyNoOtherCalls();
}

The sequence asserts both the order and the arguments across multiple mocks. Mismatches surface the full invocation log so you can see exactly where reality diverged from expectation.

🎯 Argument matchers

Matcher Use for
It<T> by-value parameters
ItIn<T> in parameters
ItOut<T> out parameters
ItRef<T> ref parameters
ItRefReadOnly<T> ref readonly parameters

Each one offers .Value(...), .Equivalent(...), .Where(predicate), and .Any().

📄 License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
1.0.0 1,173 5/3/2026