public async Task Should_decrease_number_of_dynamites_used()
        {
            // Arrange
            moveMaker.MakeMove(Arg.Any <int>()).Returns(Move.Dynamite);

            // Act
            await rpsPlayer.MakeMove();

            // Assert
            (await rpsGameStore.GetGame()).NumberOfDynamite.Should().Be(numberOfDynamite - 1);
        }
        public void Should_throw_exception_if_no_game_in_progress()
        {
            // Arrange
            var newRpsGame = new RPSGame(10, 0);

            rpsGameStore.GetGame().Returns(newRpsGame);

            // Act && Assert
            rpsPlayer.Invoking(async r => await r.GameResult(Outcome.Win, Move.Rock))
            .Should().Throw <Exception>().WithMessage(Constants.NoGameProgress);
        }
Exemplo n.º 3
0
        public void Should_throw_exception_when_game_already_in_progress()
        {
            // Arrange
            rpsGameStore.GetGame().Returns(new RPSGame(1, 1));

            // Act && Assert
            rpsPlayer.Invoking(async r => await r.GetReady(1, 1))
            .Should().Throw <Exception>().WithMessage(Constants.MatchAlreadyInProgress);
        }
        public void Setup()
        {
            rpsGameStore = Substitute.For <IRPSGameStore>();
            moveMaker    = Substitute.For <IMoveMaker>();

            rpsGameStore.GetGame().Returns(new RPSGame(numberOfGames, numberOfDynamite));
            moveMaker.MakeMove(Arg.Any <int>()).Returns(Move.Rock);

            rpsPlayer = new RPSPlayer(rpsGameStore, moveMaker);
        }
        public async Task Should_throw_exception_if_not_all_games_completed()
        {
            // Arrange
            var newRpsGame = new RPSGame(10, 1);

            rpsGameStore.GetGame().Returns(newRpsGame);

            // Act && Assert
            rpsPlayer.Invoking(async r => await r.Result(Outcome.Win))
            .Should().Throw <Exception>().WithMessage(Constants.NotAllGamesCompleted);
        }
        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);
        }
Exemplo n.º 7
0
        public async Task <string> GetReady(int numGames, int numDynamite)
        {
            if (await rpsGameStore.GetGame() != null)
            {
                throw new Exception(Constants.MatchAlreadyInProgress);
            }
            if (numGames <= 0 || numDynamite < 0)
            {
                throw new ArgumentException(Constants.InvalidParameters);
            }
            if (numDynamite > numGames)
            {
                throw new ArgumentException(Constants.InvalidNumberOfDynamite);
            }

            var rpsGame = new RPSGame(numGames, numDynamite);
            await rpsGameStore.Add(rpsGame);

            return(Constants.GameSuccessfullySetup);
        }
        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);
        }