public async Task Execute_WithProducerBrandNames_ReturnsBrandNamesForRemovedProducer()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme = helper.CreateScheme();

                MemberUpload memberUpload = helper.CreateMemberUpload(scheme);
                memberUpload.ComplianceYear = 2016;
                memberUpload.IsSubmitted    = true;
                memberUpload.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer = helper.CreateProducerAsPartnership(memberUpload, "WEE/11BBBB11");
                producer.Business.Partnership.Name  = "ABCH";
                producer.RegisteredProducer.Removed = true;

                helper.CreateBrandName(producer, "Brand1");
                helper.CreateBrandName(producer, "Brand2");

                db.Model.SaveChanges();

                // Act
                List <MembersDetailsCsvData> results = await db.StoredProcedures.SpgCSVDataBySchemeComplianceYearAndAuthorisedAuthority(2016, true, true, scheme.Id, null);

                // Assert
                Assert.NotNull(results);
                Assert.Single(results);

                Assert.NotNull(results[0].BrandNames);
                Assert.Equal("Brand1; Brand2", results[0].BrandNames);
            }
        }
        public async Task Execute_NonSubmittedMemberUpload_IgnoresProducer()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                scheme1.OrganisationId  = new Guid("4EEE5942-01B2-4A4D-855A-34DEE1BBBF26");
                scheme1.Organisation.Id = new Guid("4EEE5942-01B2-4A4D-855A-34DEE1BBBF26");

                scheme1.Organisation.BusinessAddressId = new Guid("b58e9cb2-b97e-4141-ad32-73c70284fc77");
                scheme1.Organisation.Address           = helper.CreateOrganisationAddress();
                scheme1.Organisation.Address.Id        = new Guid("b58e9cb2-b97e-4141-ad32-73c70284fc77");

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = false;

                ProducerSubmission producerSubmission = helper.CreateProducerAsCompany(memberUpload1, "WEE/99ZZZZ99");

                db.Model.SaveChanges();

                // Act
                List <ProducerPublicRegisterCSVData> results =
                    await db.StoredProcedures.SpgProducerPublicRegisterCSVDataByComplianceYear(2016);

                // Assert
                Assert.False(results.Any(i => i.PRN == "WEE/99ZZZZ99"));
            }
        }
示例#3
0
        public async Task GetChanges_WithNoEeeChanges_ReturnsEmptyResult()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme = helper.CreateScheme();

                MemberUpload memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = 2016;

                ProducerSubmission producer = helper.CreateProducerAsCompany(memberUpload, "WEE/11BBBB11");

                var eeeOutputAmount = helper.CreateEeeOutputAmount(producer.RegisteredProducer, "B2B", 1, 10);

                var previousDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                previousDataReturnVersion.SubmittedDate = new DateTime(2016, 1, 1);
                helper.AddEeeOutputAmount(previousDataReturnVersion, eeeOutputAmount);

                var currentDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                currentDataReturnVersion.SubmittedDate = new DateTime(2016, 2, 1);
                helper.AddEeeOutputAmount(currentDataReturnVersion, eeeOutputAmount);

                db.Model.SaveChanges();

                var dataAccess = new GetDataReturnSubmissionEeeChangesCsvDataAccess(db.WeeeContext);

                // Act
                var results = await dataAccess.GetChanges(currentDataReturnVersion.Id, previousDataReturnVersion.Id);

                // Assert
                Assert.Empty(results.CsvData);
            }
        }
        private RegisteredProducer RegisteredProducer()
        {
            var id = Guid.NewGuid();
            var registeredProducer = A.Fake <RegisteredProducer>();
            var memberUpload       = A.Fake <MemberUpload>();

            A.CallTo(() => registeredProducer.Scheme.Id).Returns(id);
            A.CallTo(() => registeredProducer.ComplianceYear).Returns(ComplianceYear);
            A.CallTo(() => memberUpload.Scheme.Id).Returns(id);
            A.CallTo(() => memberUpload.ComplianceYear).Returns(ComplianceYear);

            var producerSubmission = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy <ProducerBusiness>(),
                A.Dummy <AuthorisedRepresentative>(),
                A.Dummy <DateTime>(),
                A.Dummy <int>(),
                A.Dummy <bool>(),
                A.Dummy <DateTime>(),
                A.Dummy <string>(),
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                A.Dummy <SellingTechniqueType>(),
                A.Dummy <Domain.Obligation.ObligationType>(),
                A.Dummy <AnnualTurnOverBandType>(),
                A.Dummy <List <BrandName> >(),
                A.Dummy <List <SICCode> >(),
                A.Dummy <ChargeBandAmount>(),
                A.Dummy <decimal>(),
                A.Dummy <StatusType>());

            A.CallTo(() => registeredProducer.CurrentSubmission).Returns(producerSubmission);
            return(registeredProducer);
        }
        public async Task Execute_WithProducersInOtherSchemes_IgnoresOtherSchemes()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/11AAAA11");

                Scheme scheme2 = helper.CreateScheme();

                MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme2);
                memberUpload2.ComplianceYear = 2016;
                memberUpload2.IsSubmitted    = true;
                memberUpload2.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer2 = helper.CreateProducerAsPartnership(memberUpload2, "WEE/22BBBB22");

                db.Model.SaveChanges();

                // Act
                List <ProducerCsvData> results =
                    await db.StoredProcedures.SpgCSVDataByOrganisationIdAndComplianceYear(scheme1.OrganisationId, 2016);

                // Assert
                Assert.False(results.Any(r => r.RegistrationNumber == "WEE/22BBBB22"), "When a scheme ID is provided, producers from other schemes should not be returned.");
            }
        }
示例#6
0
        public void GetLatestProducerFromPreviousComplianceYears_TwoProducerEntriesIn2015_ReturnsLatestProducerByUpdatedDate()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Scheme scheme = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme);
                memberUpload1.ComplianceYear = 2015;
                memberUpload1.IsSubmitted    = true;

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "AAAAAAA");
                producer1.UpdatedDate = new DateTime(2015, 1, 1);

                MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme);
                memberUpload2.ComplianceYear = 2015;
                memberUpload2.IsSubmitted    = true;

                ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload2, "AAAAAAA");
                producer2.UpdatedDate = new DateTime(2015, 1, 2);

                database.Model.SaveChanges();

                ProducerQuerySet querySet = ProducerQuerySet(database.WeeeContext);

                // Act
                var result = querySet.GetLatestProducerFromPreviousComplianceYears("AAAAAAA");

                // Assert
                Assert.NotNull(result);
                Assert.Equal(producer2.Id, result.Id);
            }
        }
