public async Task HandleAsync_GivenWeeeReceivedDeselected_DeleteMethodsCalled()
        {
            var request = new AddReturnReportOn()
            {
                ReturnId          = Guid.NewGuid(),
                SelectedOptions   = CreateSelectedOptions(),
                DeselectedOptions = new List <int>()
                {
                    1
                },
                Options          = CreateReportQuestions(),
                DcfSelectedValue = true
            };

            var weeeReceived = A.Fake <WeeeReceived>();

            A.CallTo(() => weeeReceived.Id).Returns(Guid.NewGuid());
            A.CallTo(() => dataAccess.GetManyByReturnId <WeeeReceived>(request.ReturnId)).Returns(new List <WeeeReceived>()
            {
                weeeReceived
            });

            await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.GetManyByExpression(A <WeeeReceivedAmountByWeeeReceivedIdSpecification> ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.RemoveMany <WeeeReceivedAmount>(A <IList <WeeeReceivedAmount> > ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.RemoveMany <WeeeReceived>(A <IList <WeeeReceived> > ._)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.RemoveMany <ReturnScheme>(A <IList <ReturnScheme> > ._)).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #2
0
        public async Task GetReturnData_GivenReturn_ReturnReportsOnShouldBeRetrieved()
        {
            var returnId = Guid.NewGuid();

            var result = await populatedReturn.GetReturnData(returnId, A.Dummy <bool>());

            A.CallTo(() => genericDataAccess.GetManyByExpression(A <ReturnReportOnByReturnIdSpecification> .That.Matches(s => s.ReturnId.Equals(returnId)))).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #3
0
        public async void HandleAsync_GivenRequest_DataAccessShouldBeCalled()
        {
            var id = Guid.NewGuid();

            await handler.HandleAsync(new GetAatfByOrganisation(id));

            A.CallTo(() => dataAccess.GetManyByExpression(A <AatfsByOrganisationSpecification> .That.Matches(c => c.OrganisationId == id))).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #4
0
        public async Task HandleAsync_GivenReturn_ReturnReportsOnShouldBeRetrieved()
        {
            var returnId = SetupReturn();

            await handler.HandleAsync(new GetReturnNonObligatedCsv(returnId));

            A.CallTo(() => dataAccess.GetManyByExpression(A <ReturnReportOnByReturnIdSpecification> .That.Matches(r => r.ReturnId == @returnId))).MustHaveHappenedOnceExactly();
        }
예제 #5
0
        public async void HandleAsync_GivenRequest_DataAccessShouldBeCalled()
        {
            var id   = Guid.NewGuid();
            var type = Core.AatfReturn.FacilityType.Aatf;
            await handler.HandleAsync(new GetAatfByOrganisationFacilityType(id, type));

            A.CallTo(() => dataAccess.GetManyByExpression(A <AatfsByOrganisationAndFacilityTypeSpecification> .That.Matches(c => c.OrganisationId == id))).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.GetManyByExpression(A <AatfsByOrganisationAndFacilityTypeSpecification> .That.Matches(c => c.FacilityType.Equals(type)))).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #6
0
        public async Task GetAddresses_GivenAatfAndReturnId_AddressShouldBeReturned()
        {
            var aatfId   = Guid.NewGuid();
            var returnId = Guid.NewGuid();

            var aatfAddressMatch = A.Fake <AatfAddress>();
            var weeeReused       = A.Fake <WeeeReused>();
            var weeeReusedSite   = A.Fake <WeeeReusedSite>();

            A.CallTo(() => context.AatfAddress).Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <AatfAddress>()
            {
                aatfAddressMatch
            }));
            A.CallTo(() => weeeReused.AatfId).Returns(aatfId);
            A.CallTo(() => weeeReused.ReturnId).Returns(returnId);
            A.CallTo(() => context.WeeeReused).Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <WeeeReused>()
            {
                weeeReused
            }));
            A.CallTo(() => genericDataAccess.GetManyByExpression(A <WeeeReusedByAatfIdAndReturnIdSpecification> ._)).Returns(new List <WeeeReused>()
            {
                weeeReused
            });
            A.CallTo(() => weeeReusedSite.WeeeReused).Returns(weeeReused);
            A.CallTo(() => weeeReusedSite.Address).Returns(aatfAddressMatch);
            A.CallTo(() => context.WeeeReusedSite).Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <WeeeReusedSite>()
            {
                weeeReusedSite
            }));

            var result = await dataAccess.GetAddresses(aatfId, returnId);

            result.Should().BeEquivalentTo(aatfAddressMatch);
        }
