public void UpdateProducerSubmissionAmount(Guid memberUploadId, string name, ProducerCharge producerCharge, statusType status, producerType producerType) { var producersMember = context.ProducerSubmissions .Where(p => p.MemberUploadId == memberUploadId).ToList(); var producer = producersMember.Where(p => p.ProducerBusiness.CompanyDetails != null && p.ProducerBusiness.CompanyDetails.Name.Trim().Equals(name.Trim()) || (p.ProducerBusiness.Partnership != null && p.ProducerBusiness.Partnership.Name.Trim().Equals(name.Trim()))).ToList(); Log.Information("number found {0}", producer.Count); if (producer.Count() == 1) { //throw new ApplicationException(string.Format("Producer with name {0} in upload {1} could not be updated", name, memberUploadId)); Log.Information(string.Format("Producer charge for {0} updated from {1} to {2} and from band {3} to {4}", name, producer.First().ChargeThisUpdate, producerCharge.Amount, producer.First().ChargeBandAmount.ChargeBand, producerCharge.ChargeBandAmount.ChargeBand)); producer.First().UpdateCharge(producerCharge.Amount, producerCharge.ChargeBandAmount, (int)status); context.SaveChanges(); } else { Log.Information(string.Format("last chance to find user {0}", producerType.tradingName)); var company = producerType.producerBusiness.Item; var findProducer = new List <ProducerSubmission>(); if (company.GetType() == typeof(companyType)) { Log.Information(string.Format("1. {0}", ((companyType)company).companyName)); var test = context.ProducerSubmissions .Where(p => p.MemberUploadId == memberUploadId).Where(p => p.ProducerBusiness.CompanyDetails != null); foreach (var producerSubmission in test) { Log.Information(string.Format("{0}", producerSubmission.ProducerBusiness.CompanyDetails.Name)); } findProducer = context.ProducerSubmissions .Where(p => p.MemberUploadId == memberUploadId && p.ProducerBusiness.CompanyDetails != null && p.ProducerBusiness.CompanyDetails.Name.Trim().Equals(((companyType)company).companyName.Trim())).ToList(); } else if (company.GetType() == typeof(partnershipType)) { Log.Information(string.Format("2. {0}", ((partnershipType)company).partnershipName)); findProducer = context.ProducerSubmissions .Where(p => p.MemberUploadId == memberUploadId && p.ProducerBusiness.Partnership != null && p.ProducerBusiness.Partnership.Name.Trim().Equals(((partnershipType)company).partnershipName.Trim())).ToList(); } if (producer.Count() == 1) { Log.Information(string.Format("Producer charge for {0} updated from {1} to {2} and from band {3} to {4}", name, producer.First().ChargeThisUpdate, producerCharge.Amount, producer.First().ChargeBandAmount.ChargeBand, producerCharge.ChargeBandAmount.ChargeBand)); findProducer.First().UpdateCharge(producerCharge.Amount, producerCharge.ChargeBandAmount, (int)status); context.SaveChanges(); } else { Log.Information(string.Format("Could not find {0}", name)); } } }
public void Evaluate_Amendment_AndProducerExistsWithDifferentChargeBand_FailAsWarning_AndIncludesProducerDetailsAndChargeBandsInErrorMessage() { string producerName = "ProdA"; string registrationNumber = "reg123"; var existingChargeBand = ChargeBand.A; var evaluator = new ProducerChargeBandChangeEvaluator(producerChargeBandCalculatorChooser); var producerCharge = new ProducerCharge() { ChargeBandAmount = new ChargeBandAmount(Guid.Empty, ChargeBand.B, 0), Amount = 0 }; var fakeProducer = A.Fake <ProducerSubmission>(); ChargeBandAmount chargeBandAmount = new ChargeBandAmount( new Guid("0B513437-2971-4C6C-B633-75216FAB6757"), existingChargeBand, 123); A.CallTo(() => fakeProducer.ChargeBandAmount).Returns(chargeBandAmount); A.CallTo(() => fakeProducer.OrganisationName).Returns(producerName); A.CallTo(() => fakeProducer.RegisteredProducer.ProducerRegistrationNumber).Returns(registrationNumber); A.CallTo(() => producerChargeBandCalculatorChooser.GetProducerChargeBand(A <schemeType> ._, A <producerType> ._)).Returns(producerCharge); A.CallTo(() => evaluator.QuerySet.GetLatestProducerForComplianceYearAndScheme(A <string> ._, A <string> ._, A <Guid> ._)) .Returns(fakeProducer); var result = evaluator.Evaluate(ChargeBand.B); Assert.False(result.IsValid); Assert.Equal(Core.Shared.ErrorLevel.Warning, result.ErrorLevel); Assert.Contains(producerName, result.Message); Assert.Contains(registrationNumber, result.Message); Assert.Contains(existingChargeBand.ToString(), result.Message); Assert.Contains(producerCharge.ChargeBandAmount.ChargeBand.ToString(), result.Message); }
public void Evaluate_Amendment_AndProducerExistsWithMatchingChargeBand_ReturnsPass() { var evaluator = new ProducerChargeBandChangeEvaluator(producerChargeBandCalculatorChooser); var fakeProducer = A.Fake <ProducerSubmission>(); var producerCharge = new ProducerCharge() { ChargeBandAmount = new ChargeBandAmount(Guid.Empty, ChargeBand.E, 0), Amount = 0 }; ChargeBandAmount producerChargeBand = new ChargeBandAmount( new Guid("0B513437-2971-4C6C-B633-75216FAB6757"), ChargeBand.E, 123); A.CallTo(() => fakeProducer.ChargeBandAmount).Returns(producerChargeBand); A.CallTo(() => evaluator.QuerySet.GetLatestProducerForComplianceYearAndScheme(A <string> ._, A <string> ._, A <Guid> ._)) .Returns(fakeProducer); A.CallTo(() => producerChargeBandCalculatorChooser.GetProducerChargeBand(A <schemeType> ._, A <producerType> ._)).Returns(producerCharge); var result = evaluator.Evaluate(ChargeBand.E); Assert.True(result.IsValid); }
public void Evaluate_Amendment_AndProducerExistsWithDifferentChargeBand_FailAsWarning() { var evaluator = new ProducerChargeBandChangeEvaluator(producerChargeBandCalculatorChooser); var fakeProducer = A.Fake <ProducerSubmission>(); var producerCharge = new ProducerCharge() { ChargeBandAmount = new ChargeBandAmount(Guid.Empty, ChargeBand.B, 0), Amount = 0 }; ChargeBandAmount chargeBandAmount = new ChargeBandAmount( new Guid("0B513437-2971-4C6C-B633-75216FAB6757"), ChargeBand.E, 123); A.CallTo(() => fakeProducer.ChargeBandAmount) .Returns(chargeBandAmount); A.CallTo(() => producerChargeBandCalculatorChooser.GetProducerChargeBand(A <schemeType> ._, A <producerType> ._)).Returns(producerCharge); A.CallTo(() => evaluator.QuerySet.GetLatestProducerForComplianceYearAndScheme(A <string> ._, A <string> ._, A <Guid> ._)) .Returns(fakeProducer); var result = evaluator.Evaluate(ChargeBand.B); Assert.False(result.IsValid); Assert.Equal(Core.Shared.ErrorLevel.Warning, result.ErrorLevel); }
public async void GetProducerChargeBand_GivenPreviousAmendmentChargeAndChargeQualifies_EnvironmentAgencyProducerChargeWithZeroAmountShouldBeReturned() { var schemeType = new schemeType() { approvalNo = "app", complianceYear = ComplianceYear.ToString() }; var producerType = new producerType() { registrationNo = "no", eeePlacedOnMarketBand = eeePlacedOnMarketBandType.Morethanorequalto5TEEEplacedonmarket }; var producerCharge = new ProducerCharge() { ChargeBandAmount = new ChargeBandAmount(Guid.NewGuid(), ChargeBand.A, 0) }; A.CallTo(() => registeredProducerDataAccess.GetProducerRegistration(producerType.registrationNo, ComplianceYear, schemeType.approvalNo)) .Returns(RegisteredProducer()); A.CallTo(() => environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(schemeType, producerType)).Returns(producerCharge); A.CallTo(() => registeredProducerDataAccess.HasPreviousAmendmentCharge(A <string> ._, A <int> ._, A <string> ._)).Returns(true); var result = await calculator.GetProducerChargeBand(schemeType, producerType); Assert.Equal(result.ChargeBandAmount, producerCharge.ChargeBandAmount); Assert.Equal(result.Amount, 0); }
public async void GetProducerChargeBand_GivenCalculatorIsFound_ChargeBandFromCalculatorShouldBeReturned() { var producerType = A.Fake <producerType>(); var schemeType = A.Fake <schemeType>(); var producerCharge = new ProducerCharge(); A.CallTo(() => producerChargeBandCalculator.IsMatch(A <schemeType> ._, A <producerType> ._)).Returns(true); A.CallTo(() => producerChargeBandCalculator.GetProducerChargeBand(A <schemeType> ._, A <producerType> ._)).Returns(producerCharge); var result = await producerChargeBandCalculatorChooser.GetProducerChargeBand(schemeType, producerType); Assert.Equal(producerCharge, result); }
public async void GetProducerChargeBand_UKEngland_Morethanorequalto5TEEEplacedonmarket_VATRegistered__ProducerChargeForChargeBandShouldBeReturned() { //Arrange var countryType = new countryType(); var eeePlacedOnMarketBandType = new eeePlacedOnMarketBandType(); var annualTurnoverBandType = new annualTurnoverBandType(); var producerCharge = new ProducerCharge(); var producer = SetUpProducer(countryType, eeePlacedOnMarketBandType, annualTurnoverBandType, true); A.CallTo(() => fetchProducerCharge.GetCharge(ChargeBand.A2)).Returns(producerCharge); // Act var result = await environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(A.Dummy <schemeType>(), producer); // Assert Assert.Equal(producerCharge, result); }
public async void GetProducerChargeBand_Morethanorequalto5TEEEplacedonmarket_Lessthanorequaltoonemillionpounds_VATRegistered__ProducerChargeForChargeBandShouldBeReturned() { // Arrange var producer = new producerType { annualTurnoverBand = annualTurnoverBandType.Lessthanorequaltoonemillionpounds, VATRegistered = true, eeePlacedOnMarketBand = eeePlacedOnMarketBandType.Morethanorequalto5TEEEplacedonmarket }; var producerCharge = new ProducerCharge(); A.CallTo(() => fetchProducerCharge.GetCharge(ChargeBand.B)).Returns(producerCharge); // Act var result = await producerChargeBandCalculator.GetProducerChargeBand(A.Dummy <schemeType>(), producer); // Assert Assert.Equal(producerCharge, result); }
public async void GetProducerChargeBand_UKNorthernIreland_Morethanorequalto5TEEEplacedonmarket_GreaterthanonemillionpoundsTurnover_NotVATRegistered__ProducerChargeForChargeBandShouldBeReturned() { //Arrange var countryType = new countryType(); var eeePlacedOnMarketBandType = new eeePlacedOnMarketBandType(); var annualTurnoverBandType = new annualTurnoverBandType(); var producerCharge = new ProducerCharge(); countryType = countryType.UKNORTHERNIRELAND; annualTurnoverBandType = annualTurnoverBandType.Greaterthanonemillionpounds; var producer = SetUpProducer(countryType, eeePlacedOnMarketBandType, annualTurnoverBandType, false); A.CallTo(() => fetchProducerCharge.GetCharge(ChargeBand.D)).Returns(producerCharge); // Act var result = await environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(A.Dummy <schemeType>(), producer); // Assert Assert.Equal(producerCharge, result); }
public void Calculate_WithVaildXmlFileContainingFiveProducers_ReturnsFiveCharges() { // Arrange // This file contains 5 producers. string absoluteFilePath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), @"ExampleXML\v3-valid-ChargeBand.xml"); byte[] xml = Encoding.ASCII.GetBytes(File.ReadAllText(new Uri(absoluteFilePath).LocalPath)); ProcessXmlFile request = new ProcessXmlFile(A.Dummy <Guid>(), xml, "File name"); ProducerCharge producerCharge1 = A.Dummy <ProducerCharge>(); ProducerCharge producerCharge2 = A.Dummy <ProducerCharge>(); ProducerCharge producerCharge3 = A.Dummy <ProducerCharge>(); ProducerCharge producerCharge4 = A.Dummy <ProducerCharge>(); ProducerCharge producerCharge5 = A.Dummy <ProducerCharge>(); A.CallTo(() => producerChargerCalculator.GetProducerChargeBand(A <schemeType> ._, A <producerType> ._)) .ReturnsNextFromSequence(producerCharge1, producerCharge2, producerCharge3, producerCharge4, producerCharge5); var xmlChargeBandCalculator = XmlChargeBandCalculator(); // Act var producerCharges = xmlChargeBandCalculator.Calculate(request); // Assert Assert.NotNull(producerCharges); Assert.Equal(producerCharges.Count, 5); Assert.True(producerCharges.ContainsKey("The Empire")); Assert.True(producerCharges.ContainsKey("Tom and Jerry")); Assert.True(producerCharges.ContainsKey("The Empire 1")); Assert.True(producerCharges.ContainsKey("The Empire 2")); Assert.True(producerCharges.ContainsKey("The Empire 3")); Assert.Equal(producerCharge1, producerCharges["The Empire"]); Assert.Equal(producerCharge2, producerCharges["Tom and Jerry"]); Assert.Equal(producerCharge3, producerCharges["The Empire 1"]); Assert.Equal(producerCharge4, producerCharges["The Empire 2"]); Assert.Equal(producerCharge5, producerCharges["The Empire 3"]); }
public async void GetProducerChargeBand_GivenCurrentSubmissionsIsNotMoreThanFiveTonnes_EnvironmentAgencyProducerChargeWithZeroAmountShouldBeReturned() { var schemeType = new schemeType() { approvalNo = "app", complianceYear = ComplianceYear.ToString() }; var producerType = new producerType() { registrationNo = "no", eeePlacedOnMarketBand = eeePlacedOnMarketBandType.Lessthan5TEEEplacedonmarket }; var producerCharge = new ProducerCharge() { ChargeBandAmount = new ChargeBandAmount(Guid.NewGuid(), ChargeBand.A, 0) }; A.CallTo(() => environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(schemeType, producerType)).Returns(producerCharge); var result = await calculator.GetProducerChargeBand(schemeType, producerType); Assert.Equal(result.ChargeBandAmount, producerCharge.ChargeBandAmount); Assert.Equal(result.Amount, 0); }
public async void GetProducerChargeBand_GivenCurrentSubmissionsIsMoreThanFiveTonnesAndPreviousProducerSubmissionWasLessThanFiveTonnes_ProducerChargeShouldBeEnvironmentAgencyCharge() { var schemeType = new schemeType() { approvalNo = "app", complianceYear = ComplianceYear.ToString() }; var producerType = new producerType() { registrationNo = "no", eeePlacedOnMarketBand = eeePlacedOnMarketBandType.Morethanorequalto5TEEEplacedonmarket }; var producerCharge = new ProducerCharge() { ChargeBandAmount = new ChargeBandAmount(Guid.NewGuid(), ChargeBand.A, 0) }; A.CallTo(() => registeredProducerDataAccess.GetProducerRegistration(producerType.registrationNo, ComplianceYear, schemeType.approvalNo)) .Returns(RegisteredProducer()); A.CallTo(() => environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(schemeType, producerType)).Returns(producerCharge); var result = await calculator.GetProducerChargeBand(schemeType, producerType); Assert.Equal(producerCharge, result); }
public async void GetProducerChargeBand_GivenAmendmentCannotFindPreviousSubmission_EnvironmentAgencyProducerChargeWithZeroAmountShouldBeReturned() { var schemeType = new schemeType() { approvalNo = "app", complianceYear = ComplianceYear.ToString() }; var producerType = new producerType() { registrationNo = "no", eeePlacedOnMarketBand = eeePlacedOnMarketBandType.Lessthan5TEEEplacedonmarket }; var producerCharge = new ProducerCharge() { ChargeBandAmount = new ChargeBandAmount(Guid.NewGuid(), ChargeBand.A, 0) }; A.CallTo(() => environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(schemeType, producerType)).Returns(producerCharge); A.CallTo(() => registeredProducerDataAccess.GetProducerRegistration(A <string> ._, A <int> ._, A <string> ._)).Returns((RegisteredProducer)null); var result = await calculator.GetProducerChargeBand(schemeType, producerType); Assert.Equal(result.ChargeBandAmount, producerCharge.ChargeBandAmount); Assert.Equal(result.Amount, 0); }