コード例 #1
0
        public void Map_GivenSource_AatfDataListPropertiesShouldBeMapped()
        {
            const string name = "KoalsInTheWild";
            var          competentAuthority = A.Fake <Domain.UKCompetentAuthority>();
            var          organisation       = A.Fake <Organisation>();
            const string approvalNumber     = "123456789";
            var          status             = Domain.AatfReturn.AatfStatus.Approved;
            var          facilityType       = Domain.AatfReturn.FacilityType.Aatf;
            Int16        complianceYear     = 2019;

            var returnStatus             = Core.AatfReturn.AatfStatus.Approved;
            var returnCompetentAuthority = A.Fake <Core.Shared.UKCompetentAuthorityData>();
            var returnFacilityType       = Core.AatfReturn.FacilityType.Aatf;
            var organisationData         = A.Fake <OrganisationData>();

            A.CallTo(() => statusMap.Map(status)).Returns(returnStatus);
            A.CallTo(() => competentAuthorityMap.Map(competentAuthority)).Returns(returnCompetentAuthority);
            A.CallTo(() => facilityTypeMap.Map(facilityType)).Returns(returnFacilityType);
            A.CallTo(() => organisationMap.Map(organisation)).Returns(organisationData);

            var source = new Aatf(name, competentAuthority, approvalNumber, status, organisation, A.Fake <AatfAddress>(),
                                  A.Fake <Domain.AatfReturn.AatfSize>(), DateTime.Now, A.Fake <AatfContact>(), Domain.AatfReturn.FacilityType.Aatf, complianceYear,
                                  A.Fake <LocalArea>(), A.Fake <PanArea>());

            var result = map.Map(source);

            result.Name.Should().Be(name);
            result.ApprovalNumber.Should().Be(approvalNumber);
            result.AatfStatus.Should().Be(returnStatus);
            result.CompetentAuthority.Should().Be(returnCompetentAuthority);
            result.Organisation.Should().Be(organisationData);
            result.FacilityType.Should().Be(Core.AatfReturn.FacilityType.Aatf);
            result.ComplianceYear.Should().Be(complianceYear);
        }
コード例 #2
0
        public async Task GetAatfsDataAccess_ReturnsLatestAesList()
        {
            using (var database = new DatabaseWrapper())
            {
                var helper                       = new ModelHelper(database.Model);
                var dataAccess                   = new GetAatfsDataAccess(database.WeeeContext);
                var genericDataAccess            = new GenericDataAccess(database.WeeeContext);
                var competentAuthorityDataAccess = new CommonDataAccess(database.WeeeContext);
                var competentAuthority           = await competentAuthorityDataAccess.FetchCompetentAuthority(CompetentAuthority.England);

                var country = await database.WeeeContext.Countries.SingleAsync(c => c.Name == "UK - England");

                var aatfContact  = new AatfContact("first", "last", "position", "address1", "address2", "town", "county", "postcode", country, "telephone", "email");
                var organisation = Organisation.CreatePartnership("Koalas");
                var aatfAddress  = AddressHelper.GetAatfAddress(database);
                var aatfSize     = AatfSize.Large;

                var aatfId = Guid.NewGuid();

                var aatf  = new Aatf("KoalaBears", competentAuthority, "WEE/AB1289YZ/ATF", AatfStatus.Approved, organisation, aatfAddress, aatfSize, DateTime.Now, aatfContact, FacilityType.Ae, 2019, database.WeeeContext.LocalAreas.First(), database.WeeeContext.PanAreas.First(), aatfId);
                var aatf1 = new Aatf("KoalaBears", competentAuthority, "WEE/AB1289YZ/ATF", AatfStatus.Approved, organisation, aatfAddress, aatfSize, Convert.ToDateTime("20/01/2020"), aatfContact, FacilityType.Ae, 2020, database.WeeeContext.LocalAreas.First(), database.WeeeContext.PanAreas.First(), aatfId);

                await genericDataAccess.AddMany <Aatf>(new List <Aatf>() { aatf1, aatf });

                var aatfList = await dataAccess.GetLatestAatfs();

                aatfList.Should().Contain(aatf1);
                aatfList.Should().NotContain(aatf);
            }
        }
コード例 #3
0
ファイル: AatfSiteMapTests.cs プロジェクト: DEFRA/prsd-weee
 public AatfSiteMapTests()
 {
     map       = new AatfSiteMap();
     countryId = Guid.NewGuid();
     country   = new Country(countryId, "UK - England");
     aatf      = A.Fake <Aatf>();
 }
