Beispiel #1
0
        public async void AddBillableActivityAsync_Returns_NotFound_404_When_Create_With_null_BillableActivity()
        {
            //Configure Repository Mock
            _mockRepository.Setup(repo => repo.AddTAsync(null)).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 SUT method - returns ActionResult<BillableActivity> type
            var actionResult = await controller.AddBillableActivityAsync(new BillableActivity());

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

            var result     = actionResult.Result as NotFoundObjectResult;
            var statusCode = result.StatusCode;
            var message    = result.Value;

            //Assert message
            Assert.Equal("No Billable Activity was created", message);

            //Assert StatusCode
            Assert.Equal(404, statusCode);
        }
Beispiel #2
0
        public async void AddBillableActivityAsync_Creates_One_BillableActivity_Returns_201_And_BA_Created()
        {
            //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 mockRepo return for Add action
            _mockRepository.Setup(repo => repo.AddTAsync(expectedBillableActivity)).ReturnsAsync(1);

            //set repo return for getting the newly created object
            _mockRepository.Setup(repo => repo.GetOneByAsync(ba =>
                                                             ba.Title == expectedBillableActivity.Title &&
                                                             ba.Employee_Id == expectedBillableActivity.Employee_Id &&
                                                             ba.LegalCase_Id == expectedBillableActivity.LegalCase_Id))
            .ReturnsAsync(expectedBillableActivity);

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

            //Call the SUT method
            //returns ActionResult<BillableActivity> type
            var actionResult = await controller.AddBillableActivityAsync(expectedBillableActivity);

            //Get the int result from the posted ActionResult
            var createdResult = actionResult.Result as CreatedResult;
            var statusCode    = createdResult.StatusCode;
            BillableActivityDTO actualBaDTO = createdResult.Value as BillableActivityDTO;

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

            //Validate the return is 1 BillableActivity created
            Assert.Equal(201, statusCode);

            //Validate the actual BillableActivity
            actualBaDTO.Should().BeEquivalentTo(expectedBaDTO, options => options.ComparingByMembers <BillableActivityDTO>());
        }