Exemplo n.º 1
0
        public async void UpdateAddress_GivenAddressToUpdate_ContextShouldContainUpdatedAddress()
        {
            using (var database = new DatabaseWrapper())
            {
                var context = database.WeeeContext;

                var country = await context.Countries.SingleAsync(c => c.Name == "France");

                var aatfAddress = AddressHelper.GetAatfAddress(database);

                var dataAccess = new AatfSiteDataAccess(context, A.Fake <IGenericDataAccess>());

                var returnData = await CreateWeeeReusedSite(dataAccess, aatfAddress, database);

                var oldAddress = (context.WeeeReusedSite
                                  .Where(t => t.WeeeReused.ReturnId == returnData.Item1 &&
                                         t.WeeeReused.Aatf.Id == returnData.Item2).FirstOrDefault()).Address;
                var newAddress = new SiteAddressData("Site1", "Address11", "Address21", "Town1", "County1", "PO12ST341", country.Id, country.Name);
                var newCountry = await context.Countries.SingleAsync(c => c.Name == "Germany");

                await dataAccess.Update(oldAddress, newAddress, newCountry);

                AssertUpdated(context, returnData, newAddress, newCountry);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public async Task GetAatfsDataAccess_ReturnsAatfsList()
        {
            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 = ObligatedWeeeIntegrationCommon.CreateAatf(database, organisation);

                await genericDataAccess.Add <Aatf>(aatf);

                var aatfList = await dataAccess.GetAatfs();

                aatfList.Should().Contain(aatf);
            }
        }
Exemplo n.º 5
0
        private async Task <Aatf> CreateAatf(DatabaseWrapper database, FacilityType facilityType, DateTime date, short year, string approvalNumber = null, string name = null)
        {
            var country = database.WeeeContext.Countries.First();
            var competentAuthorityDataAccess = new CommonDataAccess(database.WeeeContext);
            var competentAuthority           = await competentAuthorityDataAccess.FetchCompetentAuthority(CompetentAuthority.England);

            var organisation = Organisation.CreatePartnership("Dummy");
            var contact      = new AatfContact("First Name", "Last Name", "Manager", "1 Address Lane", "Address Ward", "Town", "County", "Postcode", country, "01234 567890", "*****@*****.**");

            if (approvalNumber == null)
            {
                approvalNumber = "12345678";
            }

            if (name == null)
            {
                name = "name";
            }

            return(new Aatf(name,
                            competentAuthority,
                            approvalNumber,
                            AatfStatus.Approved,
                            organisation,
                            AddressHelper.GetAatfAddress(database),
                            A.Fake <AatfSize>(),
                            date,
                            contact,
                            facilityType,
                            year,
                            database.WeeeContext.LocalAreas.First(),
                            database.WeeeContext.PanAreas.First()));
        }
Exemplo n.º 6
0
        private async Task AddWeeSentOn(DateTime?approvalDate = null)
        {
            var aatf = ObligatedWeeeIntegrationCommon.CreateAatf(database, organisation);

            aatf.UpdateDetails(aatf.Name, aatf.CompetentAuthority, aatf.ApprovalNumber, aatf.AatfStatus, aatf.Organisation, aatf.Size, approvalDate, aatf.LocalArea, aatf.PanArea);

            var weeeSentOn = new List <WeeeSentOn>()
            {
                new WeeeSentOn(AddressHelper.GetAatfAddress(database), AddressHelper.GetAatfAddress(database), aatf, @return),
                new WeeeSentOn(AddressHelper.GetAatfAddress(database), AddressHelper.GetAatfAddress(database), aatf, @return)
            };

            var weeSentOnAmounts = new List <WeeeSentOnAmount>()
            {
                new WeeeSentOnAmount(weeeSentOn.ElementAt(0), 1, 10, 20),
                new WeeeSentOnAmount(weeeSentOn.ElementAt(0), 2, 30, 40),
                new WeeeSentOnAmount(weeeSentOn.ElementAt(1), 3, 0, null),
                new WeeeSentOnAmount(weeeSentOn.ElementAt(1), 4, null, 0)
            };

            database.WeeeContext.WeeeSentOnAmount.AddRange(weeSentOnAmounts);
            database.WeeeContext.WeeeSentOn.AddRange(weeeSentOn);

            await database.WeeeContext.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task CanCreateAatfAddressEntry()
        {
            using (var database = new DatabaseWrapper())
            {
                var context = database.WeeeContext;

                var aatfAddress = AddressHelper.GetAatfAddress(database);

                var dataAccess = new AatfSiteDataAccess(context, A.Fake <IGenericDataAccess>());

                var returnData = await CreateWeeeReusedSite(dataAccess, aatfAddress, database);

                AssertSubmitted(context, aatfAddress.Country, returnData, aatfAddress);
            }
        }
Exemplo n.º 8
0
        public async void RemoveWeeeSentOn_GivenWeeeSentOn_CorrectDatabaseEntriesAreDeleted()
        {
            using (var database = new DatabaseWrapper())
            {
                var context              = database.WeeeContext;
                var dataAccess           = new GenericDataAccess(database.WeeeContext);
                var weeeSentOnDataAccess = new WeeeSentOnDataAccess(database.WeeeContext);

                var countryOperator = await context.Countries.SingleAsync(c => c.Name == "France");

                var operatorAddress = AddressHelper.GetAatfAddress(database);
                var countrySite     = await context.Countries.SingleAsync(c => c.Name == "France");

                var siteAddress = AddressHelper.GetAatfAddress(database);

                var weeeSentOn = await CreateWeeeSentOnOperatorInContext(weeeSentOnDataAccess, operatorAddress, siteAddress, database);

                var weeeSentOnAmountList = await AppendWeeeSentOnAmountToWeeeSentOn(context, weeeSentOn);

                context.AatfAddress.Should().Contain(weeeSentOn.SiteAddress);
                context.AatfAddress.Should().Contain(weeeSentOn.OperatorAddress);
                foreach (var amount in weeeSentOnAmountList)
                {
                    context.WeeeSentOnAmount.Should().Contain(amount);
                }
                context.WeeeSentOn.Should().Contain(weeeSentOn);

                dataAccess.Remove(weeeSentOn.SiteAddress);
                dataAccess.Remove(weeeSentOn.OperatorAddress);
                dataAccess.RemoveMany(weeeSentOnAmountList);
                dataAccess.Remove(weeeSentOn);

                await context.SaveChangesAsync();

                context.AatfAddress.Should().NotContain(weeeSentOn.SiteAddress);
                context.AatfAddress.Should().NotContain(weeeSentOn.OperatorAddress);
                foreach (var amount in weeeSentOnAmountList)
                {
                    context.WeeeSentOnAmount.Should().NotContain(amount);
                }
                context.WeeeSentOn.Should().NotContain(weeeSentOn);
            }
        }
Exemplo n.º 9
0
        private async Task <List <Aatf> > CreateMultipleAatf(DatabaseWrapper database, FacilityType facilityType, DateTime date, short year)
        {
            var country = database.WeeeContext.Countries.First();
            var competentAuthorityDataAccess = new CommonDataAccess(database.WeeeContext);
            var competentAuthority           = await competentAuthorityDataAccess.FetchCompetentAuthority(CompetentAuthority.England);

            var organisation = Organisation.CreatePartnership("Dummy");
            var contact      = new AatfContact("First Name", "Last Name", "Manager", "1 Address Lane", "Address Ward", "Town", "County", "Postcode", country, "01234 567890", "*****@*****.**");
            var aatfList     = new List <Aatf>();

            aatfList.Add(new Aatf("B",
                                  competentAuthority,
                                  "12345678",
                                  AatfStatus.Approved,
                                  organisation,
                                  AddressHelper.GetAatfAddress(database),
                                  A.Fake <AatfSize>(),
                                  date,
                                  contact,
                                  facilityType,
                                  year,
                                  database.WeeeContext.LocalAreas.First(),
                                  database.WeeeContext.PanAreas.First()));

            aatfList.Add(new Aatf("A",
                                  competentAuthority,
                                  "12345679",
                                  AatfStatus.Approved,
                                  organisation,
                                  AddressHelper.GetAatfAddress(database),
                                  A.Fake <AatfSize>(),
                                  date,
                                  contact,
                                  facilityType,
                                  year,
                                  database.WeeeContext.LocalAreas.First(),
                                  database.WeeeContext.PanAreas.First()));

            return(aatfList);
        }
Exemplo n.º 10
0
        public async void UpdateWithOperatorAddress_GivenOperatorAddress_ContextShouldContainUpdatedWeeeSentOnWithOperatorAddress()
        {
            using (var database = new DatabaseWrapper())
            {
                var context    = database.WeeeContext;
                var dataAccess = new WeeeSentOnDataAccess(database.WeeeContext);

                var country = await context.Countries.SingleAsync(c => c.Name == "France");

                var operatorCountry = await context.Countries.SingleAsync(c => c.Name == "Germany");

                var siteAddress = AddressHelper.GetAatfAddress(database);

                var operatorAddress = AddressHelper.GetAatfAddress(database);

                var weeeSentOn = await CreateWeeeSentOnInContext(dataAccess, siteAddress, database);

                await dataAccess.UpdateWithOperatorAddress(weeeSentOn, operatorAddress);

                weeeSentOn.OperatorAddress.Should().BeSameAs(operatorAddress);
            }
        }
        public async Task Execute_GivenNoPCSReceivedData_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.B2C, authority);
                scheme1.SetStatus(Domain.Scheme.SchemeStatus.Approved);

                var @return = CreateSubmittedReturn(db, organisation);
                var aatf    = new Aatf("aatfName", authority, "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, null);

                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("WEE/AH7453NF/SCH", record.PcsApprovalNumber);
                Assert.Equal(0, record.PcsTonnage);
                Assert.Equal(10, record.AatfTonnage);
                Assert.Equal(-10, record.DifferenceTonnage);
            }
        }