コード例 #4
0
        public async Task GetFilteredAatfsDataAccess_ByName_ReturnsFilteredAatfsList()
        {
            using (var database = new DatabaseWrapper())
            {
                var helper                       = new ModelHelper(database.Model);
                var dataAccess                   = new GetAatfsDataAccess(database.WeeeContext);
                var genericDataAccess            = new GenericDataAccess(database.WeeeContext);
                var competentAuthorityDataAccess = new CommonDataAccess(database.WeeeContext);
                var competentAuthority           = await competentAuthorityDataAccess.FetchCompetentAuthority(CompetentAuthority.England);

                var country = await database.WeeeContext.Countries.SingleAsync(c => c.Name == "UK - England");

                var aatfContact  = new AatfContact("first", "last", "position", "address1", "address2", "town", "county", "postcode", country, "telephone", "email");
                var organisation = Organisation.CreatePartnership("Koalas");
                var aatfAddress  = AddressHelper.GetAatfAddress(database);
                var aatfSize     = AatfSize.Large;

                var aatf = new Aatf("KoalaBears", competentAuthority, "WEE/AB1289YZ/ATF", AatfStatus.Approved, organisation, aatfAddress, aatfSize, DateTime.Now, aatfContact, FacilityType.Aatf, 2019, database.WeeeContext.LocalAreas.First(), database.WeeeContext.PanAreas.First());

                await genericDataAccess.Add <Aatf>(aatf);

                var filteredListWithAatf = await dataAccess.GetFilteredAatfs(new Core.AatfReturn.AatfFilter {
                    Name = "k"
                });

                var filteredListWithoutAatf = await dataAccess.GetFilteredAatfs(new Core.AatfReturn.AatfFilter {
                    Name = "z"
                });

                filteredListWithAatf.Should().Contain(aatf);
                filteredListWithoutAatf.Should().NotContain(aatf);
            }
        }
コード例 #5
0
        public async Task FetchAatfByApprovalNumber_GivenApprovalNumber_ReturnedShouldBeAatf(Core.AatfReturn.FacilityType type)
        {
            FacilityType facilityType;

            if (type == Core.AatfReturn.FacilityType.Aatf)
            {
                facilityType = FacilityType.Aatf;
            }
            else
            {
                facilityType = FacilityType.Ae;
            }

            using (var database = new DatabaseWrapper())
            {
                ModelHelper         helper            = new ModelHelper(database.Model);
                DomainHelper        domainHelper      = new DomainHelper(database.WeeeContext);
                FetchAatfDataAccess dataAccess        = new FetchAatfDataAccess(database.WeeeContext, quarterWindowFactory);
                GenericDataAccess   genericDataAccess = new GenericDataAccess(database.WeeeContext);

                string approvalNumber = "test";

                Aatf aatf = await CreateAatf(database, facilityType, DateTime.Now, 2019, approvalNumber);

                await genericDataAccess.Add(aatf);

                Aatf result = await dataAccess.FetchByApprovalNumber(approvalNumber);

                Assert.NotNull(result);
                Assert.Equal(approvalNumber, result.ApprovalNumber);
                Assert.Equal(facilityType, result.FacilityType);
            }
        }
コード例 #6
0
ファイル: AatfTests.cs プロジェクト: DEFRA/prsd-weee
        public void Aatf_GivenValidParameters_AatfPropertiesShouldBeSet()
        {
            var          competentAuthority = A.Fake <UKCompetentAuthority>();
            var          organisation       = A.Fake <Organisation>();
            const string name           = "name";
            const string approvalNumber = "approvalNumber";
            var          aatfStatus     = AatfStatus.Approved;
            var          contact        = A.Fake <AatfContact>();
            var          complianceYear = (Int16)2019;
            var          localArea      = A.Fake <LocalArea>();
            var          panArea        = A.Fake <PanArea>();
            var          facilityType   = FacilityType.Aatf;
            var          date           = DateTime.Now;
            var          address        = A.Fake <AatfAddress>();
            var          size           = AatfSize.Large;

            var aatf = new Aatf(name, competentAuthority, approvalNumber, aatfStatus, organisation, address, size, date, contact, facilityType, complianceYear, localArea, panArea);

            aatf.CompetentAuthority.Should().Be(competentAuthority);
            aatf.ApprovalNumber.Should().Be(approvalNumber);
            aatf.AatfStatus.Should().Be(aatfStatus);
            aatf.Name.Should().Be(name);
            aatf.Organisation.Should().Be(organisation);
            aatf.Contact.Should().Be(contact);
            aatf.ComplianceYear.Should().Be(complianceYear);
            aatf.ApprovalDate.Should().Be(date);
            aatf.Size.Should().Be(size);
            aatf.FacilityType.Should().Be(facilityType);
            aatf.SiteAddress.Should().Be(address);
            aatf.LocalArea.Should().Be(localArea);
            aatf.PanArea.Should().Be(panArea);
            aatf.AatfId.Should().NotBeEmpty();
        }
