Example #1
0
        public void Validate_GivenCoreProviderVersionUpdatesUseLatestForNonFDZProviderSource_ValidIsFalse()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            model.CoreProviderVersionUpdates = CoreProviderVersionUpdates.UseLatest;

            ISpecificationsRepository repository        = CreateSpecificationsRepository();
            IPoliciesApiClient        policiesApiClient = CreatePoliciesApiClient(ProviderSource.CFS);

            SpecificationCreateModelValidator validator = CreateValidator(repository, policiesApiClient: policiesApiClient);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);

            result
            .Errors.Select(x => x.ErrorMessage)
            .Should()
            .Contain("CoreProviderVersionUpdates - UseLatest is not valid for provider source - CFS");
        }
Example #2
0
        public void Validate_GivenEmptyProviderSnapshotId_ValidIsFalse()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            IPoliciesApiClient policiesApiClient = Substitute.For <IPoliciesApiClient>();

            policiesApiClient
            .GetFundingPeriodById(Arg.Any <string>())
            .Returns(new ApiResponse <PolicyModels.FundingPeriod>(HttpStatusCode.OK, new PolicyModels.FundingPeriod()));

            policiesApiClient
            .GetFundingConfiguration(Arg.Any <string>(), Arg.Any <string>())
            .Returns(new ApiResponse <PolicyModels.FundingConfig.FundingConfiguration>(HttpStatusCode.OK, new PolicyModels.FundingConfig.FundingConfiguration {
                ProviderSource = ProviderSource.FDZ
            }));

            SpecificationCreateModelValidator validator = CreateValidator(policiesApiClient: policiesApiClient);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);
        }
Example #3
0
        public void Validate_GivenFundingPeriodId_FundingPeriodDoesntExist_ValidIsFalse()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            IPoliciesApiClient policiesApiClient = Substitute.For <IPoliciesApiClient>();

            policiesApiClient
            .GetFundingPeriodById(Arg.Is("1819"))
            .Returns(new ApiResponse <PolicyModels.FundingPeriod>(HttpStatusCode.OK, new PolicyModels.FundingPeriod()));

            policiesApiClient
            .GetFundingConfiguration(Arg.Is(fundingStreamId), Arg.Is(fundingPeriodId))
            .Returns(new ApiResponse <PolicyModels.FundingConfig.FundingConfiguration>(HttpStatusCode.OK, new PolicyModels.FundingConfig.FundingConfiguration()));

            SpecificationCreateModelValidator validator = CreateValidator(policiesApiClient: policiesApiClient);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors.Select(x => x.PropertyName == "FundingPeriodId" && x.ErrorMessage == "Funding period not found")
            .Count()
            .Should()
            .Be(1);
        }
Example #4
0
        public void Validate_GivenValidModel_ValidIsTrue()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            SpecificationCreateModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeTrue();
        }
Example #5
0
        public void Validate_GivenFundingPeriodId_FundingPeriodIsNotEmpty_ValidIsTrue()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();
            //model.FundingPeriodId = string.Empty;
            IPoliciesApiClient policiesApiClient = CreatePoliciesApiClient();

            SpecificationCreateModelValidator validator = CreateValidator(policiesApiClient: policiesApiClient);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeTrue();
        }
Example #6
0
        public void Validate_GivenCoreProviderVersionUpdatesUseLatestForFDZProviderSource_ValidIsTrue()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            model.CoreProviderVersionUpdates = CoreProviderVersionUpdates.UseLatest;
            model.ProviderSnapshotId         = 1;

            ISpecificationsRepository repository        = CreateSpecificationsRepository();
            IPoliciesApiClient        policiesApiClient = CreatePoliciesApiClient(ProviderSource.FDZ);

            SpecificationCreateModelValidator validator = CreateValidator(repository, policiesApiClient: policiesApiClient);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeTrue();
        }
Example #7
0
        public void Validate_GivenEmptyFundingPeriodId_ValidIsFalse()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            model.FundingPeriodId = string.Empty;

            SpecificationCreateModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);
        }
Example #8
0
        public void Validate_GivenProviderVersionIdDoesntExist_ValidIsFalse()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            IProvidersApiClient providersApiClient = CreateProviderApiClient(HttpStatusCode.NotFound);

            SpecificationCreateModelValidator validator = CreateValidator(providersApiClient: providersApiClient);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors.Select(x => x.PropertyName == "ProviderVersionId" && x.ErrorMessage == "Provider version id selected does not exist")
            .Count()
            .Should()
            .Be(1);
        }
Example #9
0
        public void Validate_GivenEmptyProviderVersionId_ValidIsFalse()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            model.ProviderVersionId = string.Empty;

            SpecificationCreateModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors.Select(x => x.PropertyName == "ProviderVersionId" && x.ErrorCode == "NotEmptyValidator")
            .Count()
            .Should()
            .Be(1);
        }
Example #10
0
        public void Validate_GivenNameAlreadyExists_ValidIsFalse()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            ISpecificationsRepository repository = CreateSpecificationsRepository(true);

            SpecificationCreateModelValidator validator = CreateValidator(repository);

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result
            .Errors
            .Count
            .Should()
            .Be(1);
        }
Example #11
0
        public void Validate_GivenEmptyDescription_ValidIsTrue()
        {
            //Arrange
            SpecificationCreateModel model = CreateModel();

            model.Description = string.Empty;

            SpecificationCreateModelValidator validator = CreateValidator();

            //Act
            ValidationResult result = validator.Validate(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeTrue();

            result
            .Errors
            .Count
            .Should()
            .Be(0);
        }