示例#1
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);
        }
示例#2
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);
            }
        }
示例#3
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);
        }
示例#4
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);
        }