public async Task PutCategoryIncomes_ShouldReturnBadRequestWhenObjectIsNull() { // Arrange expectedIdOfCategoryIncome = 1; var controller = new CategoryIncomeController(null); // Act var objectResult = await controller.Edit(expectedIdOfCategoryIncome, null) as ObjectResult; // Assert Assert.AreEqual(400, objectResult.StatusCode, "CategoryIncome StatusCode400 does not works. Method put. Object cannot be empty"); }
public async Task PostCategoryIncomes_ShouldNotCreateCategoryIncome() { // Arrange mockCategoryIncomeService.Setup(repo => repo.AddCategoryIncome(It.IsAny <List <Models.CategoryIncome> >())).Returns(Task.FromResult(false)); var controller = new CategoryIncomeController(mockCategoryIncomeService.Object); // Act var objectResult = await controller.Post(categoryIncomeListObj) as ObjectResult; // Assert Assert.AreEqual(500, objectResult.StatusCode, "CategoryIncome StatusCode500 does not works. Method post"); }
public async Task PostCategoryIncomes_ShouldReturnBadRequestObjectIsNull() { // Arrange var categoryIncomeList = new List <Models.CategoryIncome>(); var controller = new CategoryIncomeController(null); // Act var badRequestResult = await controller.Post(categoryIncomeList) as BadRequestResult; // Assert Assert.AreEqual(400, badRequestResult.StatusCode, "Badrequest does not works. Method post"); }
public async Task DeleteByIdCategoryIncomes_ShouldReturnNotFoundWhenGetAsync() { // Arrange mockCategoryIncomeService.Setup(repo => repo.RemoveAsync(categoryIncomeObj)).Returns(Task.FromResult(true)); var controller = new CategoryIncomeController(mockCategoryIncomeService.Object); // Act var notFoundResult = await controller.Delete(expectedIdOfCategoryIncome) as NotFoundResult; // Assert Assert.AreEqual(404, notFoundResult.StatusCode, "Not found result, not works. Method Delete"); }
public async Task PutCategoryIncomes_ShouldReturnStatusCode204WhenObjectIsUpdated() { // Arrange mockCategoryIncomeService.Setup(repo => repo.EditCategoryIncome(It.IsAny <Models.CategoryIncome>(), It.IsAny <int>())).Returns(Task.FromResult(true)); var controller = new CategoryIncomeController(mockCategoryIncomeService.Object); expectedIdOfCategoryIncome = 1; // Act var noContentResult = await controller.Edit(expectedIdOfCategoryIncome, categoryIncomeModelObj) as NoContentResult; // Assert Assert.AreEqual(204, noContentResult.StatusCode, "CategoryIncome method put. Object was not updated."); }
public async Task DeleteByIdCategoryIncomes_ShouldReturnInternalServerErrorCategoryIncome() { // Arrange mockCategoryIncomeService.Setup(repo => repo.GetAsync(expectedIdOfCategoryIncome)).Returns(Task.FromResult(categoryIncomeObj)); mockCategoryIncomeService.Setup(repo => repo.RemoveAsync(categoryIncomeObj)).Returns(Task.FromResult(false)); var controller = new CategoryIncomeController(mockCategoryIncomeService.Object); // Act var noContentResult = await controller.Delete(expectedIdOfCategoryIncome) 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 DeleteByIdCategoryIncomes_ShouldDeleteOneCategoryIncome() { // Arrange var categoryIncomeTestIndex = 1; var categoryIncomeTest = GetCategoryIncomesList().ToList() [categoryIncomeTestIndex]; mockCategoryIncomeService.Setup(repo => repo.GetAsync(expectedIdOfCategoryIncome)).Returns(Task.FromResult(categoryIncomeObj)); mockCategoryIncomeService.Setup(repo => repo.RemoveAsync(categoryIncomeObj)).Returns(Task.FromResult(true)); var controller = new CategoryIncomeController(mockCategoryIncomeService.Object); // Act var noContentResult = await controller.Delete(expectedIdOfCategoryIncome) as NoContentResult; // Assert Assert.NotNull(noContentResult, "noContentResult is null"); Assert.AreEqual(noContentResult.StatusCode, 204, "delete is not works"); }
public async Task GetByIdCategoryIncomes_ShouldReturnOneCategoryIncomeAsync() { // Arrange var categoryIncomeTestIndex = 1; var categoryIncomeTest = GetCategoryIncomesList().ToList() [categoryIncomeTestIndex]; mockCategoryIncomeService.Setup(repo => repo.GetAsync(expectedIdOfCategoryIncome)) .Returns(Task.FromResult(categoryIncomeTest)); var controller = new CategoryIncomeController(mockCategoryIncomeService.Object); // Act var okObjectResult = await controller.Get(expectedIdOfCategoryIncome) as OkObjectResult; var result = okObjectResult.Value as Entities.CategoryIncome; // Assert Assert.NotNull(okObjectResult, "Ok(ObjectResult) is null"); Assert.AreEqual(categoryIncomeObj.Id, result.Id, "Id is not equal"); }
public async Task GetAllCategoryIncomes_ShouldReturnAllCategoryIncomesAsync() { // Arrange var expectedNumberOfCategoryIncomesList = 4; var categoryIncomesList = GetCategoryIncomesList(); mockCategoryIncomeService.Setup(repo => repo.GetAllAsync()).Returns(Task.FromResult(categoryIncomesList)); var controller = new CategoryIncomeController(mockCategoryIncomeService.Object); // Act var okObjectResult = await controller.GetAll() as OkObjectResult; var result = okObjectResult.Value as List <Entities.CategoryIncome>; // Assert Assert.NotNull(okObjectResult, "Ok(ObjectResult) is null"); Assert.AreEqual(expectedNumberOfCategoryIncomesList, result.Count(), "Expected Number Of CategoryIncomes List"); Assert.AreEqual(categoryIncomeObj.Id, result[1].Id, "Id is not equal"); }