Пример #1
0
        public async Task HandleAsync_GivenRequest_ReturnDataAccessIsCalled()
        {
            var request = new GetReturnObligatedCsv(Guid.NewGuid());

            await handler.HandleAsync(request);

            A.CallTo(() => returnDataAccess.GetById(request.ReturnId)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task HandleAsync_GivenAddReturnSchemeRequest_ReturnShouldBeRetrieved()
        {
            var returnId = Guid.NewGuid();

            var request = new AddReturnScheme {
                ReturnId = returnId, SchemeIds = new List <Guid>()
            };

            await handler.HandleAsync(request);

            A.CallTo(() => returnDataAccess.GetById(returnId)).MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #3
0
        public async Task GetReturnData_GivenReturn_ReturnShouldBeRetrieved()
        {
            var returnId = Guid.NewGuid();

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

            A.CallTo(() => returnDataAccess.GetById(returnId)).MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #4
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));
        }
        public async Task HandleAsync_NoOrganisationAccess_ThrowsSecurityException()
        {
            var authorization = new AuthorizationBuilder().DenyOrganisationAccess().Build();

            A.CallTo(() => returnDataAccess.GetById(A <Guid> ._)).Returns(A.Fake <Return>());

            handler = new GetReturnStatusHandler(authorization,
                                                 returnDataAccess,
                                                 mapper);

            Func <Task> action = async() => await handler.HandleAsync(A.Dummy <GetReturnStatus>());

            await action.Should().ThrowAsync <SecurityException>();
        }
Пример #6
0
        public async Task <bool> HandleAsync(AddNonObligated message)
        {
            authorization.EnsureCanAccessExternalArea();

            var aatfReturn = await returnDataAccess.GetById(message.ReturnId);

            var nonObligatedWeees = mapper.Map(message, aatfReturn);

            await nonObligatedDataAccess.InsertNonObligatedWeee(message.ReturnId, nonObligatedWeees);

            return(true);
        }
Пример #7
0
        public async Task <bool> HandleAsync(EditNonObligated message)
        {
            authorization.EnsureCanAccessExternalArea();

            var aatfReturn = await returnDataAccess.GetById(message.ReturnId);

            var idsToAmounts = mapper.Map(message, aatfReturn);

            await nonObligatedDataAccess.UpdateNonObligatedWeeeAmounts(message.ReturnId, idsToAmounts);

            return(true);
        }
Пример #8
0
        public async Task <List <Guid> > HandleAsync(AddReturnScheme message)
        {
            authorization.EnsureCanAccessExternalArea();

            var @return = await returnDataAccess.GetById(message.ReturnId);

            var returnSchemes = new List <ReturnScheme>();

            foreach (var schemeId in message.SchemeIds)
            {
                var scheme = await schemeDataAccess.GetSchemeOrDefault(schemeId);

                returnSchemes.Add(new ReturnScheme(scheme, @return));
            }

            return(await returnSchemeDataAccess.Submit(returnSchemes));
        }
        public async Task <bool> HandleAsync(AddNonObligated message)
        {
            authorization.EnsureCanAccessExternalArea();

            var aatfReturn = await returnDataAccess.GetById(message.ReturnId);

            var nonObligatedWee = new List <NonObligatedWeee>();

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

            await nonObligatedDataAccess.Submit(nonObligatedWee);

            return(true);
        }
Пример #10
0
        public async Task <CSVFileData> HandleAsync(GetReturnObligatedCsv request)
        {
            var @return = await returnDataAccess.GetById(request.ReturnId);

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

            var obligatedData = await weeContext.StoredProcedures.GetReturnObligatedCsvData(@return.Id);

            var fileName =
                $"{@return.Quarter.Year}_{@return.Quarter.Q}_{@return.Organisation.OrganisationName}_Obligated return data_{SystemTime.UtcNow:ddMMyyyy_HHmm}.csv";

            var fileContent = obligatedData.DataTableToCsv(new List <string>(new string[] { "ReturnId", "AatfKey", "ObligationType", "CategoryId", "AatfId" }));

            obligatedData.Dispose();

            return(new CSVFileData
            {
                FileContent = fileContent,
                FileName = fileName
            });
        }
Пример #11
0
        public async Task <ReturnStatusData> HandleAsync(GetReturnStatus message)
        {
            authorization.EnsureCanAccessExternalArea();

            var @return = await returnDataAccess.GetById(message.ReturnId);

            if (@return == null)
            {
                throw new ArgumentException($"No return was found with id {message.ReturnId}.");
            }

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

            var returnsInYear = await returnDataAccess.GetByComplianceYearAndQuarter(@return);

            var returnData = new ReturnStatusData
            {
                ReturnStatus          = mapper.Map <ReturnStatus>(@return.ReturnStatus),
                OrganisationId        = @return.Organisation.Id,
                OtherInProgressReturn = returnsInYear.Any(r => r.ReturnStatus == EA.Weee.Domain.AatfReturn.ReturnStatus.Created)
            };

            return(returnData);
        }
Пример #12
0
        public async Task <Guid> HandleAsync(AddSentOnAatfSite message)
        {
            authorization.EnsureCanAccessExternalArea();

            var siteCountry = await organisationDetailsDataAccess.FetchCountryAsync(message.SiteAddressData.CountryId);

            var operatorCountry = await organisationDetailsDataAccess.FetchCountryAsync(message.OperatorAddressData.CountryId);

            var @return = await returnDataAccess.GetById(message.ReturnId);

            var aatf = await genericDataAccess.GetById <Aatf>(message.AatfId);

            var siteAddress = new AatfAddress(
                message.SiteAddressData.Name,
                message.SiteAddressData.Address1,
                message.SiteAddressData.Address2,
                message.SiteAddressData.TownOrCity,
                message.SiteAddressData.CountyOrRegion,
                message.SiteAddressData.Postcode,
                siteCountry);

            var operatorAddress = new AatfAddress(
                message.OperatorAddressData.Name,
                message.OperatorAddressData.Address1,
                message.OperatorAddressData.Address2,
                message.OperatorAddressData.TownOrCity,
                message.OperatorAddressData.CountyOrRegion,
                message.OperatorAddressData.Postcode,
                operatorCountry);

            var weeeSentOn = new WeeeSentOn(operatorAddress, siteAddress, aatf, @return);

            await sentOnDataAccess.Submit(weeeSentOn);

            return(weeeSentOn.Id);
        }