示例#1
0
        public void BoringToeUserCancels()
        {
            // Given
            helperMock.Setup(m => m.GetPlayerAName()).Returns("");
            helperMock.Setup(m => m.GetPlayerBName()).Returns("");
            helperMock.SetupSequence(m => m.GetXCoordinate(It.IsAny <string>()))
            .Returns(0)
            .Returns(1)
            .Throws <UserCancelException>()
            .Returns(0)
            .Returns(1)
            .Returns(0)
            .Returns(1);
            helperMock.SetupSequence(m => m.GetYCoordinate(It.IsAny <string>()))
            .Returns(0)
            .Returns(0)
            .Returns(1)
            .Returns(1)
            .Returns(1)
            .Returns(2)
            .Returns(2);
            BoringToe game = new BoringToe(helperMock.Object);

            // When
            game.Run();

            // Then
            helperMock.Verify(v => v.GetPlayerAName(), Times.Once, "GetPlayerAName must be run exactly 1 time");
            helperMock.Verify(v => v.GetPlayerBName(), Times.Once, "GetPlayerBName must be run exactly 1 time");
            helperMock.Verify(v => v.GetXCoordinate(It.IsAny <string>()), Times.Exactly(3), "GetXCoordinate must be run exactly 3 times");
            helperMock.Verify(v => v.GetYCoordinate(It.IsAny <string>()), Times.Exactly(2), "GetYCoordinate must be run exactly 2 times");
        }
示例#2
0
        public void BoringToeRunHappyPath()
        {
            // Given
            helperMock.Setup(m => m.GetPlayerAName()).Returns("");
            helperMock.Setup(m => m.GetPlayerBName()).Returns("");
            helperMock.SetupSequence(m => m.GetXCoordinate(It.IsAny <string>()))
            .Returns(0)
            .Returns(1)
            .Returns(0)
            .Returns(1)
            .Returns(0)
            .Returns(1);
            helperMock.SetupSequence(m => m.GetYCoordinate(It.IsAny <string>()))
            .Returns(0)
            .Returns(0)
            .Returns(1)
            .Returns(1)
            .Returns(2)
            .Returns(2);
            BoringToe game = new BoringToe(helperMock.Object);

            // When
            game.Run();

            // Then
            helperMock.Verify(v => v.GetPlayerAName(), Times.Once, "GetPlayerAName must be run exactly 1 time");
            helperMock.Verify(v => v.GetPlayerBName(), Times.Once, "GetPlayerBName must be run exactly 1 time");
            helperMock.Verify(v => v.GetXCoordinate(It.IsAny <string>()), Times.Exactly(5), "GetXCoordinate must be run exactly 5 times");
            helperMock.Verify(v => v.GetYCoordinate(It.IsAny <string>()), Times.Exactly(5), "GetYCoordinate must be run exactly 5 times");
        }