Skip to main content

aweXpect.Mockolate

aweXpect.Mockolate contains expectations to verify interactions with mocks from Mockolate. It is an extension for aweXpect.

Installation​

dotnet add package aweXpect.Mockolate

It does not include aweXpect itself. The expectations live in the namespace aweXpect, the HTTP content matchers in Mockolate.Web.

At a glance​

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

// verify how often a method was invoked
await That(player.Mock.Verify.Play("Let It Be")).Once();

// verify the order of the interactions
await That(player.Mock.Verify.Play("Let It Be")).Then(m => m.Stop());

// verify that no interaction was forgotten
await That(player.Mock.Verify).AllInteractionsAreVerified();

A failing verification lists the matching and all interactions with the mock. If the track was played twice, Once() would fail with:

Failure message
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)
]

Overview​

ExpectationSummary
Once, Twice, Neverthe interaction happened exactly once, twice or never
AtLeastOnce, AtLeastTwice, AtLeastthe interaction happened at least the given number of times
AtMostOnce, AtMostTwice, AtMostthe interaction happened at most the given number of times
Exactly, Betweenthe interaction happened exactly or in a range of times
Timesthe number of interactions satisfies a predicate
Thenthe interactions happened in the given order
AllInteractionsAreVerifiedevery interaction with the mock was verified
AllSetupsAreUsedevery setup of the mock was used

Verifications of a minimum number of interactions and of their order can wait for interactions that happen in the background with Within(timeout), see Waiting for interactions and Interaction order.

The HTTP content matchers add JSON matchers for It.IsHttpContent() in setups and verifications of a mocked HttpClient.