示例#1
0
        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");
        }
示例#2
0
        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");
        }
示例#3
0
        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");
        }
示例#4
0
        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");
        }
示例#5
0
        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.");
        }
示例#6
0
        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");
        }
示例#7
0
        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");
        }
示例#8
0
        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");
        }
示例#9
0
        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");
        }