public async Task HandleAsync_GivenOrganisation_ReturnsForOrganisationShouldBeRetrieved() { var organisationId = Guid.NewGuid(); var result = await handler.HandleAsync(new GetReturns(organisationId, Core.AatfReturn.FacilityType.Aatf)); A.CallTo(() => returnDataAccess.GetByOrganisationId(organisationId)).MustHaveHappened(Repeated.Exactly.Once); }
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)); }