An example - I want to test that the sniper notifies the view only for added items.
[Test]
public void NotifiesViewOfLoss_IfCloseEventReceivedForSnipedItems()
{
_sniper.AddItem(TestConstants.ItemNo54321);
_sniper.AddItem(TestConstants.ItemNo65432);
_sniper.AuctionClosedFor(TestConstants.ItemNo65432);
_mockView.Verify(view => view.UpdateStatus(TestConstants.ItemNo65432, AuctionSniperStatus.Lost));
_sniper.AuctionClosedFor(TestConstants.ItemNo54321);
_mockView.Verify(view => view.UpdateStatus(TestConstants.ItemNo54321, AuctionSniperStatus.Lost));
_sniper.AuctionClosedFor(7);
// doesn't work
//_mockView.Verify(view => view.UpdateStatus(It.IsAny<int>(), It.IsAny<AuctionSniperStatus>()),
// Times.Never() );
}
The Times.Never line doesn't work - because it matches one of the earlier calls. I know that there are other alternatives:
- set up a new expectation to throw if called (as shown above)
- like specifying 7 instead of IsAny()
- splitting the test into 2 tests