Mockerade 0.4.0
dotnet add package Mockerade --version 0.4.0
NuGet\Install-Package Mockerade -Version 0.4.0
<PackageReference Include="Mockerade" Version="0.4.0" />
<PackageVersion Include="Mockerade" Version="0.4.0" />
<PackageReference Include="Mockerade" />
paket add Mockerade --version 0.4.0
#r "nuget: Mockerade, 0.4.0"
#:package Mockerade@0.4.0
#addin nuget:?package=Mockerade&version=0.4.0
#tool nuget:?package=Mockerade&version=0.4.0
Mockerade
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), andWith.Out<T>()for advanced setups.
Getting Started
Install the
Mockeradenuget packagedotnet add package MockeradeCreate 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 typeT.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
Raisesproperty 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
Invokedproperty to access invocation history for each method or property. - You can assert on the number of invocations or inspect the arguments used.
| Product | Versions 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. |
-
.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.