コード例 #1
0
        public void Setup()
        {
            rpsGameStore = Substitute.For <IRPSGameStore>();
            moveMaker    = Substitute.For <IMoveMaker>();
            rpsGame.AddGame(Move.Rock);
            rpsGame.Games[0].UpdateOutcome(Outcome.Win, Move.Warterbomb);

            rpsGameStore.GetGame().Returns(rpsGame);

            rpsPlayer = new RPSPlayer(rpsGameStore, moveMaker);
        }
コード例 #2
0
        public void Should_throw_exception_if_game_already_in_progress()
        {
            // Arrange
            var rpsGame = new RPSGame(2, 1);

            rpsGame.AddGame(Move.Rock);
            rpsGameStore.GetGame().Returns(rpsGame);

            // Act & Assert
            rpsPlayer.Invoking(async r => await r.MakeMove()).Should().Throw <Exception>().WithMessage(Constants.GameInProgress);
        }
コード例 #3
0
        public void Setup()
        {
            rpsGameStore = Substitute.For <IRPSGameStore>();
            moveMaker    = Substitute.For <IMoveMaker>();

            rpsGame.AddGame(Move.Paper);
            rpsGameStore.GetGame().Returns(rpsGame);
            moveMaker.MakeMove(Arg.Any <int>()).Returns(Move.Rock);

            rpsPlayer = new RPSPlayer(rpsGameStore, moveMaker);
        }
コード例 #4
0
        public void Should_throw_exception_if_no_games_left_to_play()
        {
            // Arrange
            var rpsGame = new RPSGame(1, 1);

            rpsGame.AddGame(Move.Rock);
            rpsGameStore.GetGame().Returns(rpsGame);

            // Act & Assert
            rpsPlayer.Invoking(async r => await r.MakeMove())
            .Should().Throw <Exception>().WithMessage(Constants.NoGamesLeftToPlay);
        }
コード例 #5
0
        public void Should_throw_exception_if_outcome_doesnt_match_moves(Outcome yourOutcome, Move move, Move opponentMove)
        {
            // Arrange
            var newRpsGame = new RPSGame(10, 0);

            newRpsGame.AddGame(move);
            rpsGameStore.GetGame().Returns(newRpsGame);

            // Act & Assert
            rpsPlayer.Invoking(async r => await r.GameResult(yourOutcome, opponentMove)).Should().Throw <ArgumentException>()
            .WithMessage(Constants.InvalidOutcome);
        }
コード例 #6
0
        public void Should_throw_exception_if_opponent_dynamites_greater_than_allowed()
        {
            // Arrange
            var newRpsGame = new RPSGame(10, 0);

            newRpsGame.AddGame(Move.Paper);
            rpsGameStore.GetGame().Returns(newRpsGame);

            // Act && Assert
            rpsPlayer.Invoking(async r => await r.GameResult(Outcome.Win, Move.Dynamite))
            .Should().Throw <ArgumentException>().WithMessage(string.Format(Constants.TooManyDynamite, 0));
        }