Пример #1
0
        public void ExpectSetStateToCallStateProviderForTheNextState()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var state2 = new Mock<ITurnState>();
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);
            provider.Setup(p => p.Get<ITurnState>()).Returns(state2.Object);

            var turn = new Turn(player.Object, provider.Object);
            bool stateChanged = false;
            turn.StateChanged += (sender, args) =>
            {
                stateChanged = true;
                Assert.Equal(state2.Object, args);
            };
            turn.SetState<ITurnState>();

            Assert.True(stateChanged);
            provider.Verify(p => p.Get<ITurnState>());
        }