Advanced features
The basics of creating, setting up and verifying mocks cover most tests. The following features help in the remaining cases:
| Feature | Use it when you want to … |
|---|---|
| Protected members | set up or verify protected virtual members of a class mock |
| Static interface members | mock static abstract or static virtual interface members |
| Advanced callback features | control how often and when return values and callbacks apply |
| Monitor interactions | only verify the interactions within a scope, or reset the recorded interactions |
| Check for unexpected interactions | make sure every interaction was verified, or every setup was used |
| Scenarios | switch between sets of setups, for collaborators with an internal state |
For example, scenarios let a dispenser with a Refill method behave differently before and after
a refill:
dispenser.Mock.InScenario("empty").Setup.Refill(It.IsAny<int>())
.Returns(true)
.TransitionTo("loaded");
dispenser.Mock.InScenario("loaded").Setup.Dispense(It.IsAny<string>(), It.IsAny<int>())
.Returns(true);