public async Task <bool> HandleAsync(SubmitReturn message) { authorization.EnsureCanAccessExternalArea(); var @return = await genericDataAccess.GetById <Return>(message.ReturnId); if (@return == null) { throw new ArgumentException($"No return was found with id {message.ReturnId}."); } if (@return.ReturnStatus == ReturnStatus.Submitted) { return(true); } authorization.EnsureOrganisationAccess(@return.Organisation.Id); @return.UpdateSubmitted(userContext.UserId.ToString(), message.NilReturn); var aatfs = await fetchAatfDataAccess.FetchAatfByReturnQuarterWindow(@return); var returnAatfs = aatfs.Select(a => new ReturnAatf(a, @return)); await genericDataAccess.AddMany <ReturnAatf>(returnAatfs); await weeeContext.SaveChangesAsync(); return(true); }
public async Task HandleAsync_GivenReturnIsAatf_AatfsRecordsShouldBeAddedAgainstReturn() { var message = new SubmitReturn(Guid.NewGuid(), false); var @return = GetReturn(); @return.ReturnStatus = ReturnStatus.Created; var userId = Guid.NewGuid(); var aatfs = new List <Aatf>() { fixture.Build <Aatf>().Create() }; A.CallTo(() => genericDataAccess.GetById <Return>(message.ReturnId)).Returns(@return); A.CallTo(() => userContext.UserId).Returns(userId); A.CallTo(() => fetchAatfDataAccess.FetchAatfByReturnQuarterWindow(@return)).Returns(aatfs); await handler.HandleAsync(message); A.CallTo(() => genericDataAccess.AddMany <ReturnAatf>(A <IEnumerable <ReturnAatf> > .That.Matches(a => a.ElementAt(0).Return.Equals(@return) && a.ElementAt(0).Aatf.Equals(aatfs.ElementAt(0))))).MustHaveHappened() .Then(A.CallTo(() => weeeContext.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once)); }
public async Task HandleAsync_GivenAddReportOnRequest_DataAccessAddIsCalled() { var questions = CreateSelectedOptions(); var selectedOptions = CreateReportQuestions(); var request = new AddReturnReportOn() { ReturnId = Guid.NewGuid(), SelectedOptions = questions, Options = selectedOptions }; await handler.HandleAsync(request); var returnReportOn = CreateReportedOptions(request.ReturnId); A.CallTo(() => dataAccess.AddMany <ReturnReportOn>(A <IList <ReturnReportOn> > .That.Matches(r => r.Count == 4))).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => dataAccess.AddMany <ReturnReportOn>(A <IList <ReturnReportOn> > .That.IsSameAs(returnReportOn))); }
public async Task <bool> HandleAsync(AddReturnReportOn message) { authorization.EnsureCanAccessExternalArea(); if (message.DeselectedOptions != null && message.DeselectedOptions.Count != 0) { foreach (var deselected in message.DeselectedOptions) { switch (deselected) { case (int)ReportOnQuestionEnum.WeeeReceived: await DeleteWeeeReceivedData(message.ReturnId); break; case (int)ReportOnQuestionEnum.WeeeSentOn: await DeleteWeeeSentOnData(message.ReturnId); break; case (int)ReportOnQuestionEnum.WeeeReused: await DeleteWeeeReusedData(message.ReturnId); break; case (int)ReportOnQuestionEnum.NonObligated: await DeleteNonObligatedData(message.ReturnId, false); break; case (int)ReportOnQuestionEnum.NonObligatedDcf: await DeleteNonObligatedData(message.ReturnId, true); break; default: break; } } } var oldReturnOptions = await dataAccess.GetManyByReturnId <ReturnReportOn>(message.ReturnId); dataAccess.RemoveMany <ReturnReportOn>(oldReturnOptions); await context.SaveChangesAsync(); if (message.SelectedOptions != null && message.SelectedOptions.Any()) { var returnReportOn = new List <ReturnReportOn>(); foreach (var option in message.SelectedOptions) { returnReportOn.Add(new ReturnReportOn(message.ReturnId, option)); } if (message.DcfSelectedValue) { var isParentSelected = message.SelectedOptions.Contains((int?)ReportOnQuestionEnum.NonObligated ?? default(int)); if (isParentSelected) { returnReportOn.Add(new ReturnReportOn(message.ReturnId, (int)ReportOnQuestionEnum.NonObligatedDcf)); } } await dataAccess.AddMany <ReturnReportOn>(returnReportOn); } return(true); }