Mockolate 0.9.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mockolate --version 0.9.1
                    
NuGet\Install-Package Mockolate -Version 0.9.1
                    
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="Mockolate" Version="0.9.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mockolate" Version="0.9.1" />
                    
Directory.Packages.props
<PackageReference Include="Mockolate" />
                    
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 Mockolate --version 0.9.1
                    
#r "nuget: Mockolate, 0.9.1"
                    
#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 Mockolate@0.9.1
                    
#: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=Mockolate&version=0.9.1
                    
Install as a Cake Addin
#tool nuget:?package=Mockolate&version=0.9.1
                    
Install as a Cake Tool

Mockolate

Changelog Nuget Coverage Mutation testing badge

Mockolate logo

Mockolate 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 Mockolate nuget package

    dotnet add package Mockolate
    
  2. Create a mock

    using Mockolate;
    
    var mock = Mock.Create<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

Mockolate 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 (1)

Showing the top 1 NuGet packages that depend on Mockolate:

Package Downloads
aweXpect.Mockolate

Expectations to verify interactions with mocks from Mockolate.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.27.0 0 11/5/2025
0.26.0 51 11/4/2025
0.25.0 64 11/2/2025
0.24.0 58 11/1/2025
0.23.0 59 11/1/2025
0.22.0 148 10/26/2025
0.21.0 150 10/26/2025
0.20.0 128 10/26/2025
0.19.0 126 10/25/2025
0.18.0 90 10/25/2025
0.17.0 88 10/25/2025
0.16.0 91 10/25/2025
0.15.0 87 10/25/2025
0.14.0 101 10/24/2025
0.13.0 111 10/24/2025
0.12.0 165 10/20/2025
0.11.0 102 10/18/2025
0.10.2 160 10/15/2025
0.10.1 157 10/13/2025
0.10.0 319 10/12/2025
0.9.1 208 10/12/2025
0.9.0 163 10/12/2025
0.8.0 104 10/11/2025
0.7.0 167 10/10/2025
0.6.0 158 10/8/2025
0.5.4 361 10/8/2025
0.5.3 162 10/8/2025
0.5.2 157 10/7/2025
0.5.1 162 10/7/2025
0.5.0 160 10/7/2025
0.4.0 158 10/7/2025
0.3.0 156 10/5/2025
0.2.0 156 10/5/2025
0.1.0 96 10/4/2025