Beispiel #1
0
        public async void DeleteBillableActivityAsync_Deletes_One_BillableActivity_And_Returns_Number_Of_Deletions(int id)
        {
            //declare a BillableActivity
            var expectedBillableActivity = new BillableActivity
            {
                Id              = 1,
                LegalCase_Id    = 1,
                Employee_Id     = 1,
                Title           = "Billable Activity 1",
                Description     = "this is the Billable Activity 1",
                Price           = 120.50m,
                Start_DateTime  = new DateTime(2020, 06, 20, 9, 30, 00),
                Finish_DateTime = new DateTime(2020, 06, 20, 16, 00, 00)
            };
            BillableActivityDTO expectedBaDTO = _mapper.Map <BillableActivityDTO>(expectedBillableActivity);

            //set repo return for getting the object to delete
            _mockRepository.Setup(repo => repo.GetOneByAsync(ba => ba.Id == id))
            .ReturnsAsync(expectedBillableActivity);

            //set mockRepo return for Delete action
            _mockRepository.Setup(repo => repo.DeleteTAsync(expectedBillableActivity)).ReturnsAsync(1);

            //instantiate the controller, passing the repo object
            var controller = new BillableActivitiesController(_mockRepository.Object, _mapper, _logger);

            //Call the controller method
            var actionResult = await controller.DeleteBillableActivityAsync(id);

            //Get the int result
            var okObjectResult = actionResult.Result as OkObjectResult;
            var statusCode     = okObjectResult.StatusCode;
            int actualDeleted  = (int)okObjectResult.Value;

            //Assert the result
            Assert.NotNull(actionResult);

            //Validate StatusCode
            Assert.Equal(200, statusCode);

            //Validate the number of BAs deleted
            Assert.Equal(1, actualDeleted);
        }
Beispiel #2
0
        public async void DeleteBillableActivityAsync_Returns_NotFound_404_When_Delete_With_null_BillableActivity(int id)
        {
            //declare a BillableActivity
            BillableActivity expectedBillableActivity = null;

            //response error message:
            string expectedResponseMessage = "No data was found for the id";

            //set repo return for getting the object to delete
            _mockRepository.Setup(repo => repo.GetOneByAsync(ba => ba.Id == id))
            .ReturnsAsync(expectedBillableActivity);

            //set mockRepo return for Delete action
            _mockRepository.Setup(repo => repo.DeleteTAsync(expectedBillableActivity)).ReturnsAsync(0);

            //instantiate the controller, and call the method
            var controller = new BillableActivitiesController(_mockRepository.Object, _mapper, _logger);

            //Create Custom ControllerContext and add it to Controller for logging in the Controller in case of error
            controller.ControllerContext = new ControllerContextModel();

            //Call the controller method
            var actionResult = await controller.DeleteBillableActivityAsync(id);

            //Get the int result
            var    notFoundObjectResult  = actionResult.Result as NotFoundObjectResult;
            var    statusCode            = notFoundObjectResult.StatusCode;
            string actualResponseMessage = (string)notFoundObjectResult.Value;

            //Assert the result
            Assert.NotNull(actionResult);

            //Validate StatusCode
            Assert.Equal(404, statusCode);

            //Validate the number of BAs deleted
            Assert.Equal(expectedResponseMessage, actualResponseMessage);
        }