示例#7
0
        public void GetLatestCompanyProducers_ReturnsCurrentForComplianceYearCompaniesOnly()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                ModelHelper helper = new ModelHelper(database.Model);

                // Arrange
                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2015;
                memberUpload1.IsSubmitted    = true;

                ProducerSubmission companyProducer1 = helper.CreateProducerAsCompany(memberUpload1, "AA");

                ProducerSubmission companyProducer2 = helper.CreateProducerAsCompany(memberUpload1, "BB");

                ProducerSubmission companyProducer3 = helper.CreateProducerAsCompany(memberUpload1, "AA");

                database.Model.SaveChanges();

                // Act
                var result = ProducerQuerySet(database.WeeeContext).GetLatestCompanyProducers();

                // Assert
                Assert.DoesNotContain(result, p => p.Id == companyProducer1.Id);
                Assert.Contains(result, p => p.Id == companyProducer2.Id);
                Assert.Contains(result, p => p.Id == companyProducer3.Id);
            }
        }
        public async Task Execute_ProducerTypeIsPartnership_ReturnsPartnershipNameAsProducerName()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                scheme1.OrganisationId  = new Guid("4EEE5942-01B2-4A4D-855A-34DEE1BBBF26");
                scheme1.Organisation.Id = new Guid("4EEE5942-01B2-4A4D-855A-34DEE1BBBF26");

                scheme1.Organisation.BusinessAddressId = new Guid("b58e9cb2-b97e-4141-ad32-73c70284fc77");
                scheme1.Organisation.Address           = helper.CreateOrganisationAddress();
                scheme1.Organisation.Address.Id        = new Guid("b58e9cb2-b97e-4141-ad32-73c70284fc77");

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;

                ProducerSubmission producerSubmission = helper.CreateProducerAsPartnership(memberUpload1, "WEE/99ZZZZ99");

                db.Model.SaveChanges();

                // Act
                List <ProducerPublicRegisterCSVData> results =
                    await db.StoredProcedures.SpgProducerPublicRegisterCSVDataByComplianceYear(2016);

                // Assert
                var result = results.SingleOrDefault(i => i.PRN == "WEE/99ZZZZ99");

                Assert.NotNull(result);
                Assert.Equal(result.ProducerName, producerSubmission.Business.Partnership.Name);
            }
        }
示例#9
0
        public void Equals_ProducerSubmissionWithNullCeaseToExistDateAndProducerSubmissionWithCeaseToExistDate_ReturnsFalse()
        {
            ProducerSubmission producer1 = ProducerBuilder.WithCeaseToExist(null);
            ProducerSubmission producer2 = ProducerBuilder.WithCeaseToExist(A.Dummy <DateTime>());

            Assert.NotEqual(producer1, producer2);
        }
示例#10
0
        public void Equals_ProducerSubmissionsWithNullCeaseToExistDates_ReturnsTrue()
        {
            ProducerSubmission producer1 = ProducerBuilder.WithCeaseToExist(null);
            ProducerSubmission producer2 = ProducerBuilder.WithCeaseToExist(null);

            Assert.Equal(producer1, producer2);
        }
示例#11
0
        public void Equals_ProducerSubmissionsWithSameCeaseToExistDates_ReturnsTrue()
        {
            ProducerSubmission producer1 = ProducerBuilder.WithCeaseToExist(new DateTime(2016, 1, 1));
            ProducerSubmission producer2 = ProducerBuilder.WithCeaseToExist(new DateTime(2016, 1, 1));

            Assert.Equal(producer1, producer2);
        }
示例#12
0
        public void Equals_ProducerSubmissionsWithDifferentCeaseToExistDates_ReturnsFalse()
        {
            ProducerSubmission producer1 = ProducerBuilder.WithCeaseToExist(new DateTime(2016, 1, 1));
            ProducerSubmission producer2 = ProducerBuilder.WithCeaseToExist(new DateTime(2016, 1, 2));

            Assert.NotEqual(producer1, producer2);
        }
        public async Task Execute_WithOneCurrentProducerAsCompany_ReturnsCompanyName()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "WEE/11AAAA11");

                db.Model.SaveChanges();

                // Act
                List <MembersDetailsCsvData> results = await db.StoredProcedures.SpgCSVDataBySchemeComplianceYearAndAuthorisedAuthority(2016, false, false, scheme1.Id, null);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);

                MembersDetailsCsvData result = results[0];

                Assert.Equal(producer1.Business.Company.Name, result.ProducerName);
            }
        }
示例#14
0
        public void AssignToInvoiceRun_SetsProducerSubmissionAsInvoiced()
        {
            Scheme       scheme       = A.Fake <Scheme>();
            MemberUpload memberUpload = new MemberUpload(A.Dummy <Guid>(), "data", null, 100, 2015, scheme, "fileName");

            var registeredProducer = new RegisteredProducer("PRN", 2015, scheme);

            var producer = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                new ProducerBusiness(),
                null,
                new DateTime(2015, 1, 1),
                0,
                false,
                null,
                "Trading Name 1",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List <BrandName>(),
                new List <SICCode>(),
                A.Dummy <ChargeBandAmount>(),
                0,
                A.Dummy <StatusType>());

            memberUpload.ProducerSubmissions.Add(producer);
            memberUpload.Submit(A.Dummy <User>());

            memberUpload.AssignToInvoiceRun(A.Dummy <InvoiceRun>());

            Assert.True(producer.Invoiced);
        }
        public async Task Execute_HappyPath_ReturnsProducerWithSelectedSchemeandAA()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                scheme1.CompetentAuthorityId = new Guid("4EEE5942-01B2-4A4D-855A-34DEE1BBBF26");

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "WEE/11AAAA11");

                db.Model.SaveChanges();

                // Act
                List <MembersDetailsCsvData> results =
                    await db.StoredProcedures.SpgCSVDataBySchemeComplianceYearAndAuthorisedAuthority(2016, false,
                                                                                                     false, scheme1.Id, scheme1.CompetentAuthorityId);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);

                MembersDetailsCsvData result = results[0];

                Assert.Equal("WEE/11AAAA11", result.PRN);
            }
        }
        public async Task Execute_ProducerAsCompany_ReturnsCompanyName()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "WEE/11AAAA11");

                db.Model.SaveChanges();

                // Act
                List <ProducerAmendmentsHistoryCSVData> results =
                    await db.StoredProcedures.SpgProducerAmendmentsCSVDataByPRN("WEE/11AAAA11");

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);

                Assert.Equal(producer1.Business.Company.Name, results[0].ProducerName);
            }
        }
        public async Task Execute_WithOneCurrentProducerAsPartnership_ReturnsPartnershipName()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/11AAAA11");

                db.Model.SaveChanges();

                // Act
                List <ProducerCsvData> results =
                    await db.StoredProcedures.SpgCSVDataByOrganisationIdAndComplianceYear(scheme1.OrganisationId, 2016);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);

                ProducerCsvData result = results[0];

                Assert.Equal(producer1.Business.Partnership.Name, result.OrganisationName);
            }
        }
