Beispiel #1
0
        public void Good_request_should_not_throw(GameStart.Request request)
        {
            var         subject = new GameStart.Validator();
            Func <Task> action  = async() => await subject.Process(request, default);

            action.Should().NotThrow <ValidationException>();
        }
Beispiel #2
0
        public async Task Should_throw_GameHasInvalidStatusException(GameStatus status)
        {
            var context = DbContextFactory.CreateTripleTriadContext();
            var game    = CreateGame();

            game.Status = status;

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var command = new GameStart.Request()
            {
                GameId = game.GameId
            };

            var coinTossHandler = new Mock <IStepHandler <CoinTossStep> >();

            var createBoardHandler = new Mock <IStepHandler <CreateBoardStep> >();

            var subject = new GameStart.RequestHandler(
                context,
                coinTossHandler.Object,
                createBoardHandler.Object);

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

            act.Should()
            .Throw <GameHasInvalidStatusException>()
            .Where(x => x.GameId == GameId &&
                   x.Status == status);
        }
        public async Task Handle(GameStartNotification notification, CancellationToken cancellationToken)
        {
            var request = new GameStart.Request
            {
                GameId = notification.GameId
            };

            await this.mediator.Send(request);
        }
Beispiel #4
0
        public async Task Should_return_correct_response(bool coinTossIsHeads, Guid expectedStartingPlayerId)
        {
            var context    = DbContextFactory.CreateTripleTriadContext();
            var game       = CreateGame();
            var host       = CreatePlayer(HostId, true);
            var challenger = CreatePlayer(ChallengerId, false);

            await context.Players.AddAsync(host);

            await context.Players.AddAsync(challenger);

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var command = new GameStart.Request()
            {
                GameId = game.GameId
            };

            var coinTossHandler = new Mock <IStepHandler <CoinTossStep> >();

            coinTossHandler
            .Setup(x => x.Run(It.IsAny <CoinTossStep>()))
            .Returns(new GameData
            {
                HostWonCoinToss = coinTossIsHeads,
                HostTurn        = coinTossIsHeads
            });

            var createBoardHandler = new Mock <IStepHandler <CreateBoardStep> >();

            createBoardHandler
            .Setup(x => x.Run(It.IsAny <CreateBoardStep>()))
            .Returns <CreateBoardStep>(x => x.Data);

            var subject = new GameStart.RequestHandler(
                context,
                coinTossHandler.Object,
                createBoardHandler.Object);

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

            using (new AssertionScope())
            {
                response.StartPlayerId.Should().Be(expectedStartingPlayerId);
                response.HostId.Should().Be(HostId);
                response.ChallengerId.Should().Be(ChallengerId);
            }
        }
        public async Task Should_queue_room_notification()
        {
            var request  = new GameStart.Request();
            var response = new GameStart.Response
            {
                GameId       = GameId,
                HostId       = HostId,
                ChallengerId = ChallengerId
            };

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

            this.backgroundTaskQueue.Verify(
                x => x.QueueBackgroundTask(
                    It.Is <RoomNotification>(y => y.GameId == GameId)));
        }
Beispiel #6
0
        public async Task Should_throw_inner_exception_PlayerStillSelectingCardsException(
            bool hostStillSelecting,
            bool challengerStillSelecting)
        {
            var context    = DbContextFactory.CreateTripleTriadContext();
            var game       = CreateGame();
            var host       = CreatePlayer(HostId, true);
            var challenger = CreatePlayer(ChallengerId, false);

            await context.Players.AddAsync(host);

            await context.Players.AddAsync(challenger);

            await context.Games.AddAsync(game);

            await context.SaveChangesAsync();

            var command = new GameStart.Request()
            {
                GameId = game.GameId
            };

            var coinTossHandler = new Mock <IStepHandler <CoinTossStep> >();

            coinTossHandler
            .Setup(x => x.ValidateAndThrow(It.IsAny <CoinTossStep>()))
            .Throws(new PlayerStillSelectingCardsException(
                        new GameData(),
                        hostStillSelecting,
                        challengerStillSelecting));

            var createBoardHandler = new Mock <IStepHandler <CreateBoardStep> >();

            var subject = new GameStart.RequestHandler(
                context,
                coinTossHandler.Object,
                createBoardHandler.Object);

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

            act.Should()
            .Throw <GameDataInvalidException>()
            .Where(e => e.GameId == GameId)
            .WithInnerException <PlayerStillSelectingCardsException>()
            .Where(e => e.Host == hostStillSelecting &&
                   e.Challenger == challengerStillSelecting);
        }
Beispiel #7
0
        public void Should_throw_GameNotFoundException()
        {
            var context = DbContextFactory.CreateTripleTriadContext();

            var command = new GameStart.Request()
            {
                GameId = GameId
            };

            var coinTossHandler = new Mock <IStepHandler <CoinTossStep> >();

            var createBoardHandler = new Mock <IStepHandler <CreateBoardStep> >();

            var subject = new GameStart.RequestHandler(
                context,
                coinTossHandler.Object,
                createBoardHandler.Object);

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

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