public async Task TaskService_FindAsync_InputInvalid_Should_ReturnNull() { var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockTaskRepository = new MockTaskRepository().MockFindByIdAsyncInvalid(); var taskService = new TaskService(mockTaskRepository.Object, mockUnitOfWork.Object); var results = await taskService.FindAsync(1); Assert.IsNull(results); mockTaskRepository.VerifyFindByIdAsync(Times.Once()); }
public async Task TaskService_FindAsync_Should_ReturnTask() { var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockTaskRepository = new MockTaskRepository().MockFindByIdAsync(Task.FromResult(Generics.Task)); var taskService = new TaskService(mockTaskRepository.Object, mockUnitOfWork.Object); var results = await taskService.FindAsync(1); Assert.IsNotNull(results); mockTaskRepository.VerifyFindByIdAsync(Times.Once()); }
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()); }