示例#18
0
        public async Task GetChanges_ReturnsRecordsSortedByProducerNameFollowedByLatestSubmissionDate()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme = helper.CreateScheme();

                MemberUpload memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = 2016;

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload, "WEE/11AAA11");
                producer1.Business.Company.Name = "AAA";

                var previousDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                previousDataReturnVersion.SubmittedDate = new DateTime(2016, 1, 1);
                helper.CreateEeeOutputAmount(previousDataReturnVersion, producer1.RegisteredProducer, "B2B", 1, 10);

                var currentDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                currentDataReturnVersion.SubmittedDate = new DateTime(2016, 2, 1);
                helper.CreateEeeOutputAmount(currentDataReturnVersion, producer1.RegisteredProducer, "B2B", 1, 12);

                var producer2 = helper.CreateProducerAsCompany(memberUpload, "WEE/11BBB11");
                producer2.Business.Company.Name = "BBB";

                helper.CreateEeeOutputAmount(currentDataReturnVersion, producer2.RegisteredProducer, "B2B", 1, 30);

                db.Model.SaveChanges();

                var dataAccess = new GetDataReturnSubmissionEeeChangesCsvDataAccess(db.WeeeContext);

                // Act
                var results = await dataAccess.GetChanges(currentDataReturnVersion.Id, previousDataReturnVersion.Id);

                // Assert
                Assert.Equal(3, results.CsvData.Count);

                Assert.Equal("AAA", results.CsvData[0].ProducerName);
                Assert.Equal(DataReturnSubmissionChangeType.Amended, results.CsvData[0].ChangeType);
                Assert.Equal(12, results.CsvData[0].Cat1B2B);
                Assert.Equal(new DateTime(2016, 2, 1), results.CsvData[0].SubmissionDate);

                Assert.Equal("AAA", results.CsvData[1].ProducerName);
                Assert.Null(results.CsvData[1].ChangeType);
                Assert.Equal(10, results.CsvData[1].Cat1B2B);
                Assert.Equal(new DateTime(2016, 1, 1), results.CsvData[1].SubmissionDate);

                Assert.Equal("BBB", results.CsvData[2].ProducerName);
                Assert.Equal(DataReturnSubmissionChangeType.New, results.CsvData[2].ChangeType);
                Assert.Equal(30, results.CsvData[2].Cat1B2B);
                Assert.Equal(new DateTime(2016, 2, 1), results.CsvData[2].SubmissionDate);
            }
        }
示例#19
0
        public void Producer_SetProducerPartnershipCountry_Returns_RegOfficeOrPPoBCountry()
        {
            // Arrange
            Scheme scheme = new Scheme(
                A.Dummy <Guid>());

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                2019,
                scheme,
                A.Dummy <string>(),
                A.Dummy <string>());

            RegisteredProducer registeredProducer = new RegisteredProducer(
                "WEE/AA1111AA",
                2019,
                scheme);

            var producerAddress = new ProducerAddress("PrimaryName", "SecondaryName", "Street", "Town", "Locality", "AdministrativeArea",
                                                      new Country(A.Dummy <Guid>(), "SPAIN"), "PostCode");

            var producerContact = new ProducerContact(
                "Title", "Forename", "Surname", "123456", "1235467", "12345678", "[email protected]", producerAddress);

            var producerBusiness = new ProducerBusiness(
                partnership: new Partnership("TestPartnership", producerContact, new List <Partner> {
            }));

            var producer = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                producerBusiness,
                null,
                new DateTime(2019, 3, 18),
                0,
                false,
                null,
                "Trading Name 1",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                Domain.Obligation.ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List <Domain.Producer.BrandName>(),
                new List <Domain.Producer.SICCode>(),
                A.Dummy <ChargeBandAmount>(),
                0,
                A.Dummy <StatusType>());

            Assert.Equal("SPAIN", producer.RegOfficeOrPBoBCountry);
        }
        public async Task Execute_MultipleTimeProducerAmendmentsDuringComplianceYear_ReturnsAllAmendmentsRecordsWithPerfectRegisteredDateAndUpdatedDate()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                scheme1.SchemeName = "SchemeName";

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producerSubmission1 = helper.CreateProducerAsCompany(memberUpload1, "WEE/99ZZZZ99");

                MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme1);
                memberUpload2.ComplianceYear = 2016;
                memberUpload2.IsSubmitted    = true;
                memberUpload2.SubmittedDate  = new DateTime(2015, 1, 2);

                ProducerSubmission producerSubmission2 = helper.CreateProducerAsCompany(memberUpload2, "WEE/99ZZZZ99");

                MemberUpload memberUpload3 = helper.CreateMemberUpload(scheme1);
                memberUpload3.ComplianceYear = 2016;
                memberUpload3.IsSubmitted    = true;
                memberUpload3.SubmittedDate  = new DateTime(2015, 1, 3);

                ProducerSubmission producerSubmission3 = helper.CreateProducerAsCompany(memberUpload3, "WEE/99ZZZZ99");

                db.Model.SaveChanges();

                // Act
                List <ProducerAmendmentsHistoryCSVData> results =
                    await db.StoredProcedures.SpgProducerAmendmentsCSVDataByPRN("WEE/99ZZZZ99");

                // Assert
                Assert.NotNull(results);
                Assert.Equal(results.Count, 3);

                results = results.OrderBy(i => i.DateAmended).ToList();

                Assert.Equal(new DateTime(2015, 1, 1), results[0].DateRegistered);
                Assert.Equal(new DateTime(2015, 1, 1), results[1].DateRegistered);
                Assert.Equal(new DateTime(2015, 1, 1), results[2].DateRegistered);

                Assert.Equal(new DateTime(2015, 1, 1), results[0].DateAmended);
                Assert.Equal(new DateTime(2015, 1, 2), results[1].DateAmended);
                Assert.Equal(new DateTime(2015, 1, 3), results[2].DateAmended);
            }
        }
        public async Task Execute_WithDifferentChargeBandTypes_ReturnsChargeBandLetters()
        {
            {
                using (DatabaseWrapper db = new DatabaseWrapper())
                {
                    // Arrange
                    ModelHelper helper = new ModelHelper(db.Model);

                    Scheme scheme1 = helper.CreateScheme();

                    MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                    memberUpload1.ComplianceYear = 2016;
                    memberUpload1.IsSubmitted    = true;
                    memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                    ProducerSubmission producer1 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/11AAAA11");
                    producer1.ChargeBandAmount = helper.FetchChargeBandAmount(ChargeBand.A);

                    ProducerSubmission producer2 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/22BBBB22");
                    producer2.ChargeBandAmount = helper.FetchChargeBandAmount(ChargeBand.B);

                    ProducerSubmission producer3 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/33CCCC33");
                    producer3.ChargeBandAmount = helper.FetchChargeBandAmount(ChargeBand.C);

                    ProducerSubmission producer4 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/44DDDD44");
                    producer4.ChargeBandAmount = helper.FetchChargeBandAmount(ChargeBand.D);

                    ProducerSubmission producer5 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/55EEEE55");
                    producer5.ChargeBandAmount = helper.FetchChargeBandAmount(ChargeBand.E);

                    db.Model.SaveChanges();

                    // Act
                    List <ProducerCsvData> results =
                        await db.StoredProcedures.SpgCSVDataByOrganisationIdAndComplianceYear(scheme1.OrganisationId, 2016);

                    // Assert
                    Assert.NotNull(results);
                    Assert.Equal(5, results.Count);

                    Assert.Collection(results,
                                      (r1) => Assert.Equal("A", r1.ChargeBand),
                                      (r2) => Assert.Equal("B", r2.ChargeBand),
                                      (r3) => Assert.Equal("C", r3.ChargeBand),
                                      (r4) => Assert.Equal("D", r4.ChargeBand),
                                      (r5) => Assert.Equal("E", r5.ChargeBand));
                }
            }
        }
        public async Task Execute_WithSeveralVersionsOfOneCurrentProducer_ReturnsLatestDataWithFirstRegistrationDate()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/11AAAA11");

                MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme1);
                memberUpload2.ComplianceYear = 2016;
                memberUpload2.IsSubmitted    = true;
                memberUpload2.SubmittedDate  = new DateTime(2015, 1, 2);

                ProducerSubmission producer2 = helper.CreateProducerAsPartnership(memberUpload2, "WEE/11AAAA11");

                MemberUpload memberUpload3 = helper.CreateMemberUpload(scheme1);
                memberUpload3.ComplianceYear = 2016;
                memberUpload3.IsSubmitted    = true;
                memberUpload3.SubmittedDate  = new DateTime(2015, 1, 3);

                ProducerSubmission producer3 = helper.CreateProducerAsPartnership(memberUpload3, "WEE/11AAAA11");

                db.Model.SaveChanges();

                // Act
                List <ProducerCsvData> results =
                    await db.StoredProcedures.SpgCSVDataByOrganisationIdAndComplianceYear(scheme1.OrganisationId, 2016);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);

                ProducerCsvData result = results[0];

                Assert.Equal("WEE/11AAAA11", result.RegistrationNumber);
                Assert.Equal(new DateTime(2015, 1, 1), result.DateRegistered);
                Assert.Equal(new DateTime(2015, 1, 3), result.DateAmended);
            }
        }
