public async Task CanCreateNonObligatedWeeeEntry(bool dcf)
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                var context = database.WeeeContext;

                var          name        = "Test Name" + Guid.NewGuid();
                var          tradingName = "Test Trading Name" + Guid.NewGuid();
                const string crn         = "ABC12345";

                var organisation = Organisation.CreateRegisteredCompany(name, crn, tradingName);
                context.Organisations.Add(organisation);

                await context.SaveChangesAsync();

                var quarter    = new Quarter(2019, QuarterType.Q1);
                var aatfReturn = new Return(organisation, quarter, database.Model.AspNetUsers.First().Id, FacilityType.Aatf);

                var categoryValues = new List <NonObligatedValue>();

                foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
                {
                    categoryValues.Add(new NonObligatedValue((int)category, (int)category, dcf, Guid.NewGuid()));
                }

                var nonObligatedRequest = new AddNonObligated
                {
                    ReturnId       = aatfReturn.Id,
                    OrganisationId = organisation.Id,
                    CategoryValues = categoryValues
                };

                var nonObligatedWee = new List <NonObligatedWeee>();

                foreach (var categoryValue in nonObligatedRequest.CategoryValues)
                {
                    nonObligatedWee.Add(new NonObligatedWeee(aatfReturn, categoryValue.CategoryId, categoryValue.Dcf, categoryValue.Tonnage));
                }

                var dataAccess = new NonObligatedDataAccess(database.WeeeContext);

                await dataAccess.Submit(nonObligatedWee);

                var thisTestNonObligatedWeeeArray =
                    context.NonObligatedWeee.Where(o => o.ReturnId == aatfReturn.Id).ToArray();

                Assert.NotNull(thisTestNonObligatedWeeeArray);
                Assert.NotEmpty(thisTestNonObligatedWeeeArray);

                foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
                {
                    var foundCategory = thisTestNonObligatedWeeeArray.FirstOrDefault(o => o.CategoryId == (int)category);
                    foundCategory.Should().NotBeNull();
                    var indexNum = (int)category - 1;
                    Assert.Equal(foundCategory.Dcf, nonObligatedWee[indexNum].Dcf);
                    Assert.Equal(foundCategory.Tonnage, nonObligatedWee[indexNum].Tonnage);
                    Assert.Equal(foundCategory.ReturnId, nonObligatedWee[indexNum].ReturnId);
                }
            }
        }
        public async Task FetchObligatedWeeeForReturn_ReturnedListShouldContainAllTonnagesFromRequest()
        {
            using (var database = new DatabaseWrapper())
            {
                var          companyName = "Test Name" + Guid.NewGuid();
                var          tradingName = "Test Trading Name" + Guid.NewGuid();
                const string companyRegistrationNumber = "ABC12345";

                var organisation = Organisation.CreateRegisteredCompany(companyName, companyRegistrationNumber, tradingName);
                var @return      = new Return(organisation, new Quarter(2019, QuarterType.Q1), database.Model.AspNetUsers.First().Id, FacilityType.Aatf);
                var aatf         = ObligatedWeeeIntegrationCommon.CreateAatf(database, organisation);

                database.WeeeContext.Organisations.Add(organisation);
                database.WeeeContext.Aatfs.Add(aatf);
                database.WeeeContext.Returns.Add(@return);
                await database.WeeeContext.SaveChangesAsync();

                var addObligatedReusedDataAccess = new ObligatedReusedDataAccess(database.WeeeContext);

                var categoryValues = new List <ObligatedValue>();
                var weeeReused     = new WeeeReused(aatf.Id, @return.Id);

                foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
                {
                    categoryValues.Add(new ObligatedValue(Guid.NewGuid(), (int)category, (int)category, (int)category));
                }

                var obligatedReusedRequest = new AddObligatedReused()
                {
                    AatfId         = aatf.Id,
                    ReturnId       = @return.Id,
                    OrganisationId = organisation.Id,
                    CategoryValues = categoryValues
                };

                var weeeReusedAmount = new List <WeeeReusedAmount>();

                foreach (var categoryValue in obligatedReusedRequest.CategoryValues)
                {
                    weeeReusedAmount.Add(new WeeeReusedAmount(weeeReused, categoryValue.CategoryId, categoryValue.HouseholdTonnage, categoryValue.NonHouseholdTonnage));
                }

                var obligateReusedDataAccess = new ObligatedReusedDataAccess(database.WeeeContext);
                await obligateReusedDataAccess.Submit(weeeReusedAmount);

                var fetchDataAccess = new FetchObligatedWeeeForReturnDataAccess(database.WeeeContext);

                var reusedTonnageList = await fetchDataAccess.FetchObligatedWeeeReusedForReturn(@return.Id);

                var reusedNonHouseholdList = reusedTonnageList.Select(t => t.NonHouseholdTonnage);
                var reusedHouseholdList    = reusedTonnageList.Select(t => t.HouseholdTonnage);

                foreach (var category in weeeReusedAmount)
                {
                    reusedNonHouseholdList.Should().Contain(category.NonHouseholdTonnage);
                    reusedHouseholdList.Should().Contain(category.HouseholdTonnage);
                }
            }
        }
        public async void UpdateAmounts_GivenAmountToUpdate_ContextShouldContainUpdatedAmounts()
        {
            using (var database = new DatabaseWrapper())
            {
                var context    = database.WeeeContext;
                var dataAccess = new NonObligatedDataAccess(database.WeeeContext);

                var          companyName = "Test Name" + Guid.NewGuid();
                var          tradingName = "Test Trading Name" + Guid.NewGuid();
                const string companyRegistrationNumber = "ABC12345";

                var organisation = Organisation.CreateRegisteredCompany(companyName, companyRegistrationNumber, tradingName);
                var @return      = new Return(organisation, new Quarter(2019, QuarterType.Q1), database.Model.AspNetUsers.First().Id, FacilityType.Aatf);

                context.Organisations.Add(organisation);
                context.Returns.Add(@return);

                await context.SaveChangesAsync();

                var nonObligatedWee = new List <NonObligatedWeee>();

                foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
                {
                    nonObligatedWee.Add(new NonObligatedWeee(@return, (int)category, false, (int)category));
                }

                await dataAccess.Submit(nonObligatedWee);

                AssertValues(context, @return.Id);

                for (var i = 1; i <= Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>().Count(); i++)
                {
                    var amount = context.NonObligatedWeee.First(c => c.ReturnId == @return.Id && c.CategoryId == i);
                    await dataAccess.UpdateAmount(amount, i + 1);
                }

                for (var i = 1; i <= Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>().Count(); i++)
                {
                    var amount = context.NonObligatedWeee.First(c => c.ReturnId == @return.Id && c.CategoryId == i);
                    amount.Tonnage.Should().Be(i + 1);
                }
            }
        }
