Пример #1
0
        public async Task HandleAsync_Always_CreatesFileNameWithSchemeApprovalNumberComplianceYearAndCurrentTime()
        {
            // Arrange
            Domain.Scheme.Scheme scheme = new Domain.Scheme.Scheme(A.Dummy <Organisation>());
            scheme.UpdateScheme(
                "Scheme name",
                "WEE/AB1234CD/SCH",
                A.Dummy <string>(),
                A.Dummy <Domain.Obligation.ObligationType?>(),
                A.Dummy <UKCompetentAuthority>());

            IFetchSummaryCsvDataAccess dataAccess = A.Fake <IFetchSummaryCsvDataAccess>();

            A.CallTo(() => dataAccess.FetchSchemeAsync(A <Guid> ._))
            .Returns(scheme);

            FetchSummaryCsvHandler handler = new FetchSummaryCsvHandler(
                A.Dummy <IWeeeAuthorization>(),
                A.Dummy <CsvWriterFactory>(),
                dataAccess);

            // Act
            Requests.DataReturns.FetchSummaryCsv request = new Requests.DataReturns.FetchSummaryCsv(
                A.Dummy <Guid>(),
                2017);

            SystemTime.Freeze(new DateTime(2016, 1, 2, 15, 22, 59), true);
            FileInfo result = await handler.HandleAsync(request);

            SystemTime.Unfreeze();

            // Assert
            Assert.NotNull(result);
            Assert.Equal("WEE/AB1234CD/SCH_EEE_WEEE_data_2017_02012016_1522.csv", result.FileName);
        }
        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);
            }
        }
Пример #3
0
            public DataReturnVersionFromXmlBuilderHelper(string schemeApprovalNumber)
            {
                DataReturnVersionBuilder     = A.Fake <IDataReturnVersionBuilder>();
                SchemeApprovalNumberMismatch = A.Fake <ISchemeApprovalNumberMismatch>();

                Scheme scheme = new Scheme(new Guid("FE4056B3-F892-476E-A4AB-7C111AE1EF14"));

                scheme.UpdateScheme(
                    "Test scheme",
                    schemeApprovalNumber,
                    "1B1S",
                    ObligationType.Both,
                    new Guid("C5D400BE-0CE7-43D7-BD7B-B7936967E500"));

                A.CallTo(() => DataReturnVersionBuilder.Scheme).Returns(scheme);
            }
