Mockurai 1.0.0
dotnet add package Mockurai --version 1.0.0
NuGet\Install-Package Mockurai -Version 1.0.0
<PackageReference Include="Mockurai" Version="1.0.0" />
<PackageVersion Include="Mockurai" Version="1.0.0" />
<PackageReference Include="Mockurai" />
paket add Mockurai --version 1.0.0
#r "nuget: Mockurai, 1.0.0"
#:package Mockurai@1.0.0
#addin nuget:?package=Mockurai&version=1.0.0
#tool nuget:?package=Mockurai&version=1.0.0
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, andref readonlyparameters 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 | Versions 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. |
-
net10.0
- Mockurai.Abstractions (>= 1.0.0)
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,238 | 5/3/2026 |