public async Task Should_return_response(Guid playerId, bool isHost, bool isChallenger) { var context = DbContextFactory.CreateTripleTriadContext(); var game = CreateGame(); await context.Games.AddAsync(game); await context.SaveChangesAsync(); var command = new GameView.Request() { GameId = GameId, PlayerId = playerId }; var subject = new GameView.RequestHandler(context); var response = await subject.Handle(command, default); using (new AssertionScope()) { response.GameId.Should().Be(GameId); response.IsHost.Should().Be(isHost); response.IsChallenger.Should().Be(isChallenger); response.PlayerId.Should().Be(playerId); } }
public void Good_request_should_not_throw(GameView.Request request) { var subject = new GameView.Validator(); Func <Task> action = async() => await subject.Process(request, default); action.Should().NotThrow <ValidationException>(); }
public async Task Should_queue_notification(bool isHost, bool isChallenger) { var backgroundTaskQueue = new Mock <IBackgroundTaskQueue>(); backgroundTaskQueue .Setup(x => x.QueueBackgroundTask( It.IsAny <object>())); var subject = new GameView.BackgroundEnqueuer( backgroundTaskQueue.Object); var request = new GameView.Request { GameId = GameId, PlayerId = PlayerId }; var response = new GameView.Response { GameId = GameId, IsHost = isHost, IsChallenger = isChallenger, PlayerId = PlayerId }; await subject.Process(request, response); backgroundTaskQueue.Verify( x => x.QueueBackgroundTask( It.Is <UserNotification>( y => y.GameId == GameId && y.UserId == PlayerId))); }
public void Should_throw_GameNotFoundException(Guid playerId) { var gameId = 1; var context = DbContextFactory.CreateTripleTriadContext(); var command = new GameView.Request() { GameId = gameId, PlayerId = playerId }; var subject = new GameView.RequestHandler(context); Func <Task> act = async() => await subject.Handle(command, default); act.Should() .Throw <GameNotFoundException>() .Where(e => e.GameId == gameId); }
public async Task <IActionResult> View(int gameId) { var playerId = base.HttpContext.GetPlayerId(); var request = new GameView.Request() { GameId = gameId, PlayerId = playerId }; var response = await this.mediator.Send(request, default); return(base.Json(new { IsHost = response.IsHost, IsChallenger = response.IsChallenger })); }