Example #1
0
        public async Task <Move> MakeMove()
        {
            var rpsGame = await rpsGameStore.GetGame();

            if (rpsGame == null)
            {
                throw new Exception(Constants.NoMatchInProgress);
            }

            if (rpsGame.Games.Count == rpsGame.NumberOfGames)
            {
                throw new Exception(Constants.NoGamesLeftToPlay);
            }

            if (rpsGame.Games.Any(g => g.OpponentMove == null))
            {
                throw new Exception(Constants.GameInProgress);
            }

            var move = moveMaker.MakeMove(rpsGame.NumberOfDynamite);

            rpsGame.AddGame(move);

            if (move == Move.Dynamite)
            {
                rpsGame.DynamiteUsed();
            }

            await rpsGameStore.Update(rpsGame);

            return(move);
        }
        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_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 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);
        }