public async Task DeleteByIdCategoryExpenses_ShouldReturnNotFoundWhenGetAsync() { // Arrange mockCategoryExpenseService.Setup(repo => repo.RemoveAsync(categoryExpenseObj)).Returns(Task.FromResult(true)); var controller = new CategoryExpenseController(mockCategoryExpenseService.Object); // Act var notFoundResult = await controller.Delete(expectedIdOfCategoryExpense) as NotFoundResult; // Assert Assert.AreEqual(404, notFoundResult.StatusCode, "Not found result, not works. Method Delete"); }
public async Task DeleteByIdCategoryExpenses_ShouldReturnInternalServerErrorCategoryExpense() { // Arrange mockCategoryExpenseService.Setup(repo => repo.GetAsync(expectedIdOfCategoryExpense)).Returns(Task.FromResult(categoryExpenseObj)); mockCategoryExpenseService.Setup(repo => repo.RemoveAsync(categoryExpenseObj)).Returns(Task.FromResult(false)); var controller = new CategoryExpenseController(mockCategoryExpenseService.Object); // Act var noContentResult = await controller.Delete(expectedIdOfCategoryExpense) as ObjectResult; // Assert Assert.NotNull(noContentResult, "GetAsync returns null object in method Delete"); Assert.AreEqual(500, noContentResult.StatusCode, "Internal server error in method Delete"); }
public async Task DeleteByIdCategoryExpenses_ShouldDeleteOneCategoryExpense() { // Arrange var categoryExpenseTestIndex = 1; var categoryExpenseTest = GetCategoryExpensesList().ToList() [categoryExpenseTestIndex]; mockCategoryExpenseService.Setup(repo => repo.GetAsync(expectedIdOfCategoryExpense)).Returns(Task.FromResult(categoryExpenseObj)); mockCategoryExpenseService.Setup(repo => repo.RemoveAsync(categoryExpenseObj)).Returns(Task.FromResult(true)); var controller = new CategoryExpenseController(mockCategoryExpenseService.Object); // Act var noContentResult = await controller.Delete(expectedIdOfCategoryExpense) as NoContentResult; // Assert Assert.NotNull(noContentResult, "noContentResult is null"); Assert.AreEqual(noContentResult.StatusCode, 204, "delete is not works"); }