예제 #7
0
        public async Task <bool> HandleAsync(AddAatfSite message)
        {
            authorization.EnsureCanAccessExternalArea();

            Country country = await organisationDetailsDataAccess.FetchCountryAsync(message.AddressData.CountryId);

            var address = new AatfAddress(
                message.AddressData.Name,
                message.AddressData.Address1,
                message.AddressData.Address2,
                message.AddressData.TownOrCity,
                message.AddressData.CountyOrRegion,
                message.AddressData.Postcode,
                country);

            var weeeReused = await genericDataAccess.GetManyByExpression <WeeeReused>(new WeeeReusedByAatfIdAndReturnIdSpecification(message.AatfId, message.ReturnId));

            var weeeReusedSite = new WeeeReusedSite(
                weeeReused.Last(),
                address);

            await offSiteDataAccess.Submit(weeeReusedSite);

            return(true);
        }
예제 #8
0
        public async Task <ReturnData> GetReturnData(Guid returnId, bool forSummary)
        {
            authorization.EnsureCanAccessExternalArea();

            var @return = await returnDataAccess.GetById(returnId);

            if (@return == null)
            {
                throw new ArgumentException($"No return found for return id {returnId}");
            }

            authorization.EnsureOrganisationAccess(@return.Organisation.Id);

            var annualQuarterWindow = await quarterWindowFactory.GetQuarterWindow(@return.Quarter);

            var returnNonObligatedValues = await nonObligatedDataAccess.FetchNonObligatedWeeeForReturn(returnId);

            var returnObligatedReceivedValues = await obligatedDataAccess.FetchObligatedWeeeReceivedForReturn(returnId);

            var returnObligatedReusedValues = await obligatedDataAccess.FetchObligatedWeeeReusedForReturn(returnId);

            List <Aatf> aatfs;

            if (forSummary && @return.ReturnStatus.Equals(EA.Weee.Domain.AatfReturn.ReturnStatus.Submitted))
            {
                aatfs = await aatfDataAccess.FetchAatfByReturnId(@return.Id);
            }
            else
            {
                aatfs = await aatfDataAccess.FetchAatfByReturnQuarterWindow(@return);
            }

            var sentOn = await obligatedDataAccess.FetchObligatedWeeeSentOnForReturnByReturn(returnId);

            var returnSchemeList = await returnSchemeDataAccess.GetSelectedSchemesByReturnId(returnId);

            var returnReportsOn = await genericDataAccess.GetManyByExpression(new ReturnReportOnByReturnIdSpecification(returnId));

            var currentDate    = SystemTime.Now;
            var systemSettings = await systemDataDataAccess.Get();

            if (systemSettings.UseFixedCurrentDate)
            {
                currentDate = systemSettings.FixedCurrentDate;
            }

            var returnQuarterWindow = new ReturnQuarterWindow(@return,
                                                              annualQuarterWindow,
                                                              aatfs,
                                                              returnNonObligatedValues,
                                                              returnObligatedReceivedValues,
                                                              returnObligatedReusedValues,
                                                              @return.Organisation,
                                                              sentOn,
                                                              returnSchemeList,
                                                              returnReportsOn,
                                                              currentDate);

            return(mapper.Map(returnQuarterWindow));
        }
