Esempio n. 1
0
        public void Validate_GivenValidModelWithBaselineCalculationHasSpecificationThatDoesNotExist_ValidIsFalse()
        {
            //Arrange
            CalculationEditModel model = CreateModel();

            model.CalculationType = CalculationType.Baseline;

            ISpecificationsRepository specsRepo     = CreateSpecificationsRepository(false);
            Specification             specification = null;

            specsRepo
            .GetSpecificationById(specificationId)
            .Returns(specification);

            CalculationEditModelValidator validator = CreateValidator(specsRepo);

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

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

            IEnumerable <string> expectedErrors = new[] { "Specification not found", "Unable to find Allocation Line with provided ID" };

            result.Errors.Count().Should().Be(expectedErrors.Count());
            foreach (string error in expectedErrors)
            {
                result.Errors.Count(e => e.ErrorMessage == error).Should().Be(1);
            }
        }
Esempio n. 2
0
        public void Validate_GivenNameAlreadyExists_ValidIsFalse()
        {
            //Arrange
            CalculationEditModel model = CreateModel();

            ISpecificationsRepository repository = CreateSpecificationsRepository(true);

            Specification specification = new Specification()
            {
                Current = new SpecificationVersion()
            };

            repository
            .GetSpecificationById(specificationId)
            .Returns(specification);

            ICalculationsRepository calculationsRepository = Substitute.For <ICalculationsRepository>();

            calculationsRepository
            .IsCalculationNameValid(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(false);

            CalculationEditModelValidator validator = CreateValidator(repository, calculationsRepository);

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

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

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

            result
            .Errors
            .Single()
            .ErrorMessage
            .Should()
            .Be("Calculation with the same generated source code name already exists in this specification");

            calculationsRepository
            .Received(1)
            .IsCalculationNameValid(specificationId, name, calculationId);
        }
Esempio n. 3
0
        public void ValidateWithSpecificationAndFundingStream_ValidatesAsExpected(CalculationEditModel calculationEditModel,
                                                                                  Specification specification,
                                                                                  IEnumerable <FundingStream> fundingStreams,
                                                                                  bool expectedResult,
                                                                                  IEnumerable <string> expectedErrors)
        {
            //Arrange
            ISpecificationsRepository specsRepo = CreateSpecificationsRepository(false);

            specsRepo
            .GetSpecificationById(specificationId)
            .Returns(specification);

            specsRepo
            .GetFundingStreams()
            .Returns(fundingStreams);

            CalculationEditModelValidator validator = CreateValidator(specsRepo);

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

            // Assert
            result
            .IsValid
            .Should()
            .Be(expectedResult);

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

            foreach (string error in expectedErrors)
            {
                result
                .Errors
                .Count(e => e.ErrorMessage == error)
                .Should()
                .Be(1, $"Error message collection should have included '{error}'");
            }
        }