public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "list/{id}")] HttpRequest req, string id) { try { var command = new DeleteListCommand { Id = id }; var handler = Container.GetInstance <ICommandHander <DeleteListCommand> >(); await handler.Execute(command); return(new NoContentResult()); } catch (ResourceNotFoundException ex) { Container.GetInstance <TelemetryClient>().TrackException(ex); return(new NotFoundResult()); } catch (Exception ex) { Container.GetInstance <TelemetryClient>().TrackException(ex); return(new InternalServerErrorResult()); } }
private async Task <bool> HandleAsync(DeleteListCommand command) { var list = await this.context.Lists.FindAsync(command.Id); this.context.Lists.Remove(list); var count = await this.context.SaveChangesAsync(); return(count >= 0); }
public async Task <IActionResult> Delete([FromBody] Guid id) { var user = await _userManagerWrapper.FindByNameAsync(User.Identity.Name); var deletelistCommand = new DeleteListCommand { Id = id, UserId = user.Id }; await _endpointInstance.Send("LifeManager.Lists", deletelistCommand).ConfigureAwait(false); return(Ok()); }
public void Execute_ReturnsCompletedTaskOnSuccess() { var repo = new Mock <IListRepository>(); var id = Guid.NewGuid().ToString(); var command = new DeleteListCommand { Id = id }; var handler = new DeleteListCommandHandler(repo.Object); repo.Setup(r => r.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var result = handler.Execute(command); Assert.AreEqual(Task.CompletedTask, result); }
public async Task HandleDeleteCommand_ShouldCallListServiceDelete() { // Data var deleteListCommand = new DeleteListCommand { Id = Guid.NewGuid(), UserId = "username" }; // Setup _mockListService.Setup(x => x.DeleteList(deleteListCommand.Id, deleteListCommand.UserId)).Returns(Task.CompletedTask).Verifiable(); // Test var handler = new ListsEventHandler(_mockListService.Object); await handler.Handle(deleteListCommand, _mockMessageContext.Object); // Analysis _mockListService.Verify(); }
public async Task Handle(DeleteListCommand message, IMessageHandlerContext context) { await _listService.DeleteList(message.Id, message.UserId); }
public async Task <bool> DeleteList([FromBody] DeleteListCommand command) { return(await commandProcessor.ProcessAsync(command)); }