public RuleResult Evaluate(schemeType scheme, producerType producer, Guid organisationId) { if (producer.status == statusType.A) { var existingProducer = querySet.GetProducerForOtherSchemeAndObligationType(producer.registrationNo, scheme.complianceYear, organisationId, producer.obligationType.ToDomainObligationType()); if (existingProducer != null) { string schemeName = "another scheme"; if (existingProducer.RegisteredProducer.Scheme != null && !string.IsNullOrEmpty(existingProducer.RegisteredProducer.Scheme.SchemeName)) { schemeName = existingProducer.RegisteredProducer.Scheme.SchemeName; } var errorMessage = string.Format( "{0} {1} is already registered with {2} with obligation type: {3}. Review your file.", producer.GetProducerName(), producer.registrationNo, schemeName, (ObligationType)existingProducer.ObligationType); return(RuleResult.Fail(errorMessage)); } return(RuleResult.Pass()); } return(RuleResult.Pass()); }
public RuleResult Evaluate(schemeType root, producerType element, Guid organisationId) { var result = RuleResult.Pass(); if (element.status == statusType.A) { var existingProducer = querySet.GetLatestProducerForComplianceYearAndScheme(element.registrationNo, root.complianceYear, organisationId); if (existingProducer != null) { var existingChargeBandType = existingProducer.ChargeBandAmount.ChargeBand; var producerCharge = Task.Run(() => producerChargeBandCalculatorChooser.GetProducerChargeBand(root, element)).Result; if (existingChargeBandType != producerCharge.ChargeBandAmount.ChargeBand) { result = RuleResult.Fail( string.Format("The charge band of {0} {1} will change from '{2}' to '{3}'.", existingProducer.OrganisationName, existingProducer.RegisteredProducer.ProducerRegistrationNumber, existingChargeBandType, producerCharge.ChargeBandAmount.ChargeBand), Core.Shared.ErrorLevel.Warning); } } } return(result); }
public IEnumerable <RuleResult> Evaluate(schemeType scheme) { var duplicateProducerNames = new List <string>(); foreach (var producer in scheme.producerList) { if (!string.IsNullOrEmpty(producer.GetProducerName())) { var isDuplicate = scheme.producerList .Any(p => p != producer && p.GetProducerName() == producer.GetProducerName()); if (isDuplicate && !duplicateProducerNames.Contains(producer.GetProducerName())) { duplicateProducerNames.Add(producer.GetProducerName()); yield return (RuleResult.Fail( string.Format("{0} can only appear once in your file. Review your file.", producer.GetProducerName()))); continue; } } yield return(RuleResult.Pass()); } }
public async Task <RuleResult> Evaluate(producerType producer) { var result = RuleResult.Pass(); if (producer.status == statusType.A) { var existingProducerDetails = producerQuerySet.GetLatestProducerForComplianceYearAndScheme(producer.registrationNo, complianceYear, organisationId); if (existingProducerDetails != null) { var newObligationType = producer.obligationType.ToDomainObligationType(); if (existingProducerDetails.ObligationType != newObligationType) { var producerEeeData = await schemeEeeDataQuerySet.GetLatestProducerEeeData(producer.registrationNo); if (producerEeeData != null && !producerEeeData.All(e => newObligationType.HasFlag(e.ObligationType))) { var eeeDataObligationTypes = producerEeeData .Select(e => e.ObligationType) .Distinct(); string eeeDataObligationTypeMessage = eeeDataObligationTypes.Count() == 1 ? string.Format("{0} EEE data has", eeeDataObligationTypes.Single()) : "both B2B and B2C EEE data have"; var errorMessage = string.Format("You are attempting to change the obligation type of {0} {1} from {2} to {3}. You cannot make this change because {4} already been submitted for this producer.", producer.GetProducerName(), producer.registrationNo, existingProducerDetails.ObligationType, newObligationType, eeeDataObligationTypeMessage); result = RuleResult.Fail(errorMessage, ErrorLevel.Error); } else { var warningMessage = string.Format("You are changing the obligation type for {0} {1} from {2} to {3}.", producer.GetProducerName(), producer.registrationNo, existingProducerDetails.ObligationType, newObligationType); result = RuleResult.Fail(warningMessage, ErrorLevel.Warning); } } } } return(result); }
public RuleResult Evaluate(producerType newProducer) { var result = RuleResult.Pass(); if (newProducer.status == statusType.A && newProducer.producerBusiness != null) { var newCompany = newProducer.producerBusiness.Item as companyType; if (newCompany != null) { var existingProducer = producerQuerySet .GetLatestProducerFromPreviousComplianceYears(newProducer.registrationNo); if (existingProducer != null && existingProducer.ProducerBusiness.CompanyDetails != null) { var existingCompanyNumberFormatted = CompanyRegistrationNumberFormatter .FormatCompanyRegistrationNumber(existingProducer.ProducerBusiness.CompanyDetails.CompanyNumber); if (!string.IsNullOrEmpty(existingCompanyNumberFormatted)) { var newCompanyNumberFormatted = CompanyRegistrationNumberFormatter .FormatCompanyRegistrationNumber(newCompany.companyNumber); if (existingCompanyNumberFormatted != newCompanyNumberFormatted) { if (string.IsNullOrEmpty(newCompanyNumberFormatted)) { result = RuleResult.Fail( string.Format("The company registration number of {0} {1} which is currently {2} will be removed.", existingProducer.OrganisationName, existingProducer.RegisteredProducer.ProducerRegistrationNumber, existingProducer.ProducerBusiness.CompanyDetails.CompanyNumber), ErrorLevel.Warning); } else { result = RuleResult.Fail( string.Format("The company registration number of {0} {1} will change from {2} to {3}.", existingProducer.OrganisationName, existingProducer.RegisteredProducer.ProducerRegistrationNumber, existingProducer.ProducerBusiness.CompanyDetails.CompanyNumber, newCompany.companyNumber), ErrorLevel.Warning); } } } } } } return(result); }
public async Task ProducerObligationTypeChange_ShouldReturnRuleResult() { var scheme = SchemeWithXProducers(1); var schemeId = Guid.NewGuid(); var error = RuleResult.Fail("oops", ErrorLevel.Error); A.CallTo(() => producerObligationTypeChange.Evaluate(scheme.producerList.Single())).Returns(error); var result = await XmlBusinessValidator().Validate(scheme, schemeId); Assert.Single(result); Assert.Equal(error, result.Single()); }
public async Task CompanyAlreadyRegistered_ShouldReturnRuleResult() { var scheme = SchemeWithXProducers(1); var schemeId = Guid.NewGuid(); var error = RuleResult.Fail("oops", ErrorLevel.Warning); A.CallTo(() => companyAlreadyRegistered.Evaluate(scheme.producerList.Single())).Returns(error); var result = await XmlBusinessValidator().Validate(scheme, schemeId); Assert.Single(result); Assert.Equal(error, result.Single()); }
public RuleResult Evaluate(producerType producer) { if (producer.status == statusType.A && string.IsNullOrEmpty(producer.registrationNo)) { return (RuleResult.Fail( string.Format( "You have not provided a producer registration number (PRN) for {0} when attempting to amend existing producer details. To amend this producer add the PRN or to add as a brand new producer use status 'I' in the XML.", producer.GetProducerName()))); } return(RuleResult.Pass()); }
public RuleResult Evaluate(producerType producer) { if (producer.status == statusType.I && !string.IsNullOrEmpty(producer.registrationNo)) { return RuleResult.Fail( string.Format( "You cannot add a producer registration number (PRN) for {0} when adding the producer for the first time. To add {0} as a new producer, remove the PRN - or if the producer already exists, amend its details using status 'A' not 'I'.", producer.GetProducerName())); } return RuleResult.Pass(); }
public async Task SchemeApprovalNumberIsInvalid_ShouldReturnRuleResult() { var scheme = SchemeWithXProducers(1); var schemeId = Guid.NewGuid(); var error = RuleResult.Fail("oops"); A.CallTo(() => correctSchemeApprovalNumber.Evaluate(scheme, schemeId)).Returns(error); var result = await XmlBusinessValidator().Validate(scheme, schemeId); Assert.Single(result); Assert.Equal(error, result.Single()); }
public RuleResult Evaluate(producerType producer) { if (producer.status == statusType.I && !string.IsNullOrEmpty(producer.registrationNo)) { return (RuleResult.Fail( string.Format( "You cannot add a producer registration number (PRN) for {0} when registering the producer for the very first time. To register {0} as a brand new producer, remove the PRN - or if the producer has been registered previously, register them or amend their details using status 'A' not 'I'.", producer.GetProducerName()))); } return(RuleResult.Pass()); }
public async Task AnnualTurnoverHasMismatch_ShouldReturnRuleResult() { var scheme = SchemeWithXProducers(1); var schemeId = Guid.NewGuid(); var error = RuleResult.Fail("oops"); A.CallTo(() => annualTurnoverMismatch.Evaluate(scheme.producerList.Single())).Returns(error); var result = await XmlBusinessValidator().Validate(scheme, schemeId); Assert.Single(result); Assert.Equal(error, result.Single()); }
public async Task ProducerHasNoUkBasedAuthorisedRepresentative_ShouldReturnRuleResult() { var scheme = SchemeWithXProducers(1); var schemeId = Guid.NewGuid(); var error = RuleResult.Fail("oops"); A.CallTo(() => ukBasedAuthorisedRepresentative.Evaluate(scheme.producerList.Single())).Returns(error); var result = await XmlBusinessValidator().Validate(scheme, schemeId); Assert.Single(result); Assert.Equal(error, result.Single()); }
public async Task ProducerInsertHasRegistrationNumber_ShouldReturnRuleResult() { var scheme = SchemeWithXProducers(1); var schemeId = Guid.NewGuid(); var error = RuleResult.Fail("oops"); A.CallTo(() => insertHasProducerRegistrationNumber.Evaluate(scheme.producerList.Single())).Returns(error); var result = await XmlBusinessValidator().Validate(scheme, schemeId); Assert.Single(result); Assert.Equal(error, result.Single()); }
public void FailDelegatesFalse() { bool testResult = true; Action <bool, Validation> testDelegate = (b, v) => { testResult = b; }; IRuleResult toTest = new RuleResult(testDelegate); toTest.Fail(new Validation()); Assert.False(testResult); }
public async Task DuplicateProducerNames_ShouldReturnRuleResult() { var scheme = SchemeWithXProducers(1); var schemeId = Guid.NewGuid(); var errors = new List <RuleResult> { RuleResult.Fail("oops") }; A.CallTo(() => duplicateProducerNames.Evaluate(scheme)).Returns(errors); var result = await XmlBusinessValidator().Validate(scheme, schemeId); Assert.Equal(errors, result); }
public RuleResult Evaluate(schemeType scheme, Guid organisationId) { var approvalNumber = schemeQuerySet.GetSchemeApprovalNumberByOrganisationId(organisationId); if (!string.Equals(approvalNumber, scheme.approvalNo, StringComparison.InvariantCultureIgnoreCase)) { return (RuleResult.Fail( string.Format( "The PCS approval number {0} you have provided does not match with the PCS you are logged in for. Review the PCS approval number.", scheme.approvalNo))); } return(RuleResult.Pass()); }
public async Task SchemaValidatorHasNoErrors_AndBusinessValidatorDoes_ShouldReturnErrors() { A.CallTo(() => schemaValidator.Validate(A <byte[]> ._, string.Empty, A <XNamespace> ._, A <string> ._)) .Returns(new List <XmlValidationError>()); A.CallTo(() => businessValidator.Validate(A <schemeType> ._, A <Guid> ._)) .Returns(new List <RuleResult> { RuleResult.Fail("An error occurred") }); var result = await XmlValidator().Validate(new ProcessXmlFile(A.Dummy <Guid>(), A.Dummy <byte[]>(), A.Dummy <string>())); Assert.NotEmpty(result); }
public RuleResult Evaluate(producerType producer) { if (producer.authorisedRepresentative == null) { return(RuleResult.Pass()); } if (producer.authorisedRepresentative.overseasProducer == null) { return(RuleResult.Pass()); } var producerBusinessItem = producer.producerBusiness.Item; contactDetailsContainerType officeContactDetails; if (producerBusinessItem is companyType) { officeContactDetails = ((companyType)producerBusinessItem).registeredOffice; } else if (producerBusinessItem is partnershipType) { officeContactDetails = ((partnershipType)producerBusinessItem).principalPlaceOfBusiness; } else { throw new ArgumentException( string.Format("{0}: producerBusinessItem must be of type companyType or partnershipType", producer.tradingName)); } // abusing law of demeter here, but schema requires all these fields to be present and correct if (!ukCountries.Contains(officeContactDetails.contactDetails.address.country)) { return (RuleResult.Fail( string.Format( "You have entered {0} {1} as an authorised representative with a non-UK address. Authorised representatives must be based in the UK. Review your file.", producer.GetProducerName(), producer.registrationNo))); } else { return(RuleResult.Pass()); } }
public RuleResult Evaluate(producerType element) { var result = RuleResult.Pass(); if (element.status == statusType.I && element.producerBusiness != null) { var company = element.producerBusiness.Item as companyType; if (company != null) { var companyNumber = CompanyRegistrationNumberFormatter .FormatCompanyRegistrationNumber(company.companyNumber); if (!string.IsNullOrEmpty(companyNumber) && (producerQuerySet.GetLatestCompanyProducers().Any(p => { var existingCompanyRegistrationNumber = CompanyRegistrationNumberFormatter .FormatCompanyRegistrationNumber(p.ProducerBusiness.CompanyDetails.CompanyNumber); return(!string.IsNullOrEmpty(existingCompanyRegistrationNumber) && existingCompanyRegistrationNumber == companyNumber); }) || migratedProducerQuerySet.GetAllMigratedProducers().Any(m => { var migratedProducerCompanyNumber = CompanyRegistrationNumberFormatter .FormatCompanyRegistrationNumber(m.CompanyNumber); return(!string.IsNullOrEmpty(migratedProducerCompanyNumber) && migratedProducerCompanyNumber == companyNumber); }))) { result = RuleResult.Fail( string.Format(@"We have previously issued a producer registration number (PRN) to {0} with company registration number (CRN) {1}. To register this producer, provide its existing PRN and use the status 'A' in the XML file.", element.GetProducerName(), company.companyNumber), Core.Shared.ErrorLevel.Error); } } } return(result); }
public RuleResult Evaluate(producerType producer) { if (producer.status == statusType.A && !string.IsNullOrEmpty(producer.registrationNo)) { var validRegistrationNumbers = producerQuerySet.GetAllRegistrationNumbers() .Union(migratedProducerQuerySet.GetAllRegistrationNumbers()) .Select(prn => prn.ToLowerInvariant()); if (!validRegistrationNumbers.Contains(producer.registrationNo.ToLowerInvariant())) { return (RuleResult.Fail( string.Format( "We cannot recognise the producer registration number (PRN) you have entered for {0} {1}. Enter the correct PRN for this producer.", producer.GetProducerName(), producer.registrationNo))); } } return(RuleResult.Pass()); }
public RuleResult Evaluate(schemeType scheme, producerType producer, Guid organisationId) { if (producer.status == statusType.A) { string existingProducerName = string.Empty; var existingProducer = producerQuerySet.GetLatestProducerForComplianceYearAndScheme(producer.registrationNo, scheme.complianceYear, organisationId) ?? producerQuerySet.GetLatestProducerFromPreviousComplianceYears(producer.registrationNo); if (existingProducer != null) { existingProducerName = existingProducer.OrganisationName; } else { var existingMigratedProducer = migratedProducerQuerySet.GetMigratedProducer(producer.registrationNo); if (existingMigratedProducer == null) { // Producer doesn't exist so no warning return(RuleResult.Pass()); } existingProducerName = existingMigratedProducer.ProducerName; } if (existingProducerName != producer.GetProducerName()) { var errorMessage = string.Format("The producer name of {0} {1} will change from {0} to {2}.", existingProducerName, producer.registrationNo, producer.GetProducerName()); return(RuleResult.Fail(errorMessage, Core.Shared.ErrorLevel.Warning)); } } return(RuleResult.Pass()); }
public RuleResult Evaluate(producerType producer) { var higherBandThanExpected = producer.annualTurnoverBand == annualTurnoverBandType.Greaterthanonemillionpounds && producer.annualTurnover.HasValue && producer.annualTurnover.Value <= 1000000; var lowerBandThanExpected = producer.annualTurnoverBand == annualTurnoverBandType.Lessthanorequaltoonemillionpounds && producer.annualTurnover.HasValue && producer.annualTurnover.Value > 1000000; if (higherBandThanExpected || lowerBandThanExpected) { return (RuleResult.Fail( string.Format( "The annualTurnover amount and annualTurnoverBand for {0} are not compatible. Review your return XML.", producer.GetProducerName()), ErrorLevel.Warning)); } return(RuleResult.Pass()); }
public RuleResult Evaluate(producerType producer) { if (producer.authorisedRepresentative == null) { return(RuleResult.Pass()); } if (producer.authorisedRepresentative.overseasProducer == null) { return(RuleResult.Pass()); } if (producer.authorisedRepresentative.overseasProducer.overseasContact == null) { return(RuleResult.Pass()); } contactDetailsType contact = producer.authorisedRepresentative.overseasProducer.overseasContact; switch (contact.address.country) { case countryType.UKENGLAND: case countryType.UKNORTHERNIRELAND: case countryType.UKSCOTLAND: case countryType.UKWALES: string errorMessage = string.Format( "You have entered {0} {1} as an authorised representative of an organisation with a UK address. Authorised representatives cannot represent producers based in the UK. Review your file.", producer.GetProducerName(), producer.registrationNo); return(RuleResult.Fail(errorMessage, Core.Shared.ErrorLevel.Error)); default: return(RuleResult.Pass()); } }