public async void ShouldDeleteGame() { //arrange BoardContext context = new ContextBuilder().BuildClean(); Game game = new GameBuilder(context) .Build(); var newGame = context.Add(game); context.SaveChanges(); //act var command = new DeleteGameCommand(); command.Id = newGame.Entity.Id; var handler = new DeleteGameCommand.Handler(context); var result = await handler.Handle(command, default); //assert var deletedGame = context.Games .Where(x => x.Id == newGame.Entity.Id) .FirstOrDefault(); Assert.Null(deletedGame); }
public async Task <ActionResult> DeleteGameAsync(Guid gameId) { var command = new DeleteGameCommand(gameId); await _deleteGameCommandHandler.HandleAsync(command); return(Ok()); }
public async Task ShouldDeleteGame() { GenerateMock(); var gameMock = new Mock <Game>(); _gameRepositoryMock .Setup(x => x.FindAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(gameMock.Object); _gameRepositoryMock .Setup(x => x.Delete(It.IsAny <Game>())); _gameRepositoryMock .Setup(x => x.UnitOfWork.SaveAsync(It.IsAny <CancellationToken>())); var handler = GetHandler(); var command = new DeleteGameCommand(Guid.NewGuid()); await handler.Handle(command, default); _gameRepositoryMock .Verify(x => x.FindAsync(It.Is <Guid>(f => f.Equals(command.Id)), It.IsAny <CancellationToken>())); _gameRepositoryMock .Verify(x => x.Delete(It.Is <Game>(f => f.Equals(gameMock.Object)))); _gameRepositoryMock.Verify(x => x.UnitOfWork.SaveAsync(It.IsAny <CancellationToken>())); }
public async Task <IActionResult> Delete(Guid id) { var command = new DeleteGameCommand { Id = id }; var result = _deleteHandler.Handle(command); return(await Response(result, _handler.Notifications)); }
public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException() { // Arrange var sut = new DeleteGameCommandHandler(this.deletableEntityRepository, this.mediatorMock.Object); var command = new DeleteGameCommand() { Id = 90125, GameName = It.IsAny <string>() }; // Act & Assert await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>())); }
public async Task ShouldDeleteGame() { var entity = await FindAsync <IGameRepository, Game>(_entity.Id); entity.Should().NotBeNull(); entity.Name.Should().Be("Bugsnax"); var cmd = new DeleteGameCommand(_entity.Id); await SendAsync(cmd); entity = await FindAsync <IGameRepository, Game>(_entity.Id); entity.Should().BeNull(); }
public void ShouldThrowMessageGameNotFound() { GenerateMock(); _gameRepositoryMock .Setup(x => x.FindAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())); var handler = GetHandler(); var command = new DeleteGameCommand(Guid.NewGuid()); FluentActions.Invoking(async() => await handler.Handle(command, default)) .Should() .Throw <NotFoundException>().WithMessage("Game not found!"); _gameRepositoryMock .Verify(x => x.FindAsync(It.Is <Guid>(f => f.Equals(command.Id)), It.IsAny <CancellationToken>())); }
public async Task Handle_GivenValidRequest_ShouldThrowDeleteFailureException() { // Arrange var sut = new DeleteGameCommandHandler(this.deletableEntityRepository, this.mediatorMock.Object); var gameId = 2; var desiredEntity = this.deletableEntityRepository .AllAsNoTracking() .SingleOrDefault(g => g.Id == gameId); this.deletableEntityRepository.Delete(desiredEntity); await this.deletableEntityRepository.SaveChangesAsync(); var command = new DeleteGameCommand() { Id = gameId, GameName = It.IsAny <string>() }; // Act & Assert await Should.ThrowAsync <DeleteFailureException>(sut.Handle(command, It.IsAny <CancellationToken>())); }
public async Task Handle_GivenValidRequest_ShouldMarkEntityAsDeleted() { // Arrange var gameId = 2; var deleteGameCommand = new DeleteGameCommand() { Id = gameId, GameName = It.IsAny <string>() }; var sut = new DeleteGameCommandHandler(deletableEntityRepository, this.mediatorMock.Object); // Act var id = await sut.Handle(deleteGameCommand, It.IsAny <CancellationToken>()); // Assert var deletedGameEntity = deletableEntityRepository .AllAsNoTrackingWithDeleted() .SingleOrDefault(x => x.Id == gameId); deletedGameEntity.IsDeleted.ShouldBe(true); id.ShouldBe(gameId); this.mediatorMock.Verify(x => x.Publish(It.IsAny <GameDeletedNotification>(), It.IsAny <CancellationToken>())); }
public async Task <ValidationResult> Delete(Guid id) { var deleteCommand = new DeleteGameCommand(id); return(await _mediator.SendCommand(deleteCommand)); }
public void Delete(int id, int userId) { var deleteGameCommand = new DeleteGameCommand(id, userId); _bus.SendCommand(deleteGameCommand); }
public async Task Delete([FromBody] DeleteGameCommand command) { await CommandPublisher.ExecuteAsync(command); }
public async Task <ActionResult <string> > DeleteGame([FromBody] DeleteGameCommand command) { var result = await Mediator.Send(command); return(new JsonResult(result)); }
public async Task <IActionResult> Delete(DeleteGameCommand command) { await this.Mediator.Send(command); return(this.RedirectToAction(nameof(Index))); }