aweXpect.Mockolate 3.3.0

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

aweXpect.Mockolate

Changelog

Nuget Coverage Mutation testing badge

Expectations to verify interactions with mocks from Mockolate for aweXpect.

Overview

Expectation Summary
Once, Twice, Never the interaction happened exactly once, twice or never
AtLeastOnce, AtLeastTwice, AtLeast the interaction happened at least the given number of times
AtMostOnce, AtMostTwice, AtMost the interaction happened at most the given number of times
Exactly, Between the interaction happened exactly or in a range of times
Times the number of interactions satisfies a predicate
Then the interactions happened in the given order
AllInteractionsAreVerified every interaction with the mock was verified
AllSetupsAreUsed every setup of the mock was used

The samples use the following interface:

public interface IPlayer
{
    bool Play(string title);
    void Pause();
    void Stop();
}

Interaction count

You can verify how often a method was invoked:

using aweXpect.Core; // for Times()

IPlayer player = IPlayer.CreateMock();
player.Play("Let It Be");

await Expect.That(player.Mock.Verify.Play("Let It Be")).Once();
await Expect.That(player.Mock.Verify.Play("Yesterday")).Never();
await Expect.That(player.Mock.Verify.Play(It.IsAny<string>())).AtLeastOnce();
await Expect.That(player.Mock.Verify.Play(It.IsAny<string>())).AtMost(3.Times());
await Expect.That(player.Mock.Verify.Play(It.IsAny<string>())).Between(1).And(3.Times());
await Expect.That(player.Mock.Verify.Play(It.IsAny<string>())).Times(n => n % 2 == 1);

When the track was played twice, Once() fails with:

Expected that the MusicStore.IPlayer mock
invoked method Play(Let It Be) exactly once,
but it was found twice

Matching Interactions:
[
  invoke method Play(Let It Be),
  invoke method Play(Let It Be)
]

All Interactions:
[
  invoke method Play(Let It Be),
  invoke method Play(Let It Be)
]

Waiting for interactions

With Within(TimeSpan timeout), you can verify that the expected number of interactions happens within the given time. This is useful for interactions that happen asynchronously in the background.

Within and WithCancellation are available on AtLeast…, Once, Twice, Exactly, Between and Times. They are not available on Never or AtMost…, since an upper bound cannot be confirmed by waiting longer.

IPlayer player = IPlayer.CreateMock();

_ = Task.Run(async () =>
{
    await Task.Delay(500);
    player.Play("Hey Jude");
});

await Expect.That(player.Mock.Verify.Play("Hey Jude")).AtLeastOnce().Within(TimeSpan.FromSeconds(1));

When the interaction does not happen in time, e.g. a Stop() expected within 100 ms, the expectation fails:

Expected that the MusicStore.IPlayer mock
invoked method Stop() at least once within 0:00.100,
but it was never found

Matching Interactions:
[]

All Interactions:
[
  invoke method Play(Hey Jude)
]

Instead of a fixed time span, you can also provide a CancellationToken to wait for the expected interactions until it is canceled. Like for all aweXpect expectations, a cancellation leaves the expectation inconclusive instead of failing it, so use Within to limit how long the verification waits:

await Expect.That(player.Mock.Verify.Play("Hey Jude")).AtLeastOnce().WithCancellation(token);

Unlike other aweXpect expectations, these verifications also wait for the interaction when only WithTimeout or WithCancellation is given: the timeout or the token bounds how long they wait, and the verification fails when the timeout elapses. Within sets an explicit wait, which is shown in the expectation; a shorter WithTimeout still ends it early with "it did not finish within …".

A Times predicate that throws counts as not met while waiting, so the verification waits for further interactions, and only fails with the exception when the predicate still throws at the end. A selector of Then that throws fails the verification immediately.

Waiting for an interaction not to happen

DoesNotComplyWith evaluates the verification inside it non-negated, so put Within on the verification inside it to verify that an interaction does not happen within the given time. It waits the whole time and fails as soon as the interaction happens:

await Expect.That(player.Mock.Verify.Stop()).DoesNotComplyWith(it => it.AtLeastOnce().Within(TimeSpan.FromSeconds(1)));

Within on DoesNotComplyWith itself does not help here: it only checks again until the interaction is not found, so it succeeds immediately when the interaction did not happen yet.

Interaction order

