コード例 #1
0
        public async Task PutCategoryExpenses_ShouldReturnBadRequestWhenObjectIsNull()
        {
            // Arrange
            expectedIdOfCategoryExpense = 1;
            var controller = new CategoryExpenseController(null);

            // Act
            var objectResult = await controller.Edit(expectedIdOfCategoryExpense, null) as ObjectResult;

            // Assert
            Assert.AreEqual(400, objectResult.StatusCode, "CategoryExpense StatusCode400 does not works. Method put. Object cannot be empty");
        }
コード例 #2
0
        public async Task PostCategoryExpenses_ShouldNotCreateCategoryExpense()
        {
            // Arrange
            mockCategoryExpenseService.Setup(repo => repo.AddCategoryExpense(It.IsAny <List <Models.CategoryExpense> >())).Returns(Task.FromResult(false));
            var controller = new CategoryExpenseController(mockCategoryExpenseService.Object);

            // Act
            var objectResult = await controller.Post(categoryExpenseListObj) as ObjectResult;

            // Assert
            Assert.AreEqual(500, objectResult.StatusCode, "CategoryExpense StatusCode500 does not works. Method post");
        }
コード例 #3
0
        public async Task PostCategoryExpenses_ShouldReturnBadRequestObjectIsNull()
        {
            // Arrange
            var categoryExpenseList = new List <Models.CategoryExpense>();
            var controller          = new CategoryExpenseController(null);

            // Act
            var badRequestResult = await controller.Post(categoryExpenseList) as BadRequestResult;

            // Assert
            Assert.AreEqual(400, badRequestResult.StatusCode, "Badrequest does not works. Method post");
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        public async Task PutCategoryExpenses_ShouldReturnStatusCode204WhenObjectIsUpdated()
        {
            // Arrange
            mockCategoryExpenseService.Setup(repo => repo.EditCategoryExpense(It.IsAny <Models.CategoryExpense>(), It.IsAny <int>())).Returns(Task.FromResult(true));
            var controller = new CategoryExpenseController(mockCategoryExpenseService.Object);

            expectedIdOfCategoryExpense = 1;

            // Act
            var noContentResult = await controller.Edit(expectedIdOfCategoryExpense, categoryExpenseModelObj) as NoContentResult;

            // Assert
            Assert.AreEqual(204, noContentResult.StatusCode, "CategoryExpense method put. Object was not updated.");
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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");
        }
コード例 #8
0
        public async Task GetByIdCategoryExpenses_ShouldReturnOneCategoryExpenseAsync()
        {
            // Arrange
            var categoryExpenseTestIndex = 1;
            var categoryExpenseTest      = GetCategoryExpensesList().ToList() [categoryExpenseTestIndex];

            mockCategoryExpenseService.Setup(repo => repo.GetAsync(expectedIdOfCategoryExpense))
            .Returns(Task.FromResult(categoryExpenseTest));

            var controller = new CategoryExpenseController(mockCategoryExpenseService.Object);

            // Act
            var okObjectResult = await controller.Get(expectedIdOfCategoryExpense) as OkObjectResult;

            var result = okObjectResult.Value as Entities.CategoryExpense;

            // Assert
            Assert.NotNull(okObjectResult, "Ok(ObjectResult) is null");
            Assert.AreEqual(categoryExpenseObj.Id, result.Id, "Id is not equal");
        }
コード例 #9
0
        public async Task GetAllCategoryExpenses_ShouldReturnAllCategoryExpensesAsync()
        {
            // Arrange
            var expectedNumberOfCategoryExpensesList = 4;
            var categoryExpensesList = GetCategoryExpensesList();

            mockCategoryExpenseService.Setup(repo => repo.GetAllAsync()).Returns(Task.FromResult(categoryExpensesList));

            var controller = new CategoryExpenseController(mockCategoryExpenseService.Object);

            // Act
            var okObjectResult = await controller.GetAll() as OkObjectResult;

            var result = okObjectResult.Value as List <Entities.CategoryExpense>;

            // Assert
            Assert.NotNull(okObjectResult, "Ok(ObjectResult) is null");
            Assert.AreEqual(expectedNumberOfCategoryExpensesList, result.Count(), "Expected Number Of CategoryExpenses List");
            Assert.AreEqual(categoryExpenseObj.Id, result[1].Id, "Id is not equal");
        }