public async Task AndIsNotNotApplicableThenIsInvalid()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var request = new CreateApprenticeshipRequest
            {
                WageType = WageType.ToBeSpecified,
                WageUnit = fixture.Create <Generator <WageUnit> >().First(unit => unit != WageUnit.NotApplicable)
            };

            var context = GetValidationContextForProperty(request, req => req.WageUnit);

            var validator = fixture.Create <CreateApprenticeshipRequestValidator>();

            var result = await validator.ValidateAsync(context);

            result.IsValid.Should().Be(false);
            result.Errors.First().ErrorCode
            .Should().Be(ErrorCodes.CreateApprenticeship.WageUnit);
            result.Errors.First().ErrorMessage
            .Should().Be("'Wage Unit' should be equal to 'NotApplicable'.");
        }
Exemplo n.º 2
0
        public void ValidateContactDetails(string value, string errorMessage, bool shouldError)
        {
            var request = new CreateApprenticeshipRequest()
            {
                ContactName = value
            };

            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            if (shouldError)
            {
                sut.ShouldHaveValidationErrorFor(req => req.ContactName, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.ContactName)
                .WithErrorMessage(errorMessage);
            }
            else
            {
                sut.ShouldNotHaveValidationErrorFor(req => req.ContactName, request);
            }
        }
Exemplo n.º 3
0
        public async Task AndHasValueThenIsInvalid()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var request = new CreateApprenticeshipRequest
            {
                WageType       = WageType.CustomWageFixed,
                WageTypeReason = fixture.Create <string>()
            };

            var context = GetValidationContextForProperty(request, req => req.WageTypeReason);

            var validator = fixture.Create <CreateApprenticeshipRequestValidator>();

            var result = await validator.ValidateAsync(context).ConfigureAwait(false);

            result.IsValid.Should().Be(false);
            result.Errors.First().ErrorCode
            .Should().Be(ErrorCodes.CreateApprenticeship.WageTypeReason);
            result.Errors.First().ErrorMessage
            .Should().Be("'Wage Type Reason' must be empty.");
        }
Exemplo n.º 4
0
        public void ThenCheckFailingCases(string title, string errorCode, string errorMessage)
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            var request = new CreateApprenticeshipRequest()
            {
                Title = title
            };

            //only validate Title
            var context = GetValidationContextForProperty(request, req => req.Title);

            var result = sut.Validate(context);

            Assert.AreEqual(false, result.IsValid);

            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(errorCode, result.Errors[0].ErrorCode);
            Assert.AreEqual(errorMessage, result.Errors[0].ErrorMessage);
        }
        public async Task AndHasValueThenIsInvalid()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var request = new CreateApprenticeshipRequest
            {
                WageType = WageType.ToBeSpecified,
                MinWage  = fixture.Create <decimal>()
            };

            var context = GetValidationContextForProperty(request, req => req.MinWage);

            var validator = fixture.Create <CreateApprenticeshipRequestValidator>();

            var result = await validator.ValidateAsync(context);

            result.IsValid.Should().Be(false);
            result.Errors.First().ErrorCode
            .Should().Be(ErrorCodes.CreateApprenticeship.MinWage);
            result.Errors.First().ErrorMessage
            .Should().Be("'Min Wage' must be empty.");
        }
Exemplo n.º 6
0
        public void ValidateDesiredSkills(string value, string errorMessage, bool shouldError)
        {
            var request = new CreateApprenticeshipRequest
            {
                DesiredSkills = value
            };

            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            if (shouldError)
            {
                sut.Validate(request);
                sut.ShouldHaveValidationErrorFor(req => req.DesiredSkills, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.DesiredSkills)
                .WithErrorMessage(errorMessage);
            }
            else
            {
                sut.ShouldNotHaveValidationErrorFor(req => req.DesiredSkills, request);
            }
        }
        public async Task AndLessThanMinWageThenIsInvalid()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var request = new CreateApprenticeshipRequest
            {
                WageType = WageType.CustomWageRange,
                MinWage  = 50m,
                MaxWage  = 49.99m
            };

            var context = GetValidationContextForProperty(request, req => req.MaxWage);

            var validator = fixture.Create <CreateApprenticeshipRequestValidator>();

            var result = await validator.ValidateAsync(context);

            result.IsValid.Should().Be(false);
            result.Errors.First().ErrorCode
            .Should().Be(ErrorCodes.CreateApprenticeship.MaxWage);
            result.Errors.First().ErrorMessage
            .Should().Be(ErrorMessages.CreateApprenticeship.MaxWageCantBeLessThanMinWage);
        }
