The below code snippet best explains what I am trying to achieve:
[Test]
public void ReplayGoalTeamATest()
{
var stateMachineMock = new Mock<IIceHockeyOddsStateMachine>();
new IceHockeyActionLogRecord { Event = "goal", Team = "A"}.Replay(stateMachineMock.Object);
stateMachineMock.Verify(s=>s.TeamAScore++); //Syntax error
}
When you do
s.TeamAScore++then you have two different actions, which you should setup and verify. First action is getting current score from your dependency, and second action is setting new score:So, I’d go with explicitly defining this interaction with dependency:
In this case you are testing your IceHockeyActionLogRecord, the way how it interacts with dependencies. Test becomes a specification of interaction between objects.
When you are verifying TeamAScore value, you are testing mock implementation instead. Also usage of Callback will test your code, instead of testing interaction between objects.
Also, I’d give names for magic numbers inside your test, or even provide parameters:
UPDATE: if your interface doesn’t has getter for property, then just modify Arrange part of test (don’t setup property getter call):