aweXpect.Mockolate
aweXpect.Mockolate contains expectations to verify interactions with mocks from Mockolate. It is an extension for aweXpect.
Installation
- .NET CLI
- PackageReference
- Central Package Management
dotnet add package aweXpect.Mockolate
<PackageReference Include="aweXpect.Mockolate" Version="4.0.0" />
Directory.Packages.props
<PackageVersion Include="aweXpect.Mockolate" Version="4.0.0" />
Project file
<PackageReference Include="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
| 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 |
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.