Exemplo n.º 8
0
        public void ValidateProviderUkprn(int value, bool shouldBeValid, string errorMessage)
        {
            var request = new CreateApprenticeshipRequest()
            {
                ProviderUkprn = value
            };

            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            if (shouldBeValid)
            {
                sut.ShouldNotHaveValidationErrorFor(r => r.ProviderUkprn, request);
            }
            else
            {
                var result = sut.ShouldHaveValidationErrorFor(r => r.ProviderUkprn, request)
                             .WithErrorCode(ErrorCodes.CreateApprenticeship.ProviderUkprn)
                             .WithErrorMessage(errorMessage);
                result.Count().Should().Be(1);
            }
        }
Exemplo n.º 9
0
        public void ValidateDurationType(DurationType value, string errorMessage, bool shouldError)
        {
            var request = new CreateApprenticeshipRequest
            {
                DurationType = value
            };
            var sut = new Fixture().Customize(new AutoMoqCustomization())
                      .Create <CreateApprenticeshipRequestValidator>();

            sut.Validate(request);

            if (shouldError)
            {
                sut.ShouldHaveValidationErrorFor(req => req.DurationType, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.DurationType)
                .WithErrorMessage(errorMessage);
            }
            else
            {
                sut.ShouldNotHaveValidationErrorFor(req => req.DurationType, request);
            }
        }
Exemplo n.º 10
0
        public async Task AndCalculatorThrowsException_ThenReturnsValidationResult()
        {
            var request = new CreateApprenticeshipRequest
            {
                WageType          = WageType.CustomWageFixed,
                FixedWage         = _fixture.Create <decimal>(),
                WageUnit          = _fixture.CreateAnyWageUnitOtherThanNotApplicable(),
                ExpectedStartDate = _fixture.CreateFutureDateTime(),
                HoursPerWeek      = _fixture.Create <double>()
            };
            var context = GetValidationContextForProperty(request, req => req.FixedWage);

            _mockCalculator
            .Setup(calculator => calculator.Calculate(It.IsAny <decimal>(), It.IsAny <WageUnit>(), It.IsAny <decimal>()))
            .Throws <ArgumentOutOfRangeException>();

            var result = await _validator.ValidateAsync(context).ConfigureAwait(false);

            result.IsValid.Should().Be(false);
            result.Errors.First().ErrorCode
            .Should().Be(ErrorCodes.CreateApprenticeship.FixedWage);
        }
Exemplo n.º 11
0
        public void ThenValidateEmployerWebsite(string url, bool isValid, string errorMessage)
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            var request = new CreateApprenticeshipRequest()
            {
                EmployerWebsiteUrl = url
            };

            var context = GetValidationContextForProperty(request, req => req.EmployerWebsiteUrl);

            var result = sut.Validate(context);

            Assert.AreEqual(isValid, result.IsValid);

            if (!isValid)
            {
                Assert.AreEqual(ErrorCodes.CreateApprenticeship.EmployerWebsite, result.Errors[0].ErrorCode);
                Assert.AreEqual(errorMessage, result.Errors[0].ErrorMessage);
            }
        }
