Mockerade 0.4.0

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

Mockerade

Changelog

Nuget Coverage

Mockerade is a modern, strongly-typed mocking library for .NET, powered by source generators. It enables fast, compile-time validated mocks for interfaces and classes, supporting .NET Standard 2.0, .NET 8, .NET 10, and .NET Framework 4.8.

  • Source generator-based: No runtime proxy generation, fast and reliable.
  • Strongly-typed: Setup and verify mocks with full IntelliSense and compile-time safety.
  • Event support: Easily raise and verify events.
  • Flexible argument matching: Use With.Any<T>(), With.Matching<T>(predicate), and With.Out<T>() for advanced setups.

Getting Started

  1. Install the Mockerade nuget package

    dotnet add package Mockerade
    
  2. Create a mock

    using Mockerade;
    
    var mock = Mock.For<IMyInterface>();
    

Features

Setup

Set up return values or behaviors for methods and properties on your mock. This allows you to control how the mock responds to calls in your tests.

mock.Setup.AddUser(With.Any<string>())
    .Returns(new User(Guid.NewGuid(), "Alice"));

mock.Setup.Property.Get().Returns(42);
  • Use .Returns(value) to specify the value to return.
  • You can also set up void methods and property setters.

Argument Matching

Mockerade provides flexible argument matching for method setups and verifications:

  • With.Any<T>(): Matches any value of type T.
  • With.Matching<T>(predicate): Matches values based on a predicate.
  • With.Out<T>(valueFactory): Matches and sets out parameters.
mock.Setup.AddUser(With.Matching<string>(name => name.StartsWith("A")))
    .Returns(new User(Guid.NewGuid(), "Alicia"));

mock.Setup.TryDelete(With.Any<Guid>(), With.Out<User?>(() => new User(id, "Alice")))
    .Returns(true);

Event Raising

Easily raise events on your mock to test event handlers in your code:

mock.Raises.UsersChanged(this, EventArgs.Empty);
  • Use the Raises property to trigger events declared on the mocked interface or class.
  • This allows you to simulate notifications and test event-driven logic.

Verification

Verify that methods or properties were called with specific arguments and how many times:

mock.Invoked.AddUser("Bob").Invocations.Count(); // e.g., 1
mock.Invoked.TryDelete(id, With.Out<User?>()).Invocations.Count();
  • Use the Invoked property to access invocation history for each method or property.
  • You can assert on the number of invocations or inspect the arguments used.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 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 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. 
.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 was computed.  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.
  • .NETStandard 2.0

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

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.4.0 183 10/2/2025
0.3.0 194 9/30/2025
0.2.0 157 9/28/2025
0.1.0 157 9/28/2025