public async Task TaskService_DeleteAsync_Should_DeleteFromRepository() { var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockTaskRepository = new MockTaskRepository() .MockFindByIdAsync(Task.FromResult(Generics.Task)) .MockRemove(); var taskService = new TaskService(mockTaskRepository.Object, mockUnitOfWork.Object); var results = await taskService.DeleteAsync(1); Assert.IsNotNull(results); Assert.IsTrue(results.Success); Assert.IsInstanceOfType(results.Task, typeof(Domain.Models.Task)); mockTaskRepository.VerifyFindByIdAsync(Times.Once()); mockTaskRepository.VerifyRemove(Times.Once()); }
public async Task TaskService_DeleteAsync_InputInvalid_Should_DeleteFromRepository() { var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockTaskRepository = new MockTaskRepository() .MockFindByIdAsync(Task.FromResult(Generics.Task)) .MockRemoveInvalid(); var taskService = new TaskService(mockTaskRepository.Object, mockUnitOfWork.Object); var results = await taskService.DeleteAsync(1); Assert.IsNotNull(results); Assert.IsNull(results.Task); Assert.IsFalse(results.Success); Assert.IsTrue(results.Message.Contains("An error occurred when deleting the task:")); mockTaskRepository.VerifyFindByIdAsync(Times.Once()); mockTaskRepository.VerifyRemove(Times.Once()); }
public async Task TaskService_DeleteAsync_InputNotFound_Should_DeleteFromRepository() { var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockTaskRepository = new MockTaskRepository() .MockFindByIdAsyncInvalid() .MockRemove(); var taskService = new TaskService(mockTaskRepository.Object, mockUnitOfWork.Object); var results = await taskService.DeleteAsync(1); Assert.IsNotNull(results); Assert.IsNull(results.Task); Assert.IsFalse(results.Success); Assert.IsTrue(results.Message == Generics.TaskResponseNotFound); mockTaskRepository.VerifyFindByIdAsync(Times.Once()); mockTaskRepository.VerifyRemove(Times.Never()); }