Esempio n. 1
0
        public void PlayerVotingOwnCardShouldThrowInvalidOperationException()
        {
            //arrange
            var lobby = new LobbyBuilder()
                        .WithPlayers(_players)
                        .WithRoundOne()
                        .WithPlayedCards()
                        .Build();

            var mediator            = new Mock <IMediator>();
            var lobbyRepositoryMock = new Mock <ILobbyRepository>();

            lobbyRepositoryMock.Setup(lobbyRepo => lobbyRepo.GetLobbyByCode(It.IsAny <string>())).Returns(Task.FromResult(lobby));
            var lobbyRepository = lobbyRepositoryMock.Object;
            var scoreService    = new Mock <IScoreService>();
            var command         = new VoteCardCommandHandler(mediator.Object, scoreService.Object, lobbyRepository);
            var request         = new VoteCardCommand
            {
                Card   = lobby.CurrentPlayedCards.FirstOrDefault(card => card.Owner.Name == _players[1]).Id,
                Code   = lobby.Code,
                Player = _players[1]
            };

            //act
            Func <Task> action = async() => await command.Handle(request, CancellationToken.None);

            //assert
            action.Should().Throw <InvalidOperationException>();
        }
Esempio n. 2
0
        public async Task GameStateShouldBeVotingWhenNotAllPlayersVoted()
        {
            //arrange
            var lobby = new LobbyBuilder()
                        .WithPlayers(_players)
                        .WithRoundOne()
                        .WithPlayedCards()
                        .Build();

            var mediator            = new Mock <IMediator>();
            var lobbyRepositoryMock = new Mock <ILobbyRepository>();

            lobbyRepositoryMock.Setup(lobbyRepo => lobbyRepo.GetLobbyByCode(It.IsAny <string>())).Returns(Task.FromResult(lobby));
            var lobbyRepository = lobbyRepositoryMock.Object;
            var scoreService    = new Mock <IScoreService>();
            var command         = new VoteCardCommandHandler(mediator.Object, scoreService.Object, lobbyRepository);
            var request         = new VoteCardCommand
            {
                Card   = lobby.CurrentPlayedCards.FirstOrDefault(card => card.Owner.Name != _players[1]).Id,
                Code   = lobby.Code,
                Player = _players[1]
            };

            //act
            await command.Handle(request, CancellationToken.None);

            //assert
            lobby.GameState.Should().Equals(State.InProgress);
        }
Esempio n. 3
0
        public async Task GameStateShouldBeStoryWhenAllPlayerVotes()
        {
            //arrange
            var lobby = new LobbyBuilder()
                        .WithPlayers(_players)
                        .WithRoundOne()
                        .WithPlayedCards()
                        .WithVotedCardsExceptPlayer(_players[4])
                        .Build();

            var mediator            = new Mock <IMediator>();
            var lobbyRepositoryMock = new Mock <ILobbyRepository>();

            lobbyRepositoryMock.Setup(lobbyRepo => lobbyRepo.GetLobbyByCode(It.IsAny <string>())).Returns(Task.FromResult(lobby));
            var lobbyRepository = lobbyRepositoryMock.Object;
            var scoreService    = new Mock <IScoreService>();

            scoreService.Setup(service => service.VallyVotes(It.IsAny <List <Vote> >(), It.IsAny <Player>(), It.IsAny <Card>())).Returns(new List <ScoreCard> {
            });
            var previousStoryTeller = lobby.CurrentStoryTeller;
            var command             = new VoteCardCommandHandler(mediator.Object, scoreService.Object, lobbyRepository);
            var request             = new VoteCardCommand
            {
                Card   = lobby.CurrentPlayedCards.FirstOrDefault(card => card.Owner.Name != _players[4]).Id,
                Code   = lobby.Code,
                Player = _players[4]
            };

            //act
            await command.Handle(request, CancellationToken.None);

            //assert
            lobby.GameState.Should().Equals(State.Story);
            lobby.CurrentStoryTeller.Should().NotBe(previousStoryTeller);
            scoreService.Verify(service => service.VallyVotes(It.IsAny <List <Vote> >(), It.IsAny <Player>(), It.IsAny <Card>()), Times.Once());
        }