public async void DeleteToDoListItem_ReturnsNoContentResult() { //Arrange var httpContext = new DefaultHttpContext(); DeleteToDoItemCommand command = new DeleteToDoItemCommand(); var mediator = new Mock <IMediator>(); mediator.Setup(m => m.Send(It.IsAny <DeleteToDoItemCommand>(), new System.Threading.CancellationToken())); var controller = new ToDoListController(mediator.Object) { ControllerContext = new ControllerContext() { HttpContext = httpContext, } }; //ACT var result = await controller.DeleteToDoItem(command); //ASSERT Assert.IsType <NoContentResult>(result); }
public async void DeleteItemHandler_IsVerifiable_ReturnsNotNullResult() { var itemToDelete = new ToDoListItem { Id = Guid.Parse("7a73db1a-f0a8-4937-a229-b9787ea2c54f"), Completed = true, Name = "test" }; //Arrange var _serviceContextMock = new Mock <IServiceContext>(); _serviceContextMock.Setup(a => a.DeleteToDoItem(It.IsAny <ToDoListItem>())).Verifiable(); _serviceContextMock.Setup(a => a.GetToDoListItemAsync(itemToDelete.Id)).Verifiable(); DeleteToDoItemCommand command = new DeleteToDoItemCommand(); command.Id = Guid.NewGuid(); IToDoListRepository _todoListRepository = new ToDoListRepository(_serviceContextMock.Object); DeleteToDoItemHandler handler = new DeleteToDoItemHandler(_todoListRepository, _mapper); //Act var _handler = await handler.Handle(command, new System.Threading.CancellationToken()); //Assert Assert.NotNull(handler); }
public async Task <ActionResult> DeleteItem(int id) { var command = new DeleteToDoItemCommand(id); await _commandHandler.HandleAsync(command); return(Ok()); }
public async Task HandleAsync(DeleteToDoItemCommand message) { var toDoItem = await _uow.ToDoItemRepository.Get(message.Id); if (toDoItem == null) { throw new ArgumentNullException(); } _uow.ToDoItemRepository.Delete(toDoItem); await _uow.Commit(); }