Exemplo n.º 4
0
        public async Task FetchAatfByReturnId_GivenMatchingParameters_AatfsShouldBeOrderedByName()
        {
            using (var database = new DatabaseWrapper())
            {
                var helper            = new ModelHelper(database.Model);
                var domainHelper      = new DomainHelper(database.WeeeContext);
                var dataAccess        = new FetchAatfDataAccess(database.WeeeContext, quarterWindowFactory);
                var genericDataAccess = new GenericDataAccess(database.WeeeContext);

                var aatfList = await CreateMultipleAatf(database, FacilityType.Aatf, DateTime.Now, 2019);

                var @return = new Return(aatfList[0].Organisation, new Quarter(2019, QuarterType.Q1), "created", FacilityType.Aatf);

                A.CallTo(() => quarterWindowFactory.GetQuarterWindow(@return.Quarter)).Returns(new QuarterWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(1), QuarterType.Q1));

                await genericDataAccess.AddMany <Aatf>(aatfList);

                var returnedAatfList = await dataAccess.FetchAatfByReturnId(@return.Id);

                aatfList.Should().BeInDescendingOrder(m => m.Name);
            }
        }
Exemplo n.º 5
0
        public async Task FetchAatfByReturnQuarterWindow_GivenMatchingParameters_ReturnedListContainsAatf()
        {
            using (var database = new DatabaseWrapper())
            {
                var helper            = new ModelHelper(database.Model);
                var domainHelper      = new DomainHelper(database.WeeeContext);
                var dataAccess        = new FetchAatfDataAccess(database.WeeeContext, quarterWindowFactory);
                var genericDataAccess = new GenericDataAccess(database.WeeeContext);

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

                var @return = new Return(aatf.Organisation, new Quarter(2019, QuarterType.Q1), "created", FacilityType.Aatf);

                A.CallTo(() => quarterWindowFactory.GetQuarterWindow(@return.Quarter)).Returns(new QuarterWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(1), QuarterType.Q1));

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

                var aatfList = await dataAccess.FetchAatfByReturnQuarterWindow(@return);

                aatfList.Should().Contain(aatf);
            }
        }
