Skip to main content

All interactions and setups

Describes the possible expectations for verifying that all interactions with a mock were verified and all its setups were used.

ExpectationNegatedSummary
AllInteractionsAreVerifiedevery interaction with the mock was verified
AllSetupsAreUsedevery setup of the mock was used

The samples use the IPlayer interface from Interaction count.

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 That(player.Mock.Verify.Play(It.IsAny<string>())).Twice();
await That(player.Mock.Verify).AllInteractionsAreVerified();

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

Failure message
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 That(player.Mock.Verify).AllSetupsAreUsed();
Failure message
Expected that the MusicStore.IPlayer mock
has used all setups,
but it had 1 unused setup

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