Expectations to verify interactions with mocks from Mockolate for aweXpect.
IPlayer player = IPlayer.CreateMock();
player.Play("Let It Be");
player.Stop();
// verify how often a method was invoked
await Expect.That(player.Mock.Verify.Play("Let It Be")).Once();
// verify the order of the interactions
await Expect.That(player.Mock.Verify.Play("Let It Be")).Then(m => m.Stop());
// verify that no interaction was forgotten
await Expect.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:
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)
]
| 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 full documentation is available at docs.testably.org:
- Interaction count: how often a method was invoked, and waiting for interactions that happen in the background
- Interaction order:
Thento verify that methods were invoked in a specific order - All interactions and setups:
AllInteractionsAreVerifiedandAllSetupsAreUsed - HTTP content matchers: JSON matchers for
It.IsHttpContent()in setups and verifications of a mockedHttpClient