Exemplo n.º 6
0
        public async Task CanCreateReturnScheme()
        {
            using (var database = new DatabaseWrapper())
            {
                var context = database.WeeeContext;

                var          name        = "Test Name" + Guid.NewGuid();
                var          tradingName = "Test Trading Name" + Guid.NewGuid();
                const string crn         = "ABC12345";

                var organisation = Organisation.Organisation.CreateRegisteredCompany(name, crn, tradingName);

                context.Organisations.Add(organisation);
                await context.SaveChangesAsync();

                var scheme = new Scheme(organisation.Id);
                context.Schemes.Add(scheme);

                var quarter = new Quarter(2019, QuarterType.Q1);
                var @return = new Return(organisation, quarter, database.Model.AspNetUsers.First().Id, FacilityType.Aatf);

                context.Returns.Add(@return);
                await context.SaveChangesAsync();

                var dataAccess = new ReturnSchemeDataAccess(database.WeeeContext);

                var returnScheme = new ReturnScheme(scheme, @return);

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

                var returnSchemeReturned = context.ReturnScheme.First(o => o.Id == returnScheme.Id);
                returnSchemeReturned.Should().NotBeNull();
                returnSchemeReturned.ReturnId.Should().Be(@return.Id);
                returnSchemeReturned.SchemeId.Should().Be(scheme.Id);
            }
        }
        private static async Task CreateWeeReusedData(DatabaseWrapper db, EA.Weee.Domain.AatfReturn.Aatf aatf, Return @return)
        {
            var weeeReused = new EA.Weee.Domain.AatfReturn.WeeeReused(aatf, @return);

            var weeeReusedSites = new List <WeeeReusedSite>()
            {
                new Domain.AatfReturn.WeeeReusedSite(weeeReused, new AatfAddress("name1", "address", "address2", "town", "county", "postcode", db.WeeeContext.Countries.First())),
                new Domain.AatfReturn.WeeeReusedSite(weeeReused, new AatfAddress("name2", "address", "address2", "town", "county", "postcode", db.WeeeContext.Countries.First()))
            };

            db.WeeeContext.Returns.Add(@return);
            db.WeeeContext.ReturnAatfs.Add(new ReturnAatf(aatf, @return));
            db.WeeeContext.WeeeReused.Add(weeeReused);
            db.WeeeContext.WeeeReusedSite.AddRange(weeeReusedSites);

            await db.WeeeContext.SaveChangesAsync();

            db.WeeeContext.ReturnReportOns.Add(new ReturnReportOn(@return.Id, 3));

            await db.WeeeContext.SaveChangesAsync();
        }