You can verify that methods were invoked in a specific order:

IPlayer player = IPlayer.CreateMock();
player.Play("Let It Be");
player.Pause();
player.Stop();

await Expect.That(player.Mock.Verify.Play("Let It Be")).Then(
    m => m.Pause(),
    m => m.Stop());

Other interactions may happen in between. When the player was stopped before it was paused, the expectation fails:

Expected that the MusicStore.IPlayer mock
invoked method Play(Let It Be), then
invoked method Pause(), then
invoked method Stop() in order,
but it invoked method Stop() too early

All Interactions:
[
  invoke method Play(Let It Be),
  invoke method Stop(),
  invoke method Pause()
]

All interactions are verified

You can verify that all interactions with the mock were verified. This detects unintended or forgotten interactions:

IPlayer player = IPlayer.CreateMock();
player.Play("Let It Be");
player.Play("Yesterday");
player.Stop();

await Expect.That(player.Mock.Verify.Play(It.IsAny<string>())).Twice();
await Expect.That(player.Mock.Verify).AllInteractionsAreVerified();

The verification of Play covers both tracks, but Stop() was never verified:

Expected that the MusicStore.IPlayer mock
has all interactions verified,
but it had 1 unverified interaction

Unverified Interactions:
[
  invoke method Stop()
]

All setups are used

You can verify that all setups of the mock were used. This detects setups that are no longer needed:

IPlayer player = IPlayer.CreateMock();
player.Mock.Setup.Play("Let It Be").Returns(true);
player.Mock.Setup.Play("Yesterday").Returns(true);

player.Play("Let It Be");

await Expect.That(player.Mock.Verify).AllSetupsAreUsed();
Expected that the MusicStore.IPlayer mock
has used all setups,
but it had 1 unused setup

Unused Setups:
[
  bool Play("Yesterday")
]

HTTP content matchers

HTTP content matchers require .NET 8.0 or later.

This package also adds JSON matchers to Mockolate's It.IsHttpContent() (namespace Mockolate.Web). They are argument matchers, not expectations: use them in setups or verifications of a mocked HttpClient to match the JSON body of a request.

WithJsonMatching compares the body with an object, and WithJson with a JSON string, ignoring differences in formatting and property order:

HttpClient httpClient = HttpClient.CreateMock();
httpClient.Mock.Setup
    .PostAsync(It.IsAny<Uri>(), It.IsHttpContent().WithJsonMatching(new { title = "Let It Be", year = 1970 }))
    .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.Created));

httpClient.Mock.Setup
    .PostAsync(It.IsAny<Uri>(), It.IsHttpContent().WithJson("{\"year\": 1965, \"title\": \"Yesterday\"}"))
    .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.Created));

WithJsonMatching serializes the expected value by reflection, which is switched off when publishing with trimming or Native AOT enabled, so use WithJson with the expected JSON as a string there.

By default, additional properties in the actual JSON are ignored. Use IgnoringAdditionalProperties(false) to require an exact match:

httpClient.Mock.Setup
    .PostAsync(It.IsAny<Uri>(), It.IsHttpContent()
        .WithJsonMatching(new { title = "Let It Be", year = 1970 })
        .IgnoringAdditionalProperties(false))
    .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.Created));
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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on aweXpect.Mockolate:

Repository Stars
TestableIO/System.IO.Abstractions
Just like System.Web.Abstractions, but for System.IO. Yay for testable IO access!
Version Downloads Last Updated
3.3.0 116 10/10/2026
3.3.0-pre.2 40 10/8/2026
3.3.0-pre.1 58 9/28/2026
3.2.0 1,527 9/5/2026
3.1.0 4,114 5/10/2026
3.0.0 799 4/30/2026
3.0.0-pre.1 1,902 4/26/2026
2.3.0 2,028 4/3/2026
2.2.0 141 4/3/2026
2.2.0-pre.1 211 4/2/2026
2.0.0 1,270 3/25/2026
2.0.0-pre.3 86 3/24/2026
2.0.0-pre.2 86 3/24/2026
2.0.0-pre.1 88 3/22/2026
1.3.0 908 3/22/2026
1.2.0 1,020 3/6/2026
1.1.1 968 2/10/2026
1.1.0 362 2/8/2026
1.0.0 1,677 1/19/2026
0.10.0 150 1/18/2026
Loading failed