Exemplo n.º 12
0
        public async Task AndIsNotApplicableThenIsInvalid()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var request = new CreateApprenticeshipRequest
            {
                WageType = WageType.CustomWageRange,
                WageUnit = WageUnit.NotApplicable
            };

            var context = GetValidationContextForProperty(request, req => req.WageUnit);

            var validator = fixture.Create <CreateApprenticeshipRequestValidator>();

            var result = await validator.ValidateAsync(context).ConfigureAwait(false);

            result.IsValid.Should().Be(false);
            result.Errors.Count.Should().Be(1);
            result.Errors.First().ErrorCode
            .Should().Be(ErrorCodes.CreateApprenticeship.WageUnit);
            result.Errors.First().ErrorMessage
            .Should().Be("'Wage Unit' should not be equal to 'NotApplicable'.");
        }
        public void ValidateAddressLine1(string addressLine1, bool isValid, string errorMessage)
        {
            var request = new CreateApprenticeshipRequest()
            {
                LocationType = LocationType.OtherLocation,
                AddressLine1 = addressLine1
            };

            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            if (isValid)
            {
                sut.ShouldNotHaveValidationErrorFor(r => r.AddressLine1, request);
            }
            else
            {
                sut
                .ShouldHaveValidationErrorFor(r => r.AddressLine1, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.AddressLine1)
                .WithErrorMessage(errorMessage);
            }
        }
        public void ValidateTrainingCode(string trainingCode, string errorMessage, bool shouldError)
        {
            var request = new CreateApprenticeshipRequest
            {
                TrainingType = TrainingType.Framework,
                TrainingCode = trainingCode
            };

            var fixture   = new Fixture().Customize(new AutoMoqCustomization());
            var validator = fixture.Create <CreateApprenticeshipRequestValidator>();

            if (shouldError)
            {
                validator
                .ShouldHaveValidationErrorFor(req => req.TrainingCode, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.TrainingCode)
                .WithErrorMessage(errorMessage);
            }
            else
            {
                validator.ShouldNotHaveValidationErrorFor(req => req.TrainingCode, request);
            }
        }
Exemplo n.º 15
0
        public void ValidateNumberOfPositions(int numberOfPositions, bool isValid, string errorMessage)
        {
            var request = new CreateApprenticeshipRequest()
            {
                NumberOfPositions = numberOfPositions
            };

            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            if (isValid)
            {
                sut.ShouldNotHaveValidationErrorFor(x => x.NumberOfPositions, request);
            }
            else
            {
                var errors = sut
                             .ShouldHaveValidationErrorFor(x => x.NumberOfPositions, request)
                             .WithErrorCode(ErrorCodes.CreateApprenticeship.NumberOfPositions)
                             .WithErrorMessage(errorMessage);
                errors.Count().Should().Be(1);
            }
        }
        public void SetUp()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            _randomWageType       = fixture.Create <int>();
            _randomLegacyWageType = fixture.Create <int>();
            _randomWageUnit       = fixture.Create <int>();

            _randomDurationType = (DurationType) new Random().Next(1, 4);
            var durationTypeMapper = new DurationMapper();

            _randomDomainDurationType = durationTypeMapper.MapTypeToDomainType(_randomDurationType);

            _request = fixture.Build <CreateApprenticeshipRequest>()
                       .With(request => request.WageType, (WageType)_randomWageType)
                       .With(request => request.WageUnit, (WageUnit)_randomWageUnit)
                       .With(request => request.DurationType, _randomDurationType)
                       .With(request => request.IsEmployerDisabilityConfident, fixture.Create <bool>())
                       .Create();

            _mockWageTypeMapper = fixture.Freeze <Mock <IWageTypeMapper> >();
            _mockWageTypeMapper
            .Setup(typeMapper => typeMapper.MapToLegacy(It.IsAny <CreateApprenticeshipRequest>()))
            .Returns((LegacyWageType)_randomLegacyWageType);

            _mockWageTextFormatter = fixture.Freeze <Mock <IWageTextFormatter> >();


            fixture.Inject <IDurationMapper>(durationTypeMapper);

            _employerInformation = fixture.Create <EmployerInformation>();

            var mapper = fixture.Create <CreateApprenticeshipParametersMapper>();

            _mappedParameters = mapper.MapFromRequest(_request, _employerInformation);
        }