예제 #9
0
        public async Task HandleAsync_WithValidInput_SubmitIsCalledCorrectly()
        {
            var siteRequest = AddAatfSiteRequest();
            var weeReused   = new WeeeReused(siteRequest.AatfId, siteRequest.ReturnId);
            var country     = new Country(A.Dummy <Guid>(), A.Dummy <string>());

            A.CallTo(() => organisationDetailsDataAccess.FetchCountryAsync(siteRequest.AddressData.CountryId)).Returns(country);
            A.CallTo(() => genericDataAccess.GetManyByExpression(
                         A <WeeeReusedByAatfIdAndReturnIdSpecification> .That.Matches(w =>
                                                                                      w.AatfId == siteRequest.AatfId && w.ReturnId == siteRequest.ReturnId))).Returns(new List <WeeeReused>()
            {
                weeReused
            });

            await handler.HandleAsync(siteRequest);

            A.CallTo(() => addAatfSiteDataAccess.Submit(A <WeeeReusedSite> .That.Matches(w =>
                                                                                         w.Address.Address1.Equals(siteRequest.AddressData.Address1) &&
                                                                                         w.Address.Address2.Equals(siteRequest.AddressData.Address2) &&
                                                                                         w.Address.CountyOrRegion.Equals(siteRequest.AddressData.CountyOrRegion) &&
                                                                                         w.Address.TownOrCity.Equals(siteRequest.AddressData.TownOrCity) &&
                                                                                         w.Address.Postcode.Equals(siteRequest.AddressData.Postcode) &&
                                                                                         w.Address.Country.Equals(country) &&
                                                                                         w.WeeeReused.Equals(weeReused)))).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #10
0
        public async Task <List <AatfData> > HandleAsync(GetAatfByOrganisation message)
        {
            authorization.EnsureInternalOrOrganisationAccess(message.OrganisationId);

            var aatfs = await genericDataAccess.GetManyByExpression(new AatfsByOrganisationSpecification(message.OrganisationId));

            return(aatfs.Select(a => mapper.Map(a)).ToList());
        }
예제 #11
0
        private async Task DeleteWeeeReceivedData(Guid returnId)
        {
            var weeeReceiveds = await dataAccess.GetManyByReturnId <WeeeReceived>(returnId);

            var weeeReceivedAmounts = new List <WeeeReceivedAmount>();
            var weeeReturnSchemes   = await dataAccess.GetManyByReturnId <ReturnScheme>(returnId);

            foreach (var weeeReceived in weeeReceiveds)
            {
                weeeReceivedAmounts.AddRange(await dataAccess.GetManyByExpression(new WeeeReceivedAmountByWeeeReceivedIdSpecification(weeeReceived.Id)));
            }

            dataAccess.RemoveMany <WeeeReceivedAmount>(weeeReceivedAmounts);
            dataAccess.RemoveMany <WeeeReceived>(weeeReceiveds);
            dataAccess.RemoveMany <ReturnScheme>(weeeReturnSchemes);

            await context.SaveChangesAsync();
        }
        private async Task <bool> SelectedDcf(Guid returnId)
        {
            var reportsOn = await dataAccess.GetManyByExpression(new ReturnReportOnByReturnIdSpecification(returnId));

            return(reportsOn.Any(r => r.ReportOnQuestionId == (int)ReportOnQuestionEnum.NonObligatedDcf));
        }
        public async Task <List <AatfData> > HandleAsync(GetAatfByOrganisationFacilityType message)
        {
            var aatfs = await genericDataAccess.GetManyByExpression(new AatfsByOrganisationAndFacilityTypeSpecification(message.OrganisationId, message.FacilityType));

            return(aatfs.Select(a => mapper.Map(a)).ToList());
        }
예제 #14
0
        public async Task <List <AatfAddress> > GetAddresses(Guid aatfId, Guid returnId)
        {
            var weeeReusedId = (await genericDataAccess.GetManyByExpression <WeeeReused>(new WeeeReusedByAatfIdAndReturnIdSpecification(aatfId, returnId))).Last().Id;

            return(await context.WeeeReusedSite.Where(w => w.WeeeReused.Id == weeeReusedId).Select(w => w.Address).ToListAsync());
        }