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); }
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); }
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>(); }
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); }