コード例 #1
0
        public async Task HandleAsync_OpenQuartersShouldBeReturned()
        {
            var message       = new GetReturns(Guid.NewGuid(), Core.AatfReturn.FacilityType.Aatf);
            var returnQuarter = new Quarter(2019, QuarterType.Q1);

            List <Domain.DataReturns.QuarterWindow> openWindows = new List <Domain.DataReturns.QuarterWindow>()
            {
                new Domain.DataReturns.QuarterWindow(new DateTime(2019, 04, 01), new DateTime(2019, 06, 01), Domain.DataReturns.QuarterType.Q1)
            };

            Domain.DataReturns.QuarterWindow nextWindow = new Domain.DataReturns.QuarterWindow(new DateTime(2019, 06, 01), new DateTime(2019, 09, 01), Domain.DataReturns.QuarterType.Q2);

            A.CallTo(() => returnFactory.GetReturnQuarter(message.OrganisationId, message.Facility)).Returns(returnQuarter);

            DateTime date = new DateTime(2019, 04, 01);

            SystemTime.Freeze(date);

            A.CallTo(() => quarterWindowFactory.GetQuarterWindowsForDate(date)).Returns(openWindows);
            A.CallTo(() => quarterWindowFactory.GetNextQuarterWindow(Domain.DataReturns.QuarterType.Q1, 2019)).Returns(nextWindow);

            var result = await handler.HandleAsync(message);

            SystemTime.Unfreeze();

            result.OpenQuarters.Count.Should().Be(1);
            result.OpenQuarters[0].Q.Should().Be(QuarterType.Q1);
            result.OpenQuarters[0].Year.Should().Be(returnQuarter.Year);

            A.CallTo(() => quarterWindowFactory.GetQuarterWindowsForDate(date)).MustHaveHappened(Repeated.Exactly.Once);
        }
コード例 #2
0
        public async void UsingFixedDate_DateIsWithinOneOfTheQuarterWindow_ReturnTrue()
        {
            var systemData = new SubmissionWindowClosedTests.TestSystemData();

            systemData.UpdateFixedCurrentDate(new DateTime(2016, 4, 10, 0, 0, 0));
            systemData.ToggleFixedCurrentDateUsage(true);

            A.CallTo(() => systemDataDataAccess.Get())
            .Returns(systemData);

            var windowStart = new DateTime(2016, 4, 1, 0, 0, 0);
            var windowEnd   = new DateTime(2017, 3, 16, 0, 0, 0);

            A.CallTo(() => quarterWindowFactory.GetQuarterWindowsForDate(A <DateTime> ._))
            .Returns(new List <QuarterWindow>
            {
                new QuarterWindow(windowStart, windowEnd, QuarterType.Q1)
            });

            var handler = new IsSubmissionWindowOpenHandler(quarterWindowFactory, systemDataDataAccess);

            var result = await handler.HandleAsync(A.Dummy <IsSubmissionWindowOpen>());

            Assert.True(result);
        }
コード例 #3
0
        public async Task <bool> HandleAsync(IsSubmissionWindowOpen query)
        {
            var currentDate    = SystemTime.Now;
            var systemSettings = await systemDataDataAccess.Get();

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

            var possibleQuarterWindows = await quarterWindowFactory.GetQuarterWindowsForDate(currentDate);

            return(possibleQuarterWindows.Count > 0);
        }
コード例 #4
0
        public async Task <ReturnsData> HandleAsync(GetReturns message)
        {
            authorization.EnsureCanAccessExternalArea();

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

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

            var @returns = await returnDataAccess.GetByOrganisationId(message.OrganisationId);

            var quarter = await returnFactory.GetReturnQuarter(message.OrganisationId, message.Facility);

            var openQuarters = await quarterWindowFactory.GetQuarterWindowsForDate(currentDate);

            var returnsData = new List <ReturnData>();

            foreach (var @return in @returns.Where(p => p.FacilityType.Value == (int)message.Facility))
            {
                returnsData.Add(await getPopulatedReturn.GetReturnData(@return.Id, false));
            }

            var returnOpenQuarters = new List <Core.DataReturns.Quarter>();

            foreach (var q in openQuarters)
            {
                returnOpenQuarters.Add(new Core.DataReturns.Quarter(q.StartDate.Year, (Core.DataReturns.QuarterType)q.QuarterType));
            }

            Core.AatfReturn.QuarterWindow nextQuarter = null;

            if (openQuarters.Count > 0)
            {
                var latestOpenQuarter = openQuarters.OrderByDescending(p => p.QuarterType).FirstOrDefault();

                var nextWindow = await quarterWindowFactory.GetNextQuarterWindow(latestOpenQuarter.QuarterType, latestOpenQuarter.StartDate.Year);

                nextQuarter = new Core.AatfReturn.QuarterWindow(nextWindow.StartDate, nextWindow.EndDate, (QuarterType)nextWindow.QuarterType);
            }

            return(new ReturnsData(returnsData, quarter, returnOpenQuarters, nextQuarter, currentDate));
        }
コード例 #5
0
ファイル: ReturnFactory.cs プロジェクト: DEFRA/prsd-weee
        public async Task <Quarter> GetReturnQuarter(Guid organisationId, FacilityType facilityType)
        {
            var currentDate    = SystemTime.Now;
            var systemSettings = await systemDataDataAccess.Get();

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

            var availableQuarterWindows = await quarterWindowFactory.GetQuarterWindowsForDate(currentDate);

            if (!availableQuarterWindows.Any())
            {
                return(null);
            }

            var windowDates = availableQuarterWindows.OrderBy(a => a.StartDate);

            foreach (var quarterWindow in windowDates)
            {
                var year = quarterWindow.QuarterType == Domain.DataReturns.QuarterType.Q4
                    ? quarterWindow.StartDate.Year - 1
                    : quarterWindow.StartDate.Year;

                var hasAatfWithApprovalDate = await returnFactoryDataAccess.ValidateAatfApprovalDate(organisationId, quarterWindow.StartDate, year, facilityType);

                var hasReturnExists = await returnFactoryDataAccess.HasReturnQuarter(organisationId, year, quarterWindow.QuarterType, facilityType);

                if (hasAatfWithApprovalDate && !hasReturnExists)
                {
                    return(new Quarter(year, (QuarterType)quarterWindow.QuarterType));
                }
            }

            return(null);
        }