Beispiel #1
0
        public async Task ApproveAllCalculations_GivenApproveAllCalculationsReturnsBadRequest_ThrowsInvalidOperationException()
        {
            //Arrange

            string specificationId             = "abc123";
            ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>();

            calcsClient
            .QueueApproveAllSpecificationCalculations(Arg.Is(specificationId))
            .Returns(new ApiResponse <Job>(HttpStatusCode.BadRequest));

            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            IAuthorizationHelper authorizationHelper = Substitute.For <IAuthorizationHelper>();

            authorizationHelper.DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Is(specificationId), Arg.Is(SpecificationActionTypes.CanApproveAllCalculations))
            .Returns(true);

            CalculationController controller = CreateCalculationController(calcsClient, mapper, authorizationHelper, resultsApiClient);

            // Act
            Action a = new Action(() =>
            {
                IActionResult result = controller.ApproveAllCalculations(specificationId).Result;
            });

            // Assert
            a.Should().Throw <InvalidOperationException>();
        }
Beispiel #2
0
        public async Task ApproveAllCalculations_GivenApproveAllCalculationsReturnsJob_ReturnsOK()
        {
            //Arrange

            string specificationId = "abc123";
            string jobId           = "job123";

            Job job = new Job {
                Id = jobId
            };

            ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>();

            calcsClient
            .QueueApproveAllSpecificationCalculations(Arg.Is(specificationId))
            .Returns(new ApiResponse <Job>(HttpStatusCode.OK, job));

            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            IAuthorizationHelper authorizationHelper = Substitute.For <IAuthorizationHelper>();

            authorizationHelper.DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Is(specificationId), Arg.Is(SpecificationActionTypes.CanApproveAllCalculations))
            .Returns(true);

            CalculationController controller = CreateCalculationController(calcsClient, mapper, authorizationHelper, resultsApiClient);

            // Act
            IActionResult result = await controller.ApproveAllCalculations(specificationId);

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            OkObjectResult okObjectResult = result as OkObjectResult;

            okObjectResult.Should().NotBeNull();
            okObjectResult.Value.Should().NotBeNull();
            okObjectResult.Value.Should().BeOfType <Job>();

            Job actualJob = okObjectResult.Value as Job;

            actualJob.Id.Should().Be(jobId);
        }
Beispiel #3
0
        public async Task ApproveAllCalculations_GivenUserDoesNotHaveCanApproveAllCalculationPermission_Returns403()
        {
            //Arrange

            string specificationId             = "abc123";
            ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>();
            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            IAuthorizationHelper authorizationHelper = Substitute.For <IAuthorizationHelper>();

            authorizationHelper.DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Is(specificationId), Arg.Is(SpecificationActionTypes.CanApproveAllCalculations))
            .Returns(false);

            CalculationController controller = CreateCalculationController(calcsClient, mapper, authorizationHelper, resultsApiClient);

            // Act
            IActionResult result = await controller.ApproveAllCalculations(specificationId);

            // Assert
            result.Should().BeOfType <ForbidResult>();
        }