Ejemplo n.º 1
0
        public async Task Should_throw_CannotJoinGameException()
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            game.ChallengerId = Guid.NewGuid();

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var command = new GameJoin.Request()
            {
                GameId   = GameId,
                PlayerId = PlayerId
            };

            var subject = new GameJoin.RequestHandler(context);

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

            act.Should()
            .Throw <CannotJoinGameException>()
            .Where(e => e.GameId == GameId);
        }
Ejemplo n.º 2
0
        public void Good_request_should_not_throw(GameJoin.Request request)
        {
            var         subject = new GameJoin.Validator();
            Func <Task> action  = async() => await subject.Process(request, default);

            action.Should().NotThrow <ValidationException>();
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Join(int gameId)
        {
            var playerId = base.HttpContext.GetPlayerId();
            var request  = new GameJoin.Request()
            {
                GameId   = gameId,
                PlayerId = playerId
            };
            var response = await this.mediator.Send(request, default);

            return(base.Json(new { GameId = response.GameId }));
        }
Ejemplo n.º 4
0
        public void Should_throw_GameNotFoundException()
        {
            var gameId  = 1;
            var context = DbContextFactory.CreateTripleTriadContext();

            var command = new GameJoin.Request()
            {
                GameId   = gameId,
                PlayerId = PlayerId
            };
            var subject = new GameJoin.RequestHandler(context);

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

            act.Should()
            .Throw <GameNotFoundException>()
            .Where(e => e.GameId == gameId);
        }
Ejemplo n.º 5
0
        public async Task Should_queue_lobby_notification()
        {
            var request = new GameJoin.Request
            {
                GameId   = GameId,
                PlayerId = ChallengerId
            };

            var response = new GameJoin.Response
            {
                GameId = GameId,
                HostId = HostId
            };

            await this.subject.Process(request, response);

            this.backgroundTaskQueue.Verify(
                x => x.QueueBackgroundTask(It.IsAny <LobbyNotification>()));
        }
Ejemplo n.º 6
0
        public async Task Should_return_joined_game()
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var command = new GameJoin.Request()
            {
                GameId   = GameId,
                PlayerId = PlayerId
            };
            var subject = new GameJoin.RequestHandler(context);

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

            response.GameId.Should().Be(GameId);
        }
Ejemplo n.º 7
0
        public async Task Should_set_game_status_to_choose_cards()
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var command = new GameJoin.Request()
            {
                GameId   = GameId,
                PlayerId = PlayerId
            };
            var subject = new GameJoin.RequestHandler(context);

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

            game = await context.Games.SingleAsync(x => x.GameId == response.GameId);

            game.Status.Should().Be(GameStatus.ChooseCards);
        }
Ejemplo n.º 8
0
        public async Task Should_have_correct_player_two_id()
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var command = new GameJoin.Request()
            {
                GameId   = GameId,
                PlayerId = PlayerId
            };
            var subject = new GameJoin.RequestHandler(context);

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

            game = await context.Games.SingleAsync(x => x.GameId == response.GameId);

            game.ChallengerId.Should().Be(PlayerId);
        }
Ejemplo n.º 9
0
        public async Task Should_queue_challenger_user_notification()
        {
            var request = new GameJoin.Request
            {
                GameId   = GameId,
                PlayerId = ChallengerId
            };

            var response = new GameJoin.Response
            {
                GameId = GameId,
                HostId = HostId
            };

            await this.subject.Process(request, response);

            this.backgroundTaskQueue.Verify(
                x => x.QueueBackgroundTask(
                    It.Is <UserNotification>(
                        y => y.GameId == GameId &&
                        y.UserId == ChallengerId)));
        }