Exemple #1
0
        public async Task EditCalculationStatus_GivenOKResponseFromApi_ReturnsOK()
        {
            //Arrange
            string specificationId = "abc123";
            string calculationId   = "5";

            PublishStatusEditModel model = new PublishStatusEditModel();

            PublishStatusResult publishStatusResult = new PublishStatusResult();

            ValidatedApiResponse <PublishStatusResult> response = new ValidatedApiResponse <PublishStatusResult>(HttpStatusCode.OK, publishStatusResult);

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

            calcsClient
            .UpdatePublishStatus(Arg.Is(calculationId), Arg.Is(model))
            .Returns(response);

            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            IAuthorizationHelper  authorizationHelper = TestAuthHelper.CreateAuthorizationHelperSubstitute(specificationId, SpecificationActionTypes.CanEditCalculations);
            CalculationController controller          = CreateCalculationController(calcsClient, mapper, authorizationHelper);

            // Act
            IActionResult result = await controller.EditCalculationStatus(specificationId, calculationId, model);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .Be(publishStatusResult);
        }
Exemple #2
0
        public async Task EditCalculationStatus_GivenUserDoesNotHaveEditCalculationPermission_Returns403()
        {
            //Arrange
            string specificationId = "abc123";
            string calculationId   = "5";

            PublishStatusEditModel model = new PublishStatusEditModel();

            PublishStatusResult publishStatusResult = new PublishStatusResult();

            ValidatedApiResponse <PublishStatusResult> response = new ValidatedApiResponse <PublishStatusResult>(HttpStatusCode.OK, publishStatusResult);

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

            calcsClient
            .UpdatePublishStatus(Arg.Is(calculationId), Arg.Is(model))
            .Returns(response);

            IMapper mapper = MappingHelper.CreateFrontEndMapper();

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

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

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

            // Act
            IActionResult result = await controller.EditCalculationStatus(specificationId, calculationId, model);

            // Assert
            result.Should().BeOfType <ForbidResult>();
        }
Exemple #3
0
        public void EditCalculationStatus_GivenFailedStatusCode_ThrowsInvalidOperationException()
        {
            //Arrange
            string specificationId = "abc123";
            string calculationId   = "5";

            PublishStatusEditModel model = new PublishStatusEditModel();

            ValidatedApiResponse <PublishStatusResult> response = new ValidatedApiResponse <PublishStatusResult>(HttpStatusCode.BadRequest);

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

            calcsClient
            .UpdatePublishStatus(Arg.Is(calculationId), Arg.Is(model))
            .Returns(response);

            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            IAuthorizationHelper  authorizationHelper = TestAuthHelper.CreateAuthorizationHelperSubstitute(specificationId, SpecificationActionTypes.CanEditCalculations);
            CalculationController controller          = CreateCalculationController(calcsClient, mapper, authorizationHelper);

            // Act
            Func <Task> test = async() => await controller.EditCalculationStatus(specificationId, calculationId, model);

            // Assert
            test
            .Should()
            .Throw <InvalidOperationException>();
        }