Пример #4
0
        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 == "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", 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,
                    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", 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,
                    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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        public async Task Execute_GivenAatfsWithReceivedDataAndCreatedReturn_DataShouldBeReturned()
        {
            using (var db = new DatabaseWrapper())
            {
                var @return = SetupCreatedReturn(db);
                var aatf    = SetupAatfWithApprovalDate(db, DateTime.MinValue, "AAA");
                var aatf2   = SetupAatfWithApprovalDate(db, DateTime.MinValue, "AAB");

                var scheme1 = new Scheme(organisation);
                scheme1.UpdateScheme("scheme1", "1111", "1111", fixture.Create <ObligationType>(), db.WeeeContext.UKCompetentAuthorities.First());

                var scheme2 = new Scheme(organisation);
                scheme2.UpdateScheme("scheme2", "1111", "1111", fixture.Create <ObligationType>(), db.WeeeContext.UKCompetentAuthorities.First());

                var weeeReceivedAatf1Scheme1 = new WeeeReceived(scheme1, aatf, @return);
                var weeeReceivedAatf1Scheme2 = new WeeeReceived(scheme2, aatf, @return);
                var weeeReceivedAatf2Scheme2 = new WeeeReceived(scheme2, aatf2, @return);

                foreach (var categoryValue in CategoryValues())
                {
                    db.WeeeContext.WeeeReceivedAmount.Add(new Domain.AatfReturn.WeeeReceivedAmount(weeeReceivedAatf1Scheme1, categoryValue.CategoryId, categoryValue.CategoryId, categoryValue.CategoryId + 1));
                    db.WeeeContext.WeeeReceivedAmount.Add(new Domain.AatfReturn.WeeeReceivedAmount(weeeReceivedAatf1Scheme2, categoryValue.CategoryId, categoryValue.CategoryId, categoryValue.CategoryId + 1));
                    db.WeeeContext.WeeeReceivedAmount.Add(new Domain.AatfReturn.WeeeReceivedAmount(weeeReceivedAatf2Scheme2, categoryValue.CategoryId, categoryValue.CategoryId, categoryValue.CategoryId + 1));
                }

                db.WeeeContext.ReturnScheme.Add(new ReturnScheme(scheme1, @return));
                db.WeeeContext.ReturnScheme.Add(new ReturnScheme(scheme2, @return));

                db.WeeeContext.Returns.Add(@return);

                await db.WeeeContext.SaveChangesAsync();

                db.WeeeContext.ReturnReportOns.Add(new Domain.AatfReturn.ReturnReportOn(@return.Id, 1));

                await db.WeeeContext.SaveChangesAsync();

                var results = await db.StoredProcedures.GetReturnObligatedCsvData(@return.Id);

                results.Rows.Count.Should().Be(56);

                foreach (var categoryValue in CategoryValues())
                {
                    var houseHoldResultAatf1    = results.Select($"AatfKey='{aatf.Id}' AND CategoryId={categoryValue.CategoryId} AND [Obligation Type]='{B2C}'");
                    var nonHouseHoldResultAatf1 = results.Select($"AatfKey='{aatf.Id}' AND CategoryId={categoryValue.CategoryId} AND [Obligation Type]='{B2B}'");

                    houseHoldResultAatf1[0][TotalReceivedHeading].Should().Be(categoryValue.CategoryId * 2); // two schemes
                    houseHoldResultAatf1[0]["Obligated WEEE received on behalf of scheme1 (t)"].Should().Be(categoryValue.CategoryId);
                    houseHoldResultAatf1[0]["Obligated WEEE received on behalf of scheme2 (t)"].Should().Be(categoryValue.CategoryId);

                    nonHouseHoldResultAatf1[0][TotalReceivedHeading].Should().Be((categoryValue.CategoryId + 1) * 2); // two schemes
                    nonHouseHoldResultAatf1[0]["Obligated WEEE received on behalf of scheme1 (t)"].Should().Be((categoryValue.CategoryId + 1));
                    nonHouseHoldResultAatf1[0]["Obligated WEEE received on behalf of scheme2 (t)"].Should().Be(categoryValue.CategoryId + 1);

                    var houseHoldResultAatf2    = results.Select($"AatfKey='{aatf2.Id}' AND CategoryId={categoryValue.CategoryId} AND [Obligation Type]='{B2C}'");
                    var nonHouseHoldResultAatf2 = results.Select($"AatfKey='{aatf2.Id}' AND CategoryId={categoryValue.CategoryId} AND [Obligation Type]='{B2B}'");

                    houseHoldResultAatf2[0][TotalReceivedHeading].Should().Be(categoryValue.CategoryId);          //  single scheme
                    houseHoldResultAatf2[0]["Obligated WEEE received on behalf of scheme2 (t)"].Should().Be(categoryValue.CategoryId);
                    nonHouseHoldResultAatf2[0][TotalReceivedHeading].Should().Be((categoryValue.CategoryId + 1)); // single schemes
                    nonHouseHoldResultAatf2[0]["Obligated WEEE received on behalf of scheme2 (t)"].Should().Be(categoryValue.CategoryId + 1);
                }

                results.Dispose();
            }
        }
Пример #8
0
        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);
            }
        }
            public DataReturnVersionFromXmlBuilderHelper(string schemeApprovalNumber)
            {
                DataReturnVersionBuilder = A.Fake<IDataReturnVersionBuilder>();
                SchemeApprovalNumberMismatch = A.Fake<ISchemeApprovalNumberMismatch>();

                Scheme scheme = new Scheme(new Guid("FE4056B3-F892-476E-A4AB-7C111AE1EF14"));

                scheme.UpdateScheme(
                    "Test scheme",
                    schemeApprovalNumber,
                    "1B1S",
                    ObligationType.Both,
                    new Guid("C5D400BE-0CE7-43D7-BD7B-B7936967E500"));

                A.CallTo(() => DataReturnVersionBuilder.Scheme).Returns(scheme);
            }
        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 == "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", 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");

                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);

                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(
                    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", 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");

                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);

                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(
                    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);
            }
        }