Exemplo n.º 8
0
        public async Task FetchObligatedWeeeForReturn_ReturnedListShouldContainAllTonnagesFromRequest()
        {
            using (var database = new DatabaseWrapper())
            {
                var          companyName = "Test Name" + Guid.NewGuid();
                var          tradingName = "Test Trading Name" + Guid.NewGuid();
                const string companyRegistrationNumber = "ABC12345";

                var organisation       = Organisation.CreateRegisteredCompany(companyName, companyRegistrationNumber, tradingName);
                var scheme             = new Scheme(organisation);
                var competentAuthority = database.WeeeContext.UKCompetentAuthorities.FirstOrDefault();
                var country            = await database.WeeeContext.Countries.SingleAsync(c => c.Name == "France");

                var contact = new AatfContact("First Name", "Last Name", "Manager", "1 Address Lane", "Address Ward", "Town", "County", "Postcode", country, "01234 567890", "*****@*****.**");
                var aatf    = ObligatedWeeeIntegrationCommon.CreateAatf(database, organisation);
                var @return = new Return(organisation, new Quarter(2019, QuarterType.Q1), database.Model.AspNetUsers.First().Id, FacilityType.Aatf);

                database.WeeeContext.Organisations.Add(organisation);
                database.WeeeContext.Schemes.Add(scheme);
                database.WeeeContext.Aatfs.Add(aatf);
                database.WeeeContext.Returns.Add(@return);
                await database.WeeeContext.SaveChangesAsync();

                var addObligatedReceivedDataAccess = new ObligatedReceivedDataAccess(database.WeeeContext);

                var categoryValues = new List <ObligatedValue>();
                var weeeReceived   = new WeeeReceived(scheme.Id, aatf.Id, @return.Id);

                foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>())
                {
                    categoryValues.Add(new ObligatedValue(Guid.NewGuid(), (int)category, (int)category, (int)category));
                }

                var obligatedReceivedRequest = new AddObligatedReceived()
                {
                    ReturnId       = @return.Id,
                    AatfId         = aatf.Id,
                    SchemeId       = scheme.Id,
                    OrganisationId = organisation.Id,
                    CategoryValues = categoryValues
                };

                var obligatedReusedRequest = new AddObligatedReused()
                {
                    AatfId         = aatf.Id,
                    ReturnId       = @return.Id,
                    OrganisationId = organisation.Id,
                    CategoryValues = categoryValues
                };

                var weeeReceivedAmount = new List <WeeeReceivedAmount>();
                var weeeReusedAmount   = new List <WeeeReusedAmount>();

                foreach (var categoryValue in obligatedReceivedRequest.CategoryValues)
                {
                    weeeReceivedAmount.Add(new WeeeReceivedAmount(weeeReceived, categoryValue.CategoryId, categoryValue.HouseholdTonnage, categoryValue.NonHouseholdTonnage));
                }

                var obligateReceivedDataAccess = new ObligatedReceivedDataAccess(database.WeeeContext);
                await obligateReceivedDataAccess.Submit(weeeReceivedAmount);

                var fetchDataAccess = new FetchObligatedWeeeForReturnDataAccess(database.WeeeContext);

                var receivedTonnageList = await fetchDataAccess.FetchObligatedWeeeReceivedForReturn(@return.Id);

                var receivedNonHouseholdList = receivedTonnageList.Select(t => t.NonHouseholdTonnage);
                var receivedHouseholdList    = receivedTonnageList.Select(t => t.HouseholdTonnage);

                foreach (var category in weeeReceivedAmount)
                {
                    receivedNonHouseholdList.Should().Contain(category.NonHouseholdTonnage);
                    receivedHouseholdList.Should().Contain(category.HouseholdTonnage);
                }
            }
        }
        private static async Task CreateWeeSentOnData(DatabaseWrapper db, EA.Weee.Domain.AatfReturn.Aatf aatf, Return @return)
        {
            var weeeSentOn        = new EA.Weee.Domain.AatfReturn.WeeeSentOn(ObligatedWeeeIntegrationCommon.CreateAatfAddress(db), ObligatedWeeeIntegrationCommon.CreateAatfAddress(db), aatf, @return);
            var weeeSentOnAmounts = new List <WeeeSentOnAmount>()
            {
                new Domain.AatfReturn.WeeeSentOnAmount(weeeSentOn, 1, 1, 2),
                new Domain.AatfReturn.WeeeSentOnAmount(weeeSentOn, 2, 3, 4)
            };

            db.WeeeContext.Returns.Add(@return);
            db.WeeeContext.ReturnAatfs.Add(new ReturnAatf(aatf, @return));
            db.WeeeContext.WeeeSentOn.Add(weeeSentOn);
            db.WeeeContext.WeeeSentOnAmount.AddRange(weeeSentOnAmounts);

            await db.WeeeContext.SaveChangesAsync();

            db.WeeeContext.ReturnReportOns.Add(new ReturnReportOn(@return.Id, 2));

            await db.WeeeContext.SaveChangesAsync();
        }
Exemplo n.º 10
0
 private void AssertFixedPropertiesForReturn(List <AatfSubmissionHistory> results, DatabaseWrapper db, Return @return)
 {
     results.ElementAt(0).SubmittedBy.Should().Be(db.Model.AspNetUsers.First().FirstName + " " + db.Model.AspNetUsers.First().Surname);
     results.ElementAt(0).SubmittedDate.Date.Should().Be(@return.SubmittedDate.Value.Date);
     results.ElementAt(0).ComplianceYear.Should().Be(@return.Quarter.Year);
     results.ElementAt(0).Quarter.Should().Be((int)@return.Quarter.Q);
 }