Exemplo n.º 17
0
        public async Task AndCallingValidate(string wageTypeReasonToValidate, bool expectedIsValid,
                                             string expectedErrorCodes, string expectedErrorMessages)
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var request = new CreateApprenticeshipRequest
            {
                WageTypeReason = wageTypeReasonToValidate
            };

            var context = GetValidationContextForProperty(request, req => req.WageTypeReason);

            var validator = fixture.Create <CreateApprenticeshipRequestValidator>();

            var result = await validator.ValidateAsync(context);

            result.IsValid.Should().Be(expectedIsValid);
            if (!expectedIsValid)
            {
                result.Errors.First().ErrorCode
                .Should().Be(expectedErrorCodes);
                result.Errors.First().ErrorMessage
                .Should().Be(expectedErrorMessages);
            }
        }
Exemplo n.º 18
0
        public void ValidateSupplementaryQuestion2(string value, string errorMessage, bool shouldError)
        {
            var request = new CreateApprenticeshipRequest
            {
                ApplicationMethod      = ApplicationMethod.Online,
                SupplementaryQuestion2 = value
            };

            var sut = new Fixture().Customize(new AutoMoqCustomization())
                      .Create <CreateApprenticeshipRequestValidator>();

            sut.Validate(request);

            if (shouldError)
            {
                sut.ShouldHaveValidationErrorFor(req => req.SupplementaryQuestion2, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.SupplementaryQuestion2)
                .WithErrorMessage(errorMessage);
            }
            else
            {
                sut.ShouldNotHaveValidationErrorFor(req => req.SupplementaryQuestion2, request);
            }
        }
        public void ValidatePostcode(bool isValid, string postCode, string errorMessage)
        {
            var request = new CreateApprenticeshipRequest()
            {
                LocationType = LocationType.OtherLocation,
                Postcode     = postCode
            };

            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            if (isValid)
            {
                sut.ShouldNotHaveValidationErrorFor(r => r.Postcode, request);
            }
            else
            {
                var errors = sut
                             .ShouldHaveValidationErrorFor(r => r.Postcode, request)
                             .WithErrorCode(ErrorCodes.CreateApprenticeship.Postcode)
                             .WithErrorMessage(errorMessage);
                errors.Count().Should().Be(1);
            }
        }
        public void ValidateExternalApplicationInstructions(string value, string errorMessage, bool shouldError)
        {
            var request = new CreateApprenticeshipRequest
            {
                ApplicationMethod = ApplicationMethod.Offline,
                ExternalApplicationInstructions = value
            };

            var sut = new Fixture().Customize(new AutoMoqCustomization())
                      .Create <CreateApprenticeshipRequestValidator>();

            sut.Validate(request);

            if (shouldError)
            {
                sut.ShouldHaveValidationErrorFor(req => req.ExternalApplicationInstructions, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.ExternalApplicationInstructions)
                .WithErrorMessage(errorMessage);
            }
            else
            {
                sut.ShouldNotHaveValidationErrorFor(req => req.ExternalApplicationInstructions, request);
            }
        }
Exemplo n.º 21
0
        public void ThenShouldValidate(string shortDescription, bool isValid, string errorCode, string errorMessage)
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());
            var sut     = fixture.Create <CreateApprenticeshipRequestValidator>();

            var request = new CreateApprenticeshipRequest()
            {
                ShortDescription = shortDescription
            };

            //only validate ShortDescription
            var context = GetValidationContextForProperty(request, req => req.ShortDescription);

            var result = sut.Validate(context);

            Assert.AreEqual(isValid, result.IsValid);

            if (!result.IsValid)
            {
                Assert.AreEqual(1, result.Errors.Count);
                Assert.AreEqual(errorCode, result.Errors[0].ErrorCode);
                Assert.AreEqual(errorMessage, result.Errors[0].ErrorMessage);
            }
        }