public async Task Execute_GivenWeeeReceivedData_ReturnsPcsAatfDiscrepancyDataShouldBeCorrect() { using (DatabaseWrapper db = new DatabaseWrapper()) { // Arrange Organisation organisation = Organisation.CreateSoleTrader("Test Organisation"); Domain.UKCompetentAuthority authority = db.WeeeContext.UKCompetentAuthorities.Single(c => c.Abbreviation == UKCompetentAuthorityAbbreviationType.EA); var year = 2019; Quarter quarter = new Quarter(year, QuarterType.Q1); Scheme scheme1 = new Scheme(organisation); scheme1.UpdateScheme("Test Scheme 1", "WEE/AH7453NF/SCH", "WEE9462846", Domain.Obligation.ObligationType.B2B, authority); scheme1.SetStatus(Domain.Scheme.SchemeStatus.Approved); Domain.DataReturns.DataReturn dataReturn1 = new Domain.DataReturns.DataReturn(scheme1, quarter); Domain.DataReturns.DataReturnVersion version1 = new Domain.DataReturns.DataReturnVersion(dataReturn1); Domain.DataReturns.WeeeDeliveredAmount amount1 = new Domain.DataReturns.WeeeDeliveredAmount( Domain.Obligation.ObligationType.B2B, WeeeCategory.LargeHouseholdAppliances, 123.456m, new AatfDeliveryLocation("WEE/AA1111AA/ATF", string.Empty)); db.WeeeContext.DataReturns.Add(dataReturn1); db.WeeeContext.DataReturnVersions.Add(version1); version1.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount(amount1); await db.WeeeContext.SaveChangesAsync(); dataReturn1.SetCurrentVersion(version1); await db.WeeeContext.SaveChangesAsync(); var @return = CreateSubmittedReturn(db, organisation); var aatf = new Aatf("aatfName", db.WeeeContext.UKCompetentAuthorities.First(), "WEE/AA1111AA/ATF", AatfStatus.Approved, organisation, AddressHelper.GetAatfAddress(db), AatfSize.Large, DateTime.Now, ObligatedWeeeIntegrationCommon.CreateDefaultContact(db.WeeeContext.Countries.First()), FacilityType.Aatf, (short)year, null, null); var weeeReceived = new EA.Weee.Domain.AatfReturn.WeeeReceived(scheme1, aatf, @return); var weeeReceivedAmounts = new List <WeeeReceivedAmount>() { new Domain.AatfReturn.WeeeReceivedAmount(weeeReceived, 1, 2, 10) }; db.WeeeContext.Returns.Add(@return); db.WeeeContext.ReturnAatfs.Add(new ReturnAatf(aatf, @return)); db.WeeeContext.WeeeReceived.Add(weeeReceived); db.WeeeContext.WeeeReceivedAmount.AddRange(weeeReceivedAmounts); await db.WeeeContext.SaveChangesAsync(); // Act var results = await db.StoredProcedures.GetPcsAatfComparisonDataCsvData(year, null, string.Empty); var record = results.First(x => x.AatfApprovalNumber == "WEE/AA1111AA/ATF" && x.ObligationType == "B2B"); //Assert Assert.NotNull(record); Assert.Equal("WEE/AA1111AA/ATF", record.AatfApprovalNumber); Assert.Equal(123.456m, record.PcsTonnage); Assert.Equal(10, record.AatfTonnage); Assert.Equal(113.456m, record.DifferenceTonnage); } }
private async Task CreateScheme(DatabaseWrapper db) { const Domain.Obligation.ObligationType obligationType = Domain.Obligation.ObligationType.B2B; var contact = new Domain.Organisation.Contact("firstName", "LastName", "Position"); Organisation organisation = Organisation.CreateSoleTrader("Test Organisation"); var address = new Address("address1", "address2", "town", "county", "postcode", db.WeeeContext.Countries.First(), "telephone", "email"); organisation.AddOrUpdateAddress(Domain.AddressType.RegisteredOrPPBAddress, address); Domain.UKCompetentAuthority authority = db.WeeeContext.UKCompetentAuthorities.Single(c => c.Abbreviation == UKCompetentAuthorityAbbreviationType.EA); Scheme scheme1 = new Scheme(organisation); scheme1.UpdateScheme("BBB", "TT", "Test", obligationType, authority); scheme1.AddOrUpdateMainContactPerson(contact); scheme1.AddOrUpdateAddress(address); db.WeeeContext.Organisations.Add(organisation); db.WeeeContext.Schemes.Add(scheme1); await db.WeeeContext.SaveChangesAsync(); }
public async Task Execute_WithoutSchemeFilter_ReturnsResultsForAllSchemes() { using (DatabaseWrapper wrapper = new DatabaseWrapper()) { // Arrange Domain.Organisation.Organisation organisation = Domain.Organisation.Organisation.CreateSoleTrader("Test Organisation"); Domain.UKCompetentAuthority authority = wrapper.WeeeContext.UKCompetentAuthorities.Single(c => c.Abbreviation == UKCompetentAuthorityAbbreviationType.EA); Quarter quarter = new Quarter(2099, QuarterType.Q1); // Arrange - Scheme 1 Domain.Scheme.Scheme scheme1 = new Domain.Scheme.Scheme(organisation); scheme1.UpdateScheme("Test Scheme 1", "WEE/AH7453NF/SCH", "WEE9462846", Domain.Obligation.ObligationType.B2C, authority); scheme1.SetStatus(Domain.Scheme.SchemeStatus.Approved); Domain.DataReturns.DataReturn dataReturn1 = new Domain.DataReturns.DataReturn(scheme1, quarter); Domain.DataReturns.DataReturnVersion version1 = new Domain.DataReturns.DataReturnVersion(dataReturn1); Domain.DataReturns.WeeeCollectedAmount amount1 = new Domain.DataReturns.WeeeCollectedAmount( WeeeCollectedAmountSourceType.Dcf, Domain.Obligation.ObligationType.B2C, WeeeCategory.LargeHouseholdAppliances, 123.456m); version1.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(amount1); wrapper.WeeeContext.DataReturnVersions.Add(version1); await wrapper.WeeeContext.SaveChangesAsync(); dataReturn1.SetCurrentVersion(version1); await wrapper.WeeeContext.SaveChangesAsync(); // Arrange - Scheme 2 Domain.Scheme.Scheme scheme2 = new Domain.Scheme.Scheme(organisation); scheme2.UpdateScheme("Test Scheme 2", "WEE/ZU6355HV/SCH", "WEE5746395", Domain.Obligation.ObligationType.B2C, authority); scheme2.SetStatus(Domain.Scheme.SchemeStatus.Approved); Domain.DataReturns.DataReturn dataReturn2 = new Domain.DataReturns.DataReturn(scheme2, quarter); Domain.DataReturns.DataReturnVersion version2 = new Domain.DataReturns.DataReturnVersion(dataReturn2); Domain.DataReturns.WeeeCollectedAmount amount2 = new Domain.DataReturns.WeeeCollectedAmount( WeeeCollectedAmountSourceType.Dcf, Domain.Obligation.ObligationType.B2C, WeeeCategory.LargeHouseholdAppliances, 123.456m); version2.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(amount2); wrapper.WeeeContext.DataReturnVersions.Add(version2); await wrapper.WeeeContext.SaveChangesAsync(); dataReturn2.SetCurrentVersion(version2); await wrapper.WeeeContext.SaveChangesAsync(); // Act SpgSchemeWeeeCsvResult result = await wrapper.WeeeContext.StoredProcedures.SpgSchemeWeeeCsvAsync( 2099, null, "B2C"); // Assert Assert.NotNull(result); Assert.NotNull(result.Schemes); Assert.Equal(2, result.Schemes.Count); Assert.NotNull(result.CollectedAmounts); Assert.Equal(2, result.CollectedAmounts.Count); } }
public async Task Execute_WithSchemeFilter_ReturnsResultsForSelectedSchemeOnly() { using (DatabaseWrapper wrapper = new DatabaseWrapper()) { // Arrange Domain.Organisation.Organisation organisation = Domain.Organisation.Organisation.CreateSoleTrader("Test Organisation"); Domain.UKCompetentAuthority authority = wrapper.WeeeContext.UKCompetentAuthorities.Single(c => c.Abbreviation == UKCompetentAuthorityAbbreviationType.EA); Domain.Lookup.ChargeBandAmount chargeBandAmount = wrapper.WeeeContext.ChargeBandAmounts.First(); Quarter quarter = new Quarter(2099, QuarterType.Q1); wrapper.WeeeContext.Organisations.Add(organisation); await wrapper.WeeeContext.SaveChangesAsync(); // Arrange - Scheme 1 Domain.Scheme.Scheme scheme1 = new Domain.Scheme.Scheme(organisation); scheme1.UpdateScheme("Test Scheme 1", "WEE/AH7453NF/SCH", "WEE9462846", Domain.Obligation.ObligationType.B2C, authority); scheme1.SetStatus(Domain.Scheme.SchemeStatus.Approved); Domain.Producer.RegisteredProducer registeredProducer1 = new Domain.Producer.RegisteredProducer("WEE/AG48365JN", 2099, scheme1); Domain.Scheme.MemberUpload memberUpload1 = new Domain.Scheme.MemberUpload( organisation.Id, "data", new List <Domain.Scheme.MemberUploadError>(), 0, 2099, scheme1, "file name", null, false); Domain.Producer.ProducerSubmission submission1 = new Domain.Producer.ProducerSubmission(registeredProducer1, memberUpload1, new Domain.Producer.ProducerBusiness(), new Domain.Producer.AuthorisedRepresentative("Foo"), new DateTime(2016, 1, 1), 0, true, null, "Trading Name 2", Domain.Producer.Classfication.EEEPlacedOnMarketBandType.Both, Domain.Producer.Classfication.SellingTechniqueType.Both, Domain.Obligation.ObligationType.B2C, Domain.Producer.Classfication.AnnualTurnOverBandType.Lessthanorequaltoonemillionpounds, new List <Domain.Producer.BrandName>(), new List <Domain.Producer.SICCode>(), chargeBandAmount, 0, A.Dummy <StatusType>()); memberUpload1.ProducerSubmissions.Add(submission1); wrapper.WeeeContext.MemberUploads.Add(memberUpload1); await wrapper.WeeeContext.SaveChangesAsync(); registeredProducer1.SetCurrentSubmission(submission1); await wrapper.WeeeContext.SaveChangesAsync(); Domain.DataReturns.DataReturn dataReturn1 = new Domain.DataReturns.DataReturn(scheme1, quarter); Domain.DataReturns.DataReturnVersion version1 = new Domain.DataReturns.DataReturnVersion(dataReturn1); Domain.DataReturns.EeeOutputAmount amount1 = new Domain.DataReturns.EeeOutputAmount( Domain.Obligation.ObligationType.B2C, WeeeCategory.LargeHouseholdAppliances, 123.456m, registeredProducer1); version1.EeeOutputReturnVersion.AddEeeOutputAmount(amount1); wrapper.WeeeContext.DataReturnVersions.Add(version1); await wrapper.WeeeContext.SaveChangesAsync(); dataReturn1.SetCurrentVersion(version1); await wrapper.WeeeContext.SaveChangesAsync(); // Arrange - Scheme 2 Domain.Scheme.Scheme scheme2 = new Domain.Scheme.Scheme(organisation); scheme2.UpdateScheme("Test Scheme 2", "WEE/ZU6355HV/SCH", "WEE5746395", Domain.Obligation.ObligationType.B2C, authority); scheme2.SetStatus(Domain.Scheme.SchemeStatus.Approved); Domain.Producer.RegisteredProducer registeredProducer2 = new Domain.Producer.RegisteredProducer("WEE/HT7483HD", 2099, scheme2); Domain.Scheme.MemberUpload memberUpload2 = new Domain.Scheme.MemberUpload( organisation.Id, "data", new List <Domain.Scheme.MemberUploadError>(), 0, 2099, scheme2, "file name", null, false); Domain.Producer.ProducerSubmission submission2 = new Domain.Producer.ProducerSubmission(registeredProducer2, memberUpload2, new Domain.Producer.ProducerBusiness(), new Domain.Producer.AuthorisedRepresentative("Foo"), new DateTime(2016, 1, 1), 0, true, null, "Trading Name 1", Domain.Producer.Classfication.EEEPlacedOnMarketBandType.Both, Domain.Producer.Classfication.SellingTechniqueType.Both, Domain.Obligation.ObligationType.B2C, Domain.Producer.Classfication.AnnualTurnOverBandType.Lessthanorequaltoonemillionpounds, new List <Domain.Producer.BrandName>(), new List <Domain.Producer.SICCode>(), chargeBandAmount, 0, A.Dummy <StatusType>()); memberUpload2.ProducerSubmissions.Add(submission2); wrapper.WeeeContext.MemberUploads.Add(memberUpload2); await wrapper.WeeeContext.SaveChangesAsync(); registeredProducer2.SetCurrentSubmission(submission2); await wrapper.WeeeContext.SaveChangesAsync(); Domain.DataReturns.DataReturn dataReturn2 = new Domain.DataReturns.DataReturn(scheme2, quarter); Domain.DataReturns.DataReturnVersion version2 = new Domain.DataReturns.DataReturnVersion(dataReturn2); Domain.DataReturns.EeeOutputAmount amount2 = new Domain.DataReturns.EeeOutputAmount( Domain.Obligation.ObligationType.B2C, WeeeCategory.LargeHouseholdAppliances, 123.456m, registeredProducer2); version2.EeeOutputReturnVersion.AddEeeOutputAmount(amount2); wrapper.WeeeContext.DataReturnVersions.Add(version2); await wrapper.WeeeContext.SaveChangesAsync(); dataReturn2.SetCurrentVersion(version2); await wrapper.WeeeContext.SaveChangesAsync(); // Act List <ProducerEeeCsvData> results = await wrapper.WeeeContext.StoredProcedures.SpgProducerEeeCsvData( 2099, scheme1.Id, "B2C"); // Assert Assert.NotNull(results); Assert.Equal(1, results.Count); Assert.NotNull(results[0]); Assert.Equal("Test Scheme 1", results[0].SchemeName); } }