public async void RemoveAsync_GivenCategoryExistsAndMoreThanOneProject_ReturnsSuccess() { var categoryToDelete = new CategoryDTO { Id = 1, Name = "Category" }; var projectsArray = new ProjectSummaryDTO[] { new ProjectSummaryDTO { Title = "Project1", Category = categoryToDelete }, new ProjectSummaryDTO { Title = "Project2", Category = categoryToDelete } }; categoryRepositoryMock.Setup(c => c.FindAsync(categoryToDelete.Id)).ReturnsAsync(categoryToDelete); projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(projectsArray); using (var logic = new CategoryLogic(categoryRepositoryMock.Object, projectRepositoryMock.Object)) { var response = await logic.RemoveAsync(categoryToDelete); Assert.Equal(ResponseLogic.SUCCESS, response); categoryRepositoryMock.Verify(c => c.FindAsync(categoryToDelete.Id)); categoryRepositoryMock.Verify(c => c.DeleteAsync(It.IsAny <int>()), Times.Never()); projectRepositoryMock.Verify(p => p.ReadAsync()); } }
public async void RemoveAsync_GivenCategoryDoesNotExist_ReturnsNOT_FOUND() { var categoryToDelete = new CategoryDTO { Id = 1, Name = "Category" }; categoryRepositoryMock.Setup(c => c.FindAsync(categoryToDelete.Id)).ReturnsAsync(default(CategoryDTO)); using (var logic = new CategoryLogic(categoryRepositoryMock.Object, projectRepositoryMock.Object)) { var response = await logic.RemoveAsync(categoryToDelete); Assert.Equal(ResponseLogic.NOT_FOUND, response); categoryRepositoryMock.Verify(c => c.FindAsync(categoryToDelete.Id)); categoryRepositoryMock.Verify(c => c.DeleteAsync(It.IsAny <int>()), Times.Never()); projectRepositoryMock.Verify(p => p.ReadAsync(), Times.Never()); } }
public async void RemoveAsync_GivenDatabaseError_ReturnsERROR_DELETING() { var categoryToDelete = new CategoryDTO { Id = 1, Name = "Category" }; categoryRepositoryMock.Setup(c => c.FindAsync(categoryToDelete.Id)).ReturnsAsync(categoryToDelete); categoryRepositoryMock.Setup(c => c.DeleteAsync(categoryToDelete.Id)).ReturnsAsync(false); projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(new ProjectSummaryDTO[] { }); using (var logic = new CategoryLogic(categoryRepositoryMock.Object, projectRepositoryMock.Object)) { var response = await logic.RemoveAsync(categoryToDelete); Assert.Equal(ResponseLogic.ERROR_DELETING, response); categoryRepositoryMock.Verify(c => c.FindAsync(categoryToDelete.Id)); categoryRepositoryMock.Verify(c => c.DeleteAsync(categoryToDelete.Id)); projectRepositoryMock.Verify(p => p.ReadAsync()); } }
public async void RemoveAsync_GivenCategoryExistsAndInNoProjects_ReturnsSuccess() { var categoryToDelete = new CategoryDTO { Id = 1, Name = "Category" }; categoryRepositoryMock.Setup(c => c.FindAsync(categoryToDelete.Id)).ReturnsAsync(categoryToDelete); categoryRepositoryMock.Setup(c => c.DeleteAsync(categoryToDelete.Id)).ReturnsAsync(true); projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(new ProjectSummaryDTO[] { }); using (var logic = new CategoryLogic(categoryRepositoryMock.Object, projectRepositoryMock.Object)) { var response = await logic.RemoveAsync(categoryToDelete); Assert.Equal(ResponseLogic.SUCCESS, response); categoryRepositoryMock.Verify(c => c.FindAsync(categoryToDelete.Id)); categoryRepositoryMock.Verify(c => c.DeleteAsync(categoryToDelete.Id)); projectRepositoryMock.Verify(p => p.ReadAsync()); } }