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 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 void FormatCompanyRegistrationNumber_ReturnsFormattedString(string originalValue, string expectedValue) { var result = CompanyRegistrationNumberFormatter.FormatCompanyRegistrationNumber(originalValue); Assert.Equal(expectedValue, result); }