コード例 #7
0
        public async Task Execute_GivenAatfWithApprovalDateExpectedToReportAndReturnNotStarted_RecordDataIsAsExpected()
        {
            using (var db = new DatabaseWrapper())
            {
                var organisation = Domain.Organisation.Organisation.CreateSoleTrader(fixture.Create <string>());

                var aatf = new Aatf(fixture.Create <string>(), GetAuthority(db), fixture.Create <string>().Substring(0, 10), AatfStatus.Approved, organisation, ObligatedWeeeIntegrationCommon.CreateAatfAddress(db), AatfSize.Large, Convert.ToDateTime("01/02/2019"), ObligatedWeeeIntegrationCommon.CreateDefaultContact(db.WeeeContext.Countries.First()), FacilityType.Aatf, 2019, db.WeeeContext.LocalAreas.First(), db.WeeeContext.PanAreas.First());

                db.WeeeContext.Aatfs.Add(aatf);

                await db.WeeeContext.SaveChangesAsync();

                var results = await db.StoredProcedures.GetAatfAeReturnDataCsvData(2019, 1,
                                                                                   1, null, null, null, null, false);

                var record = results.First(x => x.AatfId == aatf.Id);
                record.ApprovalNumber.Should().Be(aatf.ApprovalNumber);
                record.CompetentAuthorityAbbr.Should().Be("EA");
                record.Name.Should().Be(aatf.Name);
                record.OrganisationName.Should().Be(organisation.OrganisationName);
                record.CreatedDate.Should().BeNull();
                record.ReturnStatus.Should().Be("Not Started");
                record.SubmittedBy.Should().BeNullOrWhiteSpace();
                record.SubmittedDate.Should().BeNull();
                record.ReSubmission.Should().Be("First submission");
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        public Aatf CreateAatf(DatabaseWrapper database, Organisation organisation, DateTime approvalDate, int count, string cA)
        {
            var aatfContact = ObligatedWeeeIntegrationCommon.CreateDefaultContact(database.WeeeContext.Countries.First());
            var aatfAddress = ObligatedWeeeIntegrationCommon.CreateAatfAddress(database);
            var aatf        = new Aatf("aatfname" + count, database.WeeeContext.UKCompetentAuthorities.First(c => c.Abbreviation == cA), "number", AatfStatus.Approved, organisation, aatfAddress, AatfSize.Large, approvalDate, aatfContact, FacilityType.Aatf, 2019, database.WeeeContext.LocalAreas.First(), database.WeeeContext.PanAreas.First());

            return(aatf);
        }
コード例 #10
0
 private void SetupApprovalDateMovedToNextQuarter(Aatf aatf, DateTime currentApprovalDate, DateTime newApprovalDate)
 {
     A.CallTo(() => aatf.ApprovalDate).Returns(currentApprovalDate);
     A.CallTo(() => quarterWindowFactory.GetAnnualQuarterForDate(currentApprovalDate)).Returns(QuarterType.Q1);
     A.CallTo(() => quarterWindowFactory.GetAnnualQuarterForDate(newApprovalDate)).Returns(QuarterType.Q2);
     A.CallTo(() => quarterWindowFactory.GetAnnualQuarter(A <Quarter> .That.Matches(x =>
                                                                                    x.Q.Equals(QuarterType.Q1) && x.Year.Equals(currentApprovalDate.Year)))).Returns(quarterWindow);
 }
コード例 #11
0
        public async Task Execute_GivenAatfWithApprovalDateExpectedToReportAndResubmissionCreatedAndResubmissionsRequested_RecordDataIsAsExpected()
        {
            using (var db = new DatabaseWrapper())
            {
                var date = new DateTime(2019, 1, 1, 11, 10, 1);
                SystemTime.Freeze(date);

                var organisation = Domain.Organisation.Organisation.CreateSoleTrader(fixture.Create <string>());

                var aatf = new Aatf(fixture.Create <string>(), GetAuthority(db), fixture.Create <string>().Substring(0, 10), AatfStatus.Approved, organisation, ObligatedWeeeIntegrationCommon.CreateAatfAddress(db), AatfSize.Large, Convert.ToDateTime("01/02/2019"), ObligatedWeeeIntegrationCommon.CreateDefaultContact(db.WeeeContext.Countries.First()), FacilityType.Aatf, 2019, db.WeeeContext.LocalAreas.First(), db.WeeeContext.PanAreas.First());

                var @return = ObligatedWeeeIntegrationCommon.CreateReturn(organisation, db.Model.AspNetUsers.First().Id, FacilityType.Aatf, 2019,
                                                                          QuarterType.Q1);

                @return.UpdateSubmitted(db.Model.AspNetUsers.First().Id, false);

                SystemTime.Unfreeze();

                SystemTime.Freeze(date.Date.AddDays(1));
                var @return2 = ObligatedWeeeIntegrationCommon.CreateReturn(organisation, db.Model.AspNetUsers.First().Id, FacilityType.Aatf, 2019,
                                                                           QuarterType.Q1);
                SystemTime.Unfreeze();

                db.WeeeContext.Aatfs.Add(aatf);
                db.WeeeContext.Returns.Add(@return);
                db.WeeeContext.Returns.Add(@return2);
                db.WeeeContext.ReturnAatfs.Add(new ReturnAatf(aatf, @return));

                await db.WeeeContext.SaveChangesAsync();

                var results = await db.StoredProcedures.GetAatfAeReturnDataCsvData(2019, 1,
                                                                                   1, null, null, null, null, true);

                var initialSubmission = results.Where(x => x.AatfId == aatf.Id).ElementAt(0);

                initialSubmission.ApprovalNumber.Should().Be(aatf.ApprovalNumber);
                initialSubmission.CompetentAuthorityAbbr.Should().Be("EA");
                initialSubmission.Name.Should().Be(aatf.Name);
                initialSubmission.OrganisationName.Should().Be(organisation.OrganisationName);
                initialSubmission.CreatedDate.Should().Be(date);
                initialSubmission.ReturnStatus.Should().Be("Submitted");
                initialSubmission.SubmittedBy.Should().Be($"{db.Model.AspNetUsers.First().FirstName} {db.Model.AspNetUsers.First().Surname}");
                initialSubmission.SubmittedDate.Should().Be(date);
                initialSubmission.ReSubmission.Should().Be("First submission");

                var resubmission = results.Where(x => x.AatfId == aatf.Id).ElementAt(1);

                resubmission.ApprovalNumber.Should().Be(aatf.ApprovalNumber);
                resubmission.CompetentAuthorityAbbr.Should().Be("EA");
                resubmission.Name.Should().Be(aatf.Name);
                resubmission.OrganisationName.Should().Be(organisation.OrganisationName);
                resubmission.CreatedDate.Should().Be(date.Date.AddDays(1));
                resubmission.ReturnStatus.Should().Be("Started");
                resubmission.SubmittedBy.Should().BeNullOrWhiteSpace();
                resubmission.SubmittedDate.Should().BeNull();
                resubmission.ReSubmission.Should().Be("Resubmission");
            }
        }
コード例 #12
0
ファイル: AatfTests.cs プロジェクト: DEFRA/prsd-weee
        public void Aatf_GivenNameIsNull_ThrowsArgumentNullException()
        {
            Action constructor = () =>
            {
                var @return = new Aatf(null, A.Dummy <UKCompetentAuthority>(), A.Dummy <string>(), AatfStatus.Approved, A.Fake <Organisation>(), A.Fake <AatfAddress>(), A.Fake <AatfSize>(), DateTime.Now, A.Fake <AatfContact>(), A.Dummy <FacilityType>(), A.Dummy <Int16>(), A.Dummy <LocalArea>(), A.Dummy <PanArea>());
            };

            constructor.Should().Throw <ArgumentNullException>();
        }
コード例 #13
0
ファイル: AatfTests.cs プロジェクト: DEFRA/prsd-weee
        public void Aatf_GivenApprovalNumberIsEmpty_ThrowsArgumentException(string value)
        {
            Action constructor = () =>
            {
                var @return = new Aatf("name", A.Dummy <UKCompetentAuthority>(), value, AatfStatus.Approved, A.Fake <Organisation>(), A.Fake <AatfAddress>(), A.Fake <AatfSize>(), DateTime.Now, A.Fake <AatfContact>(), A.Dummy <FacilityType>(), A.Dummy <Int16>(), A.Dummy <LocalArea>(), A.Dummy <PanArea>());
            };

            constructor.Should().Throw <ArgumentException>();
        }
コード例 #14
0
ファイル: AatfTests.cs プロジェクト: DEFRA/prsd-weee
        public void Aatf_GivenOrganisationIsNull_ThrowsArgumentNullException()
        {
            Action constructor = () =>
            {
                var @return = new Aatf("name", null, "approvalNumber", null, null, A.Fake <AatfAddress>(), A.Fake <AatfSize>(), DateTime.Now, A.Fake <AatfContact>(), A.Dummy <FacilityType>(), A.Dummy <Int16>(), A.Dummy <LocalArea>(), A.Dummy <PanArea>());
            };

            constructor.Should().Throw <ArgumentNullException>();
        }
コード例 #15
0
        public async Task <bool> HasAatfOrganisationOtherAeOrAatf(Aatf aatf)
        {
            var findAatf = await GetAatfById(aatf.Id);

            var organisationId = aatf.Organisation.Id;

            return(await context.Aatfs.CountAsync(p => p.Organisation.Id == organisationId &&
                                                  p.ComplianceYear == findAatf.ComplianceYear &&
                                                  p.FacilityType.Value == findAatf.FacilityType.Value &&
                                                  p.Id != findAatf.Id) > 0);
        }
コード例 #16
0
 private void AssertCreatedRow(DataTable results, Aatf aatf, int row, string category, string obligation)
 {
     results.Rows[row][ComplianceYear].Should().Be(2019);
     results.Rows[row][Quarter].Should().Be("Q1");
     results.Rows[row][Name].Should().Be(aatf.Name);
     results.Rows[row][ApprovalNumber].Should().Be(aatf.ApprovalNumber);
     results.Rows[row][SubmittedBy].Should().Be(" ");
     results.Rows[row][SubmittedDate].ToString().Should().Be(string.Empty);
     results.Rows[row][Obligation].Should().Be(obligation);
     results.Rows[row][Category].Should().Be(category);
     results.Rows[row][TotalReceivedHeading].ToString().Should().BeEmpty();
     results.Rows[row][TotalReusedHeading].ToString().Should().BeEmpty();
     results.Rows[row][TotalSentOnHeading].ToString().Should().BeEmpty();
 }
コード例 #17
0
 private void AssertSubmittedRow(DataTable results, Aatf aatf, DatabaseWrapper db, int row, string category, string obligation)
 {
     results.Rows[row][ComplianceYear].Should().Be(2019);
     results.Rows[row][Quarter].Should().Be("Q1");
     results.Rows[row][Name].Should().Be(aatf.Name);
     results.Rows[row][ApprovalNumber].Should().Be(aatf.ApprovalNumber);
     results.Rows[row][SubmittedBy].Should().Be($"{db.Model.AspNetUsers.First().FirstName} {db.Model.AspNetUsers.First().Surname}");
     results.Rows[row][SubmittedDate].Should().Be(date);
     results.Rows[row][Obligation].Should().Be(obligation);
     results.Rows[row][Category].Should().Be(category);
     results.Rows[row][TotalReceivedHeading].ToString().Should().BeEmpty();
     results.Rows[row][TotalReusedHeading].ToString().Should().BeEmpty();
     results.Rows[row][TotalSentOnHeading].ToString().Should().BeEmpty();
 }
コード例 #18
0
        public async void HandleAsync_GivenAatfAeData_AatfDataShouldBeReturn()
        {
            var      facilityType = Weee.Core.AatfReturn.FacilityType.Aatf;
            DateTime date         = DateTime.Now;
            var      id           = Guid.NewGuid();
            var      aatfData1    = new AatfData(Guid.NewGuid(), "name", "approval number", 2019, A.Dummy <Core.Shared.UKCompetentAuthorityData>(),
                                                 Core.AatfReturn.AatfStatus.Approved, A.Dummy <AatfAddressData>(), Core.AatfReturn.AatfSize.Large, DateTime.Now,
                                                 A.Dummy <Core.Shared.PanAreaData>(), null)
            {
                FacilityType = facilityType
            };

            var aatfData2 = new AatfData(Guid.NewGuid(), "name", "approval number", 2019, A.Dummy <Core.Shared.UKCompetentAuthorityData>(),
                                         Core.AatfReturn.AatfStatus.Approved, A.Dummy <AatfAddressData>(), Core.AatfReturn.AatfSize.Large, DateTime.Now,
                                         A.Dummy <Core.Shared.PanAreaData>(), null)
            {
                FacilityType = facilityType
            };

            var aatfData3 = new AatfData(Guid.NewGuid(), "name", "approval number", 2019, A.Dummy <Core.Shared.UKCompetentAuthorityData>(),
                                         Core.AatfReturn.AatfStatus.Approved, A.Dummy <AatfAddressData>(), Core.AatfReturn.AatfSize.Large, DateTime.Now,
                                         A.Dummy <Core.Shared.PanAreaData>(), null)
            {
                FacilityType = Weee.Core.AatfReturn.FacilityType.Ae
            };

            var aatfDatas = new List <AatfData>()
            {
                aatfData1, aatfData2, aatfData3
            }.ToArray();

            Aatf aatf  = new Aatf("name", A.Dummy <UKCompetentAuthority>(), "1234", Domain.AatfReturn.AatfStatus.Approved, A.Fake <Organisation>(), A.Dummy <AatfAddress>(), Domain.AatfReturn.AatfSize.Large, date, A.Fake <AatfContact>(), Domain.AatfReturn.FacilityType.Aatf, 2019, A.Fake <LocalArea>(), A.Fake <PanArea>());
            Aatf aatf2 = new Aatf("name", A.Dummy <UKCompetentAuthority>(), "1234", Domain.AatfReturn.AatfStatus.Approved, A.Fake <Organisation>(), A.Dummy <AatfAddress>(), Domain.AatfReturn.AatfSize.Large, date, A.Fake <AatfContact>(), Domain.AatfReturn.FacilityType.Aatf, 2019, A.Fake <LocalArea>(), A.Fake <PanArea>());
            Aatf aatf3 = new Aatf("name", A.Dummy <UKCompetentAuthority>(), "1234", Domain.AatfReturn.AatfStatus.Approved, A.Fake <Organisation>(), A.Dummy <AatfAddress>(), Domain.AatfReturn.AatfSize.Large, date, A.Fake <AatfContact>(), Domain.AatfReturn.FacilityType.Ae, 2019, A.Fake <LocalArea>(), A.Fake <PanArea>());

            var aatfs = new List <Aatf>()
            {
                aatf, aatf2
            };

            A.CallTo(() => dataAccess.GetManyByExpression(A <AatfsByOrganisationAndFacilityTypeSpecification> ._)).Returns(aatfs);

            A.CallTo(() => mapper.Map(aatfs.ElementAt(0))).Returns(aatfDatas.ElementAt(0));
            A.CallTo(() => mapper.Map(aatfs.ElementAt(1))).Returns(aatfDatas.ElementAt(1));

            var result = await handler.HandleAsync(new GetAatfByOrganisationFacilityType(id, Core.AatfReturn.FacilityType.Aatf));

            result.Count().Should().Be(2);
        }
コード例 #19
0
        public Task UpdateDetails(Aatf oldDetails, Aatf newDetails)
        {
            oldDetails.UpdateDetails(
                newDetails.Name,
                newDetails.CompetentAuthority,
                newDetails.ApprovalNumber,
                newDetails.AatfStatus,
                newDetails.Organisation,
                newDetails.Size,
                newDetails.ApprovalDate,
                newDetails.LocalArea,
                newDetails.PanArea);

            return(context.SaveChangesAsync());
        }
コード例 #20
0
        public async Task <CanApprovalDateBeChangedFlags> Validate(Aatf aatf, DateTime newApprovalDate)
        {
            var result = new CanApprovalDateBeChangedFlags();

            if (aatf.ApprovalDate.HasValue)
            {
                var currentQuarter = await quarterWindowFactory.GetAnnualQuarterForDate(aatf.ApprovalDate.Value);

                var newQuarter = await quarterWindowFactory.GetAnnualQuarterForDate(newApprovalDate);

                if (aatf.ApprovalDate.Equals(newApprovalDate))
                {
                    return(result);
                }

                if ((int)newQuarter > (int)currentQuarter)
                {
                    result |= CanApprovalDateBeChangedFlags.DateChanged;

                    var returns = await organisationDataAccess.GetReturnsByComplianceYear(aatf.Organisation.Id, aatf.ComplianceYear, aatf.FacilityType);

                    if (returns.Any(r => (int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Created.Value))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasStartedReturn;
                    }

                    if (returns.Any(r => (int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Submitted.Value))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasSubmittedReturn;
                    }

                    if (returns.Any(r => ((int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Submitted.Value && r.ParentId != null) ||
                                    ((int)r.Quarter.Q == (int)currentQuarter && r.ReturnStatus.Value == ReturnStatus.Submitted.Value && r.ParentId != null)))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasResubmission;
                    }

                    if (await aatfDataAccess.HasAatfOrganisationOtherAeOrAatf(aatf))
                    {
                        result |= CanApprovalDateBeChangedFlags.HasMultipleFacility;
                    }
                }
            }

            return(result);
        }
コード例 #21
0
        private static async Task CreateWeeeSentOnAmounts(
            ObligatedSentOnDataAccess dataAccess,
            Return @return,
            Aatf aatf,
            AatfAddress siteAddress,
            AatfAddress operatorAddress)
        {
            var weeeSentOn = new WeeeSentOn(operatorAddress, siteAddress, aatf, @return);

            var weeeSentOnAmount = new List <WeeeSentOnAmount>();

            foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
            {
                weeeSentOnAmount.Add(new WeeeSentOnAmount(weeeSentOn, (int)category, (decimal?)category, (decimal?)category + 1));
            }

            await dataAccess.Submit(weeeSentOnAmount);
        }
コード例 #22
0
        public async void HandleAsync_GivenOrganisationId_OnlyAatfWithMatchingOrganisationShouldBeReturned()
        {
            var organisationId = Guid.NewGuid();
            var matchingOrg    = A.Fake <Organisation>();

            A.CallTo(() => matchingOrg.Id).Returns(organisationId);

            var aatf1 = new Aatf("B", A.Fake <UKCompetentAuthority>(), "TEST", A.Fake <Domain.AatfReturn.AatfStatus>(), matchingOrg,
                                 A.Fake <AatfAddress>(), A.Fake <Domain.AatfReturn.AatfSize>(), DateTime.Now, A.Fake <AatfContact>(),
                                 A.Fake <Domain.AatfReturn.FacilityType>(), A.Dummy <Int16>(), A.Fake <LocalArea>(), A.Fake <PanArea>());
            var aatf2 = new Aatf("A", A.Fake <UKCompetentAuthority>(), "TEST", A.Fake <Domain.AatfReturn.AatfStatus>(), matchingOrg,
                                 A.Fake <AatfAddress>(), A.Fake <Domain.AatfReturn.AatfSize>(), DateTime.Now, A.Fake <AatfContact>(),
                                 A.Fake <Domain.AatfReturn.FacilityType>(), A.Dummy <Int16>(), A.Fake <LocalArea>(), A.Fake <PanArea>());
            var aatf3 = new Aatf("C", A.Fake <UKCompetentAuthority>(), "TEST", A.Fake <Domain.AatfReturn.AatfStatus>(), A.Fake <Organisation>(),
                                 A.Fake <AatfAddress>(), A.Fake <Domain.AatfReturn.AatfSize>(), DateTime.Now, A.Fake <AatfContact>(),
                                 A.Fake <Domain.AatfReturn.FacilityType>(), A.Dummy <Int16>(), A.Fake <LocalArea>(), A.Fake <PanArea>());

            var aatfs = new List <Aatf>()
            {
                aatf1,
                aatf2,
                aatf3
            };

            var aatfDatas = new List <AatfDataList>()
            {
                new AatfDataList(Guid.NewGuid(), "B", A.Fake <UKCompetentAuthorityData>(), "TEST", A.Fake <Core.AatfReturn.AatfStatus>(), A.Fake <OrganisationData>(), Core.AatfReturn.FacilityType.Aatf, (Int16)2019, Guid.NewGuid(), null),
                new AatfDataList(Guid.NewGuid(), "A", A.Fake <UKCompetentAuthorityData>(), "TEST", A.Fake <Core.AatfReturn.AatfStatus>(), A.Fake <OrganisationData>(), Core.AatfReturn.FacilityType.Aatf, (Int16)2019, Guid.NewGuid(), null),
                new AatfDataList(Guid.NewGuid(), "C", A.Fake <UKCompetentAuthorityData>(), "TEST", A.Fake <Core.AatfReturn.AatfStatus>(), A.Fake <OrganisationData>(), Core.AatfReturn.FacilityType.Aatf, (Int16)2019, Guid.NewGuid(), null)
            }.ToArray();

            A.CallTo(() => dataAccess.GetAatfs()).Returns(aatfs);
            A.CallTo(() => aatfmap.Map(aatfs.ElementAt(0))).Returns(aatfDatas.ElementAt(0));
            A.CallTo(() => aatfmap.Map(aatfs.ElementAt(1))).Returns(aatfDatas.ElementAt(1));
            A.CallTo(() => aatfmap.Map(aatfs.ElementAt(2))).Returns(aatfDatas.ElementAt(2));

            var result = await handler.HandleAsync(new GetAatfsByOrganisationId(organisationId));

            result.Should().Contain(aatfDatas.ElementAt(0));
            result.Should().Contain(aatfDatas.ElementAt(1));
            result.Should().NotContain(aatfDatas.ElementAt(2));
            result.Count().Should().Be(2);
        }
コード例 #23
0
        public async Task FetchAatfByApprovalNumber_GivenApprovalNumberThatExistForCY_ReturnedShouldNotBeNull()
        {
            using (var database = new DatabaseWrapper())
            {
                ModelHelper         helper            = new ModelHelper(database.Model);
                DomainHelper        domainHelper      = new DomainHelper(database.WeeeContext);
                FetchAatfDataAccess dataAccess        = new FetchAatfDataAccess(database.WeeeContext, quarterWindowFactory);
                GenericDataAccess   genericDataAccess = new GenericDataAccess(database.WeeeContext);

                string approvalNumber = "test";

                Aatf aatf = await CreateAatf(database, FacilityType.Aatf, DateTime.Now, 2019, approvalNumber);

                await genericDataAccess.Add(aatf);

                Aatf result = await dataAccess.FetchByApprovalNumber(approvalNumber, 2019);

                Assert.NotNull(result);
            }
        }
コード例 #24
0
ファイル: AatfTests.cs プロジェクト: DEFRA/prsd-weee
        public void Aatf_GivenNullPanArea_PanAreaIsNull()
        {
            var          competentAuthority = A.Fake <UKCompetentAuthority>();
            var          organisation       = A.Fake <Organisation>();
            const string name           = "name";
            const string approvalNumber = "approvalNumber";
            var          aatfStatus     = AatfStatus.Approved;
            var          contact        = A.Fake <AatfContact>();
            var          complianceYear = (Int16)2019;
            var          localArea      = A.Fake <LocalArea>();
            PanArea      panArea        = null;
            var          facilityType   = FacilityType.Aatf;
            var          date           = DateTime.Now;
            var          address        = A.Fake <AatfAddress>();
            var          size           = AatfSize.Large;

            var aatf = new Aatf(name, competentAuthority, approvalNumber, aatfStatus, organisation, address, size, date, contact, facilityType, complianceYear, localArea, panArea);

            aatf.PanArea.Should().Be(panArea);
        }
コード例 #25
0
        private static async Task CreateWeeeReusedAmounts(
            ObligatedReusedDataAccess obligatedReusedDataAccess,
            AatfSiteDataAccess aatfSiteDataAccess,
            Return @return,
            Aatf aatf,
            AatfAddress address)
        {
            var weeeReused = new WeeeReused(aatf.Id, @return.Id);

            var weeeReusedAmount = new List <WeeeReusedAmount>();

            foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
            {
                weeeReusedAmount.Add(new WeeeReusedAmount(weeeReused, (int)category, (int)category, (int)category + 1));
            }

            var weeeReusedSite = new WeeeReusedSite(weeeReused, address);

            await obligatedReusedDataAccess.Submit(weeeReusedAmount);

            await aatfSiteDataAccess.Submit(weeeReusedSite);
        }
コード例 #26
0
        public async Task GetAatfObligatedDataCsvHandler_ReturnsFileName()
        {
            var authorization    = new AuthorizationBuilder().AllowInternalAreaAccess().Build();
            var context          = A.Fake <WeeeContext>();
            var aatfDataAccess   = A.Fake <IGetAatfsDataAccess>();
            var csvWriterFactory = A.Fake <CsvWriterFactory>();
            int complianceYear   = 2019;

            SystemTime.Freeze(new DateTime(2019, 2, 1, 11, 1, 2));
            Aatf aatf = new Aatf("Company Aatf", A.Dummy <UKCompetentAuthority>(), "1234", Domain.AatfReturn.AatfStatus.Approved, A.Fake <Organisation>(), A.Dummy <AatfAddress>(), Domain.AatfReturn.AatfSize.Large, DateTime.Now, A.Fake <AatfContact>(), Domain.AatfReturn.FacilityType.Aatf, 2019, A.Fake <LocalArea>(), A.Fake <PanArea>());

            var handler = new GetAatfObligatedDataHandler(authorization, context, csvWriterFactory, aatfDataAccess);
            var request = new GetAatfObligatedData(complianceYear, 1, A.Dummy <Guid>(), A.Dummy <Guid>());

            A.CallTo(() => aatfDataAccess.GetAatfById(request.AatfId)).Returns(aatf);

            // Act
            CSVFileData data = await handler.HandleAsync(request);

            // Assert
            data.FileName.Should().Be("2019_Q1_1234_Full data_01022019_1101.csv");
        }
コード例 #27
0
        public async Task GetManyByExpression_Specification_AatfsByAatfFacilityTypeShouldBeReturned()
        {
            using (var database = new DatabaseWrapper())
            {
                var dataAccess = new GenericDataAccess(database.WeeeContext);

                var organisation = Organisation.CreateSoleTrader("Test Organisation");
                var aatf1        = ObligatedWeeeIntegrationCommon.CreateAatf(database, organisation);
                var aatf2        = ObligatedWeeeIntegrationCommon.CreateAatf(database, organisation);
                var aatf3        = new Aatf("aatfname", database.WeeeContext.UKCompetentAuthorities.First(), "number", AatfStatus.Approved, organisation, ObligatedWeeeIntegrationCommon.CreateAatfAddress(database), AatfSize.Large, DateTime.Now, ObligatedWeeeIntegrationCommon.CreateDefaultContact(database.WeeeContext.Countries.First()), FacilityType.Ae, 2019, database.WeeeContext.LocalAreas.First(), database.WeeeContext.PanAreas.First());

                database.WeeeContext.Aatfs.Add(aatf1);
                database.WeeeContext.Aatfs.Add(aatf2);
                database.WeeeContext.Aatfs.Add(aatf3);
                await database.WeeeContext.SaveChangesAsync();

                var aatfInfo = await dataAccess.GetManyByExpression(new AatfsByOrganisationAndFacilityTypeSpecification(organisation.Id, Core.AatfReturn.FacilityType.Aatf));

                aatfInfo.Count.Should().Be(2);
                aatfInfo.Where(a => Equals(aatf1)).Should().NotBeNull();
                aatfInfo.Where(a => Equals(aatf2)).Should().NotBeNull();
                aatfInfo.Where(a => Equals(aatf3)).Should().BeEmpty();
            }
        }
コード例 #28
0
        private static async Task CreateWeeeReceivedAmounts(
            ObligatedReceivedDataAccess dataAccess,
            ReturnSchemeDataAccess returnSchemeDataAccess,
            Return @return,
            Aatf aatf,
            Scheme scheme)
        {
            var returnScheme = new ReturnScheme(scheme, @return);

            var weeeReceived = new WeeeReceived(scheme, aatf, @return);

            var weeeReceivedAmount = new List <WeeeReceivedAmount>();

            foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
            {
                weeeReceivedAmount.Add(new WeeeReceivedAmount(weeeReceived, (int)category, (int)category, (int)category + 1));
            }

            await returnSchemeDataAccess.Submit(new List <ReturnScheme> {
                returnScheme
            });

            await dataAccess.Submit(weeeReceivedAmount);
        }
コード例 #29
0
        public async Task Execute_GivenAaatfWithApprovalDateExpectedToReportWithFacilityParameter_CorrectRecordsShouldBeReturned()
        {
            using (var db = new DatabaseWrapper())
            {
                var organisation1 = Domain.Organisation.Organisation.CreateSoleTrader("Test Organisation");

                var aatf1 = new Aatf("aatfname1", GetAuthority(db), "number", AatfStatus.Approved, organisation1, ObligatedWeeeIntegrationCommon.CreateAatfAddress(db), AatfSize.Large, Convert.ToDateTime("01/02/2019"), ObligatedWeeeIntegrationCommon.CreateDefaultContact(db.WeeeContext.Countries.First()), FacilityType.Aatf, 2019, db.WeeeContext.LocalAreas.First(), GetPanArea(db, "North"));
                var aatf2 = new Aatf("aatfname2", GetAuthority(db), "number", AatfStatus.Approved, organisation1, ObligatedWeeeIntegrationCommon.CreateAatfAddress(db), AatfSize.Large, Convert.ToDateTime("01/02/2019"), ObligatedWeeeIntegrationCommon.CreateDefaultContact(db.WeeeContext.Countries.First()), FacilityType.Aatf, 2019, db.WeeeContext.LocalAreas.First(), GetPanArea(db, "North"));
                var ae    = new Aatf("aatfname3", GetAuthority(db), "number", AatfStatus.Approved, organisation1, ObligatedWeeeIntegrationCommon.CreateAatfAddress(db), AatfSize.Large, Convert.ToDateTime("01/02/2019"), ObligatedWeeeIntegrationCommon.CreateDefaultContact(db.WeeeContext.Countries.First()), FacilityType.Ae, 2019, db.WeeeContext.LocalAreas.First(), GetPanArea(db, "North"));

                db.WeeeContext.Aatfs.Add(aatf1);
                db.WeeeContext.Aatfs.Add(aatf2);
                db.WeeeContext.Aatfs.Add(ae);

                await db.WeeeContext.SaveChangesAsync();

                var results = await db.StoredProcedures.GetAatfAeReturnDataCsvData(2019, 1,
                                                                                   1, null, null, null, null, false);

                results.Count(x => x.AatfId == aatf1.Id).Should().Be(1);
                results.Count(x => x.AatfId == aatf2.Id).Should().Be(1);
                results.Count(x => x.AatfId == ae.Id).Should().Be(0);
            }
        }
コード例 #30
0
ファイル: AatfSiteMapTests.cs プロジェクト: DEFRA/prsd-weee
        public WeeeReused ReturnWeeeReused(Aatf aatf, Return @return)
        {
            var weeeReused = new WeeeReused(aatf, @return);

            return(weeeReused);
        }