示例#1
0
        public async Task Should_return_game_id()
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var request = new GameMove.Request()
            {
                GameId   = GameId,
                PlayerId = HostId,
                Card     = Card,
                TileId   = TileId
            };

            var playCardHandler = new Mock <IStepHandler <PlayCardStep> >();

            playCardHandler
            .Setup(x => x.Run(It.IsAny <PlayCardStep>()))
            .Returns(new GameData
            {
                HostCards       = HostCards,
                ChallengerCards = ChallengerCards,
                Tiles           = new[] { CreateTile() }
            });

            var subject = new GameMove.RequestHandler(context, playCardHandler.Object);

            var response = await subject.Handle(request, default);

            response.GameId.Should().Be(GameId);
        }
示例#2
0
        public async Task Should_throw_GameInvalidPlayerException()
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var playerId = Guid.NewGuid();

            var command = new GameMove.Request()
            {
                GameId   = GameId,
                PlayerId = playerId,
                Card     = Card,
                TileId   = TileId
            };

            var playCardHandler = new Mock <IStepHandler <PlayCardStep> >();

            var subject = new GameMove.RequestHandler(context, playCardHandler.Object);

            Func <Task> act = async() => await subject.Handle(command, default);

            act.Should()
            .Throw <GameInvalidPlayerException>()
            .Where(x => x.GameId == GameId &&
                   x.PlayerId == playerId);
        }
示例#3
0
        public async Task Should_throw_inner_exception_NotPlayerTurnException()
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var request = new GameMove.Request()
            {
                GameId   = GameId,
                PlayerId = HostId,
                Card     = Card,
                TileId   = TileId
            };

            var playCardHandler = new Mock <IStepHandler <PlayCardStep> >();

            playCardHandler
            .Setup(x => x.ValidateAndThrow(It.IsAny <PlayCardStep>()))
            .Throws(new NotPlayerTurnException(new GameData(), true));

            var subject = new GameMove.RequestHandler(context, playCardHandler.Object);

            Func <Task> act = async() => await subject.Handle(request, default);

            act.Should()
            .Throw <GameDataInvalidException>()
            .Where(e => e.GameId == GameId)
            .WithInnerException <NotPlayerTurnException>();
        }
示例#4
0
        public void Should_throw_GameNotFoundException()
        {
            var context = DbContextFactory.CreateTripleTriadContext();

            var command = new GameMove.Request()
            {
                GameId   = GameId,
                PlayerId = HostId,
                Card     = Card,
                TileId   = TileId
            };

            var playCardHandler = new Mock <IStepHandler <PlayCardStep> >();

            var subject = new GameMove.RequestHandler(context, playCardHandler.Object);

            Func <Task> act = async() => await subject.Handle(command, default);

            act.Should()
            .Throw <GameNotFoundException>()
            .Where(e => e.GameId == GameId);
        }