示例#23
0
        public void Producer_SetProducerCompanyCountry_Returns_RegOfficeOrPPoBCountry()
        {
            // Arrange
            Scheme scheme = new Scheme(
                A.Dummy <Guid>());

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                2019,
                scheme,
                A.Dummy <string>(),
                A.Dummy <string>());

            RegisteredProducer registeredProducer = new RegisteredProducer(
                "WEE/AA1111AA",
                2019,
                scheme);

            var producer = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                new EA.Weee.Domain.Producer.ProducerBusiness(
                    new Company("CompanyName", "RegisteredNo",
                                new ProducerContact(A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(),
                                                    new ProducerAddress(A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(), A.Dummy <string>(),
                                                                        new Country(Guid.NewGuid(), "FRANCE"), A.Dummy <string>())))),
                null,
                new DateTime(2019, 3, 18),
                0,
                false,
                null,
                "Trading Name 1",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                Domain.Obligation.ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List <Domain.Producer.BrandName>(),
                new List <Domain.Producer.SICCode>(),
                A.Dummy <ChargeBandAmount>(),
                0,
                A.Dummy <StatusType>());

            Assert.Equal("FRANCE", producer.RegOfficeOrPBoBCountry);
        }
示例#24
0
            private ProducerSubmission Build()
            {
                Scheme scheme = new Scheme(
                    A.Dummy <Guid>());

                var memberUpload = new MemberUpload(
                    A.Dummy <Guid>(),
                    A.Dummy <string>(),
                    A.Dummy <List <MemberUploadError> >(),
                    A.Dummy <decimal>(),
                    2017,
                    scheme,
                    A.Dummy <string>(),
                    A.Dummy <string>());

                var updatedDate = A.Dummy <DateTime>();

                RegisteredProducer registeredProducer = new RegisteredProducer(
                    registrationNumber,
                    2017,
                    scheme);

                ProducerSubmission producerSubmission = new ProducerSubmission(
                    registeredProducer,
                    memberUpload,
                    producerBusiness,
                    authorisedRepresentative,
                    updatedDate,
                    annualTurnover,
                    vatRegistered,
                    ceaseToExist,
                    tradingName,
                    eeePlacedOnMarketBandType,
                    sellingTechniqueType,
                    obligationType,
                    annualTurnOverBandType,
                    brandNames,
                    sicCodes,
                    chargeBandAmount,
                    (decimal)5.0,
                    status);

                registeredProducer.SetCurrentSubmission(producerSubmission);

                return(producerSubmission);
            }
示例#25
0
        public void Producer_SetProducerMemberUpload_HasAnnualCharge_Returns_No()
        {
            // Arrange
            Scheme scheme = new Scheme(
                A.Dummy <Guid>());

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                2019,
                scheme,
                A.Dummy <string>(),
                A.Dummy <string>(),
                false);

            RegisteredProducer registeredProducer = new RegisteredProducer(
                "WEE/AA1111AA",
                2019,
                scheme);

            var producer = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy <ProducerBusiness>(),
                null,
                new DateTime(2019, 3, 21),
                0,
                false,
                null,
                "Trading Name 1",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                Domain.Obligation.ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List <Domain.Producer.BrandName>(),
                new List <Domain.Producer.SICCode>(),
                A.Dummy <ChargeBandAmount>(),
                0,
                A.Dummy <StatusType>());

            Assert.Equal("No", producer.HasAnnualCharge);
        }
        public async Task Execute_HappyPath_ReturnsParticularPRNRecords()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                scheme1.SchemeName = "SchemeName";

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producerSubmission1 = helper.CreateProducerAsCompany(memberUpload1, "WEE/99ZZZZ99");
                ProducerSubmission producerSubmission2 = helper.CreateProducerAsCompany(memberUpload1, "WEE/11ZZZZ11");
                producerSubmission2.VATRegistered = true;

                Scheme scheme2 = helper.CreateScheme();

                MemberUpload memberUpload2 = helper.CreateMemberUpload(scheme2);
                memberUpload2.ComplianceYear = 2017;
                memberUpload2.IsSubmitted    = true;
                memberUpload2.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producerSubmission3 = helper.CreateProducerAsCompany(memberUpload2, "WEE/11ZZZZ11");
                producerSubmission2.VATRegistered = false;

                db.Model.SaveChanges();

                // Act
                List <ProducerAmendmentsHistoryCSVData> results =
                    await db.StoredProcedures.SpgProducerAmendmentsCSVDataByPRN("WEE/11ZZZZ11");

                // Assert
                Assert.NotNull(results);
                Assert.Equal(results.Count, 2);
                Assert.True(results.TrueForAll(i => i.PRN == "WEE/11ZZZZ11"));
                Assert.False(results.TrueForAll(i => i.VATRegistered));
            }
        }
        public async Task Execute_WithAuthorisedRepresentative_ReturnsOverseasProducer()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "WEE/11AAAA11");

                AuthorisedRepresentative authorisedRepresentative = new AuthorisedRepresentative()
                {
                    Id = new Guid("620E71A6-0E74-47AF-B82F-97BA64083E37"),
                    OverseasProducerName = "Overseas Producer Name",
                };
                db.Model.AuthorisedRepresentatives.Add(authorisedRepresentative);

                producer1.AuthorisedRepresentative = authorisedRepresentative;

                db.Model.SaveChanges();

                // Act
                List <ProducerCsvData> results =
                    await db.StoredProcedures.SpgCSVDataByOrganisationIdAndComplianceYear(scheme1.OrganisationId, 2016);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);

                ProducerCsvData result = results[0];

                Assert.Equal("No", result.AuthorisedRepresentative);
                Assert.Equal("Overseas Producer Name", result.OverseasProducer);
            }
        }
示例#28
0
        public async Task GetChanges_WithNoEeeForCurrentSubmission_AndDataForPreviousSubmission_ReturnsDataAsRemoved()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme = helper.CreateScheme();

                MemberUpload memberUpload = helper.CreateSubmittedMemberUpload(scheme);
                memberUpload.ComplianceYear = 2016;

                ProducerSubmission producer = helper.CreateProducerAsCompany(memberUpload, "WEE/11BBBB11");

                var eeeOutputAmount1 = helper.CreateEeeOutputAmount(producer.RegisteredProducer, "B2B", 1, 10);
                var eeeOutputAmount2 = helper.CreateEeeOutputAmount(producer.RegisteredProducer, "B2B", 2, 20);

                var previousDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                previousDataReturnVersion.SubmittedDate = new DateTime(2016, 1, 1);

                helper.AddEeeOutputAmount(previousDataReturnVersion, eeeOutputAmount1);
                helper.AddEeeOutputAmount(previousDataReturnVersion, eeeOutputAmount2);

                var currentDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2016, 1, true);
                currentDataReturnVersion.SubmittedDate = new DateTime(2016, 2, 1);

                db.Model.SaveChanges();

                var dataAccess = new GetDataReturnSubmissionEeeChangesCsvDataAccess(db.WeeeContext);

                // Act
                var results = await dataAccess.GetChanges(currentDataReturnVersion.Id, previousDataReturnVersion.Id);

                // Assert
                Assert.Single(results.CsvData);
                Assert.Equal(DataReturnSubmissionChangeType.Removed, results.CsvData[0].ChangeType);
                Assert.Null(results.CsvData[0].Cat1B2B);
                Assert.Null(results.CsvData[0].Cat2B2B);
                Assert.Equal(new DateTime(2016, 2, 1), results.CsvData[0].SubmissionDate);
            }
        }
        public async Task Execute_WithSeveralProducersAndIncludeRemovedProducersIsYes_ReturnsAllProducersWithRemovedProducers()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/11BBBB11");
                producer1.Business.Partnership.Name  = "ABCH";
                producer1.RegisteredProducer.Removed = true;

                ProducerSubmission producer2 = helper.CreateProducerAsCompany(memberUpload1, "WEE/22AAAA22");
                producer2.Business.Company.Name      = "AAAA";
                producer2.RegisteredProducer.Removed = true;

                ProducerSubmission producer3 = helper.CreateProducerAsPartnership(memberUpload1, "WEE/33CCCC33");
                producer3.Business.Partnership.Name = "ABCD";

                db.Model.SaveChanges();

                // Act
                List <MembersDetailsCsvData> results = await db.StoredProcedures.SpgCSVDataBySchemeComplianceYearAndAuthorisedAuthority(2016, true, false, scheme1.Id, null);

                // Assert
                Assert.NotNull(results);

                Assert.Equal(3, results.Count);
                Assert.Collection(results,
                                  (r1) => Assert.Equal("WEE/22AAAA22", r1.PRN),
                                  (r2) => Assert.Equal("WEE/33CCCC33", r2.PRN),
                                  (r3) => Assert.Equal("WEE/11BBBB11", r3.PRN));
            }
        }
        public async Task Execute_WithOneCurrentProducer_ReturnsFullSetOfData()
        {
            using (DatabaseWrapper db = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(db.Model);

                Scheme scheme1 = helper.CreateScheme();

                MemberUpload memberUpload1 = helper.CreateMemberUpload(scheme1);
                memberUpload1.ComplianceYear = 2016;
                memberUpload1.IsSubmitted    = true;
                memberUpload1.SubmittedDate  = new DateTime(2015, 1, 1);

                ProducerSubmission producer1 = helper.CreateProducerAsCompany(memberUpload1, "WEE/11AAAA11");
                producer1.ChargeBandAmount = helper.FetchChargeBandAmount(ChargeBand.C);

                db.Model.SaveChanges();

                // Act
                List <ProducerCsvData> results =
                    await db.StoredProcedures.SpgCSVDataByOrganisationIdAndComplianceYear(scheme1.OrganisationId, 2016);

                // Assert
                Assert.NotNull(results);
                Assert.Equal(1, results.Count);

                ProducerCsvData result = results[0];

                Assert.Equal(producer1.Business.Company.Name, result.OrganisationName);
                Assert.Equal(producer1.TradingName, result.TradingName);
                Assert.Equal("WEE/11AAAA11", result.RegistrationNumber);
                Assert.Equal(producer1.Business.Company.CompanyNumber, result.CompanyNumber);
                Assert.Equal("C", result.ChargeBand);
                Assert.Equal(new DateTime(2015, 1, 1), result.DateRegistered);
                Assert.Equal(new DateTime(2015, 1, 1), result.DateAmended);
                Assert.Equal("No", result.AuthorisedRepresentative);
                Assert.Equal(string.Empty, result.OverseasProducer);
            }
        }
        public void AssignToInvoiceRun_DoesNotSetRemovedProducerSubmissionAsInvoiced()
        {
            Scheme scheme = A.Fake<Scheme>();
            MemberUpload memberUpload = new MemberUpload(A.Dummy<Guid>(), "data", null, 100, 2015, scheme, "fileName");

            var registeredProducer = new RegisteredProducer("PRN", 2015, scheme);
            registeredProducer.Remove();

            var producer = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                new ProducerBusiness(),
                null,
                new DateTime(2015, 1, 1),
                0,
                false,
                null,
                "Trading Name 1",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List<BrandName>(),
                new List<SICCode>(),
                A.Dummy<ChargeBandAmount>(),
                0);

            memberUpload.ProducerSubmissions.Add(producer);
            memberUpload.Submit(A.Dummy<User>());

            memberUpload.AssignToInvoiceRun(A.Dummy<InvoiceRun>());

            Assert.False(producer.Invoiced);
        }
        public async Task CreateTransactionFile_WithTwoMemberUploads_CreatesTwoInvoices()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Organisation organisation = Organisation.CreateSoleTrader("Test organisation");

            Scheme scheme = new Scheme(organisation);
            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear = A.Dummy<int>();

            MemberUpload memberUpload1 = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            RegisteredProducer registeredProducer1 = new RegisteredProducer("WEE/11AAAA11", complianceYear, scheme);

            ProducerSubmission producerSubmission1 = new ProducerSubmission(
                registeredProducer1,
                memberUpload1,
                A.Dummy<ProducerBusiness>(),
                A.Dummy<AuthorisedRepresentative>(),
                A.Dummy<DateTime>(),
                A.Dummy<decimal>(),
                A.Dummy<bool>(),
                A.Dummy<DateTime?>(),
                A.Dummy<string>(),
                A.Dummy<EEEPlacedOnMarketBandType>(),
                A.Dummy<SellingTechniqueType>(),
                A.Dummy<ObligationType>(),
                A.Dummy<AnnualTurnOverBandType>(),
                A.Dummy<List<BrandName>>(),
                A.Dummy<List<SICCode>>(),
                A.Dummy<Domain.Lookup.ChargeBandAmount>(),
                100m);

            memberUpload1.ProducerSubmissions.Add(producerSubmission1);

            memberUpload1.Submit(A.Dummy<User>());

            MemberUpload memberUpload2 = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            RegisteredProducer registeredProducer2 = new RegisteredProducer("WEE/22BBBB22", complianceYear, scheme);

            ProducerSubmission producerSubmission2 = new ProducerSubmission(
                registeredProducer2,
                memberUpload2,
                A.Dummy<ProducerBusiness>(),
                A.Dummy<AuthorisedRepresentative>(),
                A.Dummy<DateTime>(),
                A.Dummy<decimal>(),
                A.Dummy<bool>(),
                A.Dummy<DateTime?>(),
                A.Dummy<string>(),
                A.Dummy<EEEPlacedOnMarketBandType>(),
                A.Dummy<SellingTechniqueType>(),
                A.Dummy<ObligationType>(),
                A.Dummy<AnnualTurnOverBandType>(),
                A.Dummy<List<BrandName>>(),
                A.Dummy<List<SICCode>>(),
                A.Dummy<Domain.Lookup.ChargeBandAmount>(),
                100m);

            memberUpload2.ProducerSubmissions.Add(producerSubmission2);

            memberUpload2.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload1);
            memberUploads.Add(memberUpload2);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

            ITransactionReferenceGenerator transactionReferenceGenerator = A.Fake<ITransactionReferenceGenerator>();
            A.CallTo(() => transactionReferenceGenerator.GetNextTransactionReferenceAsync()).Returns("WEE800001H");

            ByChargeValueTransactionFileGenerator generator = new ByChargeValueTransactionFileGenerator(transactionReferenceGenerator);

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);
            TransactionFile transactionFile = result.IbisFile;

            // Assert
            Assert.NotNull(transactionFile);
            Assert.Equal(2, transactionFile.Invoices.Count);

            Invoice invoice1 = transactionFile.Invoices[0];
            Assert.NotNull(invoice1);
            Assert.Equal(100m, invoice1.TransactionTotal);

            Invoice invoice2 = transactionFile.Invoices[1];
            Assert.NotNull(invoice2);
            Assert.Equal(100m, invoice2.TransactionTotal);
        }
        public async Task CreateTransactionFile_WithOneProducerSubmission_CreatesOneInvoiceWithOneLineItem()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Organisation organisation = Organisation.CreateSoleTrader("Test organisation");

            Scheme scheme = new Scheme(organisation);
            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear = A.Dummy<int>();

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            RegisteredProducer registeredProducer = new RegisteredProducer("WEE/11AAAA11", complianceYear, scheme);

            ProducerSubmission producerSubmission = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy<ProducerBusiness>(),
                A.Dummy<AuthorisedRepresentative>(),
                A.Dummy<DateTime>(),
                A.Dummy<decimal>(),
                A.Dummy<bool>(),
                A.Dummy<DateTime?>(),
                A.Dummy<string>(),
                A.Dummy<EEEPlacedOnMarketBandType>(),
                A.Dummy<SellingTechniqueType>(),
                A.Dummy<ObligationType>(),
                A.Dummy<AnnualTurnOverBandType>(),
                A.Dummy<List<BrandName>>(),
                A.Dummy<List<SICCode>>(),
                A.Dummy<Domain.Lookup.ChargeBandAmount>(),
                123.45m);

            memberUpload.ProducerSubmissions.Add(producerSubmission);

            memberUpload.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload);

            SystemTime.Freeze(new DateTime(2015, 12, 31));
            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());
            SystemTime.Unfreeze();

            ITransactionReferenceGenerator transactionReferenceGenerator = A.Fake<ITransactionReferenceGenerator>();
            A.CallTo(() => transactionReferenceGenerator.GetNextTransactionReferenceAsync()).Returns("WEE800001H");

            ByChargeValueTransactionFileGenerator generator = new ByChargeValueTransactionFileGenerator(transactionReferenceGenerator);

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);
            TransactionFile transactionFile = result.IbisFile;

            // Assert
            Assert.NotNull(transactionFile);
            Assert.Equal(1, transactionFile.Invoices.Count);

            Invoice invoice = transactionFile.Invoices[0];
            Assert.NotNull(invoice);

            Assert.Equal(TransactionType.Invoice, invoice.TransactionType);
            Assert.Equal("WEE800001H", invoice.TransactionReference);
            Assert.Equal(123.45m, invoice.TransactionTotal);
            Assert.Equal(null, invoice.TransactionHeaderNarrative);
            Assert.Equal(new DateTime(2015, 12, 31), invoice.TransactionDate);
            Assert.Equal(null, invoice.RelatedTransactionReference);
            Assert.Equal(CurrencyCode.GBP, invoice.CurrencyCode);
            Assert.Equal("WEE00000001", invoice.CustomerReference);

            Assert.NotNull(invoice.LineItems);
            Assert.Equal(1, invoice.LineItems.Count);

            InvoiceLineItem lineItem = invoice.LineItems[0];
            Assert.NotNull(lineItem);

            Assert.Equal(123.45m, lineItem.AmountExcludingVAT);
            Assert.Equal("1 producer registration charge at £123.45.", lineItem.Description);
            Assert.Equal("H", lineItem.AreaCode);
            Assert.Equal("H", lineItem.ContextCode);
            Assert.Equal("W", lineItem.IncomeStreamCode);
            Assert.Equal((ulong)1, lineItem.Quantity);
            Assert.Equal(UnitOfMeasure.Each, lineItem.UnitOfMeasure);
            Assert.Equal(null, lineItem.VatCode);
        }
        public async Task HandleAsync_HappyPath_ReturnsProducerDetailsSchemeObjectWithPerfectValue()
        {
            // Arrange
            Scheme scheme = new Scheme(
               A.Dummy<Guid>());

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                2017,
                scheme,
                A.Dummy<string>(),
                A.Dummy<string>());

            RegisteredProducer registeredProducer = new RegisteredProducer(
                "WEE/AA1111AA",
                2017,
                scheme);

            var producer = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                new EA.Weee.Domain.Producer.ProducerBusiness(
                    new Company("CompanyName", "RegisteredNo",
                    new ProducerContact(A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(),
                    new ProducerAddress(A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(), A.Dummy<string>(),
                    new Country(Guid.NewGuid(), A.Dummy<string>()), A.Dummy<string>())))),
                null,
                new DateTime(2015, 1, 1),
                0,
                false,
                null,
                "Trading Name 1",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                Domain.Obligation.ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List<Domain.Producer.BrandName>(),
                new List<Domain.Producer.SICCode>(),
                A.Dummy<ChargeBandAmount>(),
                0);

            registeredProducer.SetCurrentSubmission(producer);

            registeredProducer.Scheme.UpdateScheme("SchemeName", "WEE/FA9999KE/SCH", "test", ObligationType.B2B, Guid.NewGuid());

            IGetProducerDetailsByRegisteredProducerIdDataAccess dataAccess = A.Fake<IGetProducerDetailsByRegisteredProducerIdDataAccess>();
            A.CallTo(() => dataAccess.Fetch(registeredProducer.Id))
                .Returns(registeredProducer);

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            GetProducerDetailsByRegisteredProducerIdHandler handler = new GetProducerDetailsByRegisteredProducerIdHandler(dataAccess, authorization);

            Requests.Admin.GetProducerDetailsByRegisteredProducerId request =
                new Requests.Admin.GetProducerDetailsByRegisteredProducerId(registeredProducer.Id);

            // Act
            ProducerDetailsScheme result = await handler.HandleAsync(request);

            // Assert
            Assert.Equal(result.ComplianceYear, registeredProducer.ComplianceYear);
            Assert.Equal(result.ProducerName, registeredProducer.CurrentSubmission.OrganisationName);
            Assert.Equal(result.SchemeName, registeredProducer.Scheme.SchemeName);
            Assert.Equal(result.RegistrationNumber, registeredProducer.ProducerRegistrationNumber);
        }
        public async Task CreateTransactionFile_WithExceptionThrown_ReturnsError_AndNoTransactionFile()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Organisation organisation = Organisation.CreateSoleTrader("Test organisation");

            Scheme scheme = new Scheme(organisation);
            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear = A.Dummy<int>();

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            RegisteredProducer registeredProducer = new RegisteredProducer("WEE/11AAAA11", complianceYear, scheme);

            ProducerSubmission producerSubmission = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy<ProducerBusiness>(),
                A.Dummy<AuthorisedRepresentative>(),
                A.Dummy<DateTime>(),
                A.Dummy<decimal>(),
                A.Dummy<bool>(),
                A.Dummy<DateTime?>(),
                A.Dummy<string>(),
                A.Dummy<EEEPlacedOnMarketBandType>(),
                A.Dummy<SellingTechniqueType>(),
                A.Dummy<ObligationType>(),
                A.Dummy<AnnualTurnOverBandType>(),
                A.Dummy<List<BrandName>>(),
                A.Dummy<List<SICCode>>(),
                A.Dummy<Domain.Lookup.ChargeBandAmount>(),
                100M);

            memberUpload.ProducerSubmissions.Add(producerSubmission);

            memberUpload.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

            ITransactionReferenceGenerator transactionReferenceGenerator = A.Fake<ITransactionReferenceGenerator>();
            A.CallTo(() => transactionReferenceGenerator.GetNextTransactionReferenceAsync()).Returns((string)null); // A null value will cause the Ibis object to throw an exception.

            ByChargeValueTransactionFileGenerator generator = new ByChargeValueTransactionFileGenerator(
                transactionReferenceGenerator);

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);

            // Assert
            Assert.Null(result.IbisFile);
            Assert.NotEmpty(result.Errors);
        }
        public async Task HandleAsync_WithDataReturnWithNoEee_SetsHasSubmittedEEEToFalse()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            Organisation organisation = Organisation.CreateSoleTrader("Trading Name");

            Scheme scheme = new Scheme(organisation);

            RegisteredProducer registeredProducer = new RegisteredProducer("WEE/AA1111AA", 2016, scheme);

            Guid registeredProducerId = new Guid("75B6B4E7-BA92-477D-A6CA-C43C8C0E9823");
            typeof(Entity).GetProperty("Id").SetValue(registeredProducer, registeredProducerId);

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                "data",
                new List<MemberUploadError>(),
                0,
                2016,
                scheme,
                "file.xml",
                "UserID");

            ProducerSubmission producerSubmission = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy<ProducerBusiness>(),
                A.Dummy<AuthorisedRepresentative>(),
                A.Dummy<DateTime>(),
                A.Dummy<decimal?>(),
                A.Dummy<bool>(),
                A.Dummy<DateTime?>(),
                A.Dummy<string>(),
                A.Dummy<EEEPlacedOnMarketBandType>(),
                A.Dummy<SellingTechniqueType>(),
                A.Dummy<ObligationType>(),
                A.Dummy<AnnualTurnOverBandType>(),
                A.Dummy<List<BrandName>>(),
                A.Dummy<List<SICCode>>(),
                A.Dummy<ChargeBandAmount>(),
                A.Dummy<decimal>());

            registeredProducer.SetCurrentSubmission(producerSubmission);
            DataReturn dataReturn = new DataReturn(scheme, new Quarter(2016, QuarterType.Q4));

            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            dataReturnVersion.Submit("UserID");

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

            A.CallTo(() => dataAccess.Fetch(registeredProducerId)).Returns(registeredProducer);
            A.CallTo(() => dataAccess.FetchDataReturns(scheme, 2016)).Returns(new List<DataReturn>() { dataReturn });

            GetProducerDetailsByRegisteredProducerIdHandler handler = new GetProducerDetailsByRegisteredProducerIdHandler(dataAccess, authorization);

            // Act
            GetProducerDetailsByRegisteredProducerId request = new GetProducerDetailsByRegisteredProducerId(registeredProducerId);
            ProducerDetailsScheme result = await handler.HandleAsync(request);

            // Assert
            Assert.Equal(false, result.HasSubmittedEEE);
        }
        public async Task CreateTransactionFile_ProducerSubmissionWithNoCharge_NotIncludedInTransactionFile()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Organisation organisation = Organisation.CreateSoleTrader("Test organisation");

            Scheme scheme = new Scheme(organisation);
            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear = A.Dummy<int>();

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            RegisteredProducer registeredProducer = new RegisteredProducer("WEE/11AAAA11", complianceYear, scheme);

            ProducerSubmission producerSubmission = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy<ProducerBusiness>(),
                A.Dummy<AuthorisedRepresentative>(),
                A.Dummy<DateTime>(),
                A.Dummy<decimal>(),
                A.Dummy<bool>(),
                A.Dummy<DateTime?>(),
                A.Dummy<string>(),
                A.Dummy<EEEPlacedOnMarketBandType>(),
                A.Dummy<SellingTechniqueType>(),
                A.Dummy<ObligationType>(),
                A.Dummy<AnnualTurnOverBandType>(),
                A.Dummy<List<BrandName>>(),
                A.Dummy<List<SICCode>>(),
                A.Dummy<Domain.Lookup.ChargeBandAmount>(),
                0);

            memberUpload.ProducerSubmissions.Add(producerSubmission);

            memberUpload.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

            ByChargeValueTransactionFileGenerator generator = new ByChargeValueTransactionFileGenerator(
                A.Dummy<ITransactionReferenceGenerator>());

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);
            TransactionFile transactionFile = result.IbisFile;

            // Assert
            Assert.NotNull(transactionFile);
            Assert.Equal(0, transactionFile.Invoices.Count);
        }
        public async Task<IEnumerable<ProducerSubmission>> GenerateProducerData(schemeType scheme, MemberUpload memberUpload, Dictionary<string, ProducerCharge> producerCharges)
        {
            if (memberUpload.ComplianceYear == null)
            {
                string errorMessage = "Producers cannot be generated for a member upload "
                    + "that does not have a compliance year.";
                throw new InvalidOperationException(errorMessage);
            }

            List<ProducerSubmission> producers = new List<ProducerSubmission>();

            int numberOfPrnsNeeded = scheme.producerList.Count(p => p.status == statusType.I);
            Queue<string> generatedPrns = await dataAccess.ComputePrns(numberOfPrnsNeeded);

            foreach (producerType producerData in scheme.producerList)
            {
                var producerName = producerData.GetProducerName();

                if (producerCharges == null)
                {
                    throw new ApplicationException("No charges have been supplied");
                }
                if (!producerCharges.ContainsKey(producerName))
                {
                    throw new ApplicationException(string.Format("No charges have been supplied for the {0}.", producerName));
                }
                var chargeBandAmount = producerCharges[producerName].ChargeBandAmount;
                var chargeThisUpdate = producerCharges[producerName].Amount;

                List<BrandName> brandNames = producerData.producerBrandNames.Select(name => new BrandName(name)).ToList();

                List<SICCode> codes = producerData.SICCodeList.Select(name => new SICCode(name)).ToList();

                ProducerBusiness producerBusiness = await SetProducerBusiness(producerData.producerBusiness);

                AuthorisedRepresentative authorisedRepresentative = await SetAuthorisedRepresentative(producerData.authorisedRepresentative);

                EEEPlacedOnMarketBandType eeebandType = Enumeration.FromValue<EEEPlacedOnMarketBandType>((int)producerData.eeePlacedOnMarketBand);

                SellingTechniqueType sellingTechniqueType = Enumeration.FromValue<SellingTechniqueType>((int)producerData.sellingTechnique);

                ObligationType obligationType = producerData.obligationType.ToDomainObligationType();

                AnnualTurnOverBandType annualturnoverType = Enumeration.FromValue<AnnualTurnOverBandType>((int)producerData.annualTurnoverBand);

                DateTime? ceaseDate = null;
                if (producerData.ceaseToExistDateSpecified)
                {
                    ceaseDate = producerData.ceaseToExistDate;
                }

                RegisteredProducer registeredProducer = null;

                string producerRegistrationNo;
                switch (producerData.status)
                {
                    case statusType.I:
                    producerRegistrationNo = generatedPrns.Dequeue();
                        break;

                    case statusType.A:
                        producerRegistrationNo = producerData.registrationNo;

                        await EnsureProducerRegistrationNumberExists(producerRegistrationNo);

                        registeredProducer = await dataAccess.FetchRegisteredProducerOrDefault(
                            producerRegistrationNo,
                            memberUpload.ComplianceYear.Value,
                            memberUpload.Scheme.Id);
                        break;

                    default:
                        throw new NotSupportedException();
                }

                if (registeredProducer == null)
                {
                    registeredProducer = new RegisteredProducer(
                        producerRegistrationNo,
                        memberUpload.ComplianceYear.Value,
                        memberUpload.Scheme);
                }

                ProducerSubmission producer = new ProducerSubmission(
                    registeredProducer,
                    memberUpload,
                    producerBusiness,
                    authorisedRepresentative,
                    SystemTime.UtcNow,
                    producerData.annualTurnover,
                    producerData.VATRegistered,
                    ceaseDate,
                    producerData.tradingName,
                    eeebandType,
                    sellingTechniqueType,
                    obligationType,
                    annualturnoverType,
                    brandNames,
                    codes,
                    chargeBandAmount,
                    chargeThisUpdate);

                // modify producer data
                switch (producerData.status)
                {
                    case statusType.A:

                        if (registeredProducer.CurrentSubmission == null)
                        {
                            producers.Add(producer);
                        }
                        else
                        {
                            if (!registeredProducer.CurrentSubmission.Equals(producer))
                            {
                                producers.Add(producer);
                            }
                            else
                            {
                                /*
                                 * The producer's details are the same as the current submission for this
                                 * registration so we don't need to update them.
                                 */
                            }
                        }
                        break;

                    case statusType.I:
                        producers.Add(producer);
                        break;
                }
            }

            return producers;
        }
            private ProducerSubmission Build()
            {
                Scheme scheme = new Scheme(
                    A.Dummy<Guid>());

                var memberUpload = new MemberUpload(
                    A.Dummy<Guid>(),
                    A.Dummy<string>(),
                    A.Dummy<List<MemberUploadError>>(),
                    A.Dummy<decimal>(),
                    2017,
                    scheme,
                    A.Dummy<string>(),
                    A.Dummy<string>());

                var updatedDate = A.Dummy<DateTime>();

                RegisteredProducer registeredProducer = new RegisteredProducer(
                    registrationNumber,
                    2017,
                    scheme);

                ProducerSubmission producerSubmission = new ProducerSubmission(
                    registeredProducer,
                    memberUpload,
                    producerBusiness,
                    authorisedRepresentative,
                    updatedDate,
                    annualTurnover,
                    vatRegistered,
                    ceaseToExist,
                    tradingName,
                    eeePlacedOnMarketBandType,
                    sellingTechniqueType,
                    obligationType,
                    annualTurnOverBandType,
                    brandNames,
                    sicCodes,
                    chargeBandAmount,
                    (decimal)5.0);

                registeredProducer.SetCurrentSubmission(producerSubmission);

                return producerSubmission;
            }
 public override bool Equals(ProducerSubmission other)
 {
     return false;
 }