public async Task <bool> HandleAsync(RemoveWeeeSentOn message) { authorization.EnsureCanAccessExternalArea(); var weeeSentOn = await genericDataAccess.GetById <WeeeSentOn>(message.WeeeSentOnId); if (weeeSentOn == null) { return(false); } var weeeSentOnAmount = await obligatedWeeeDataAccess.FetchObligatedWeeeSentOnForReturn(message.WeeeSentOnId); genericDataAccess.Remove(weeeSentOn.SiteAddress); genericDataAccess.Remove(weeeSentOn.OperatorAddress); genericDataAccess.Remove(weeeSentOn); genericDataAccess.RemoveMany(weeeSentOnAmount); await context.SaveChangesAsync(); return(true); }
public async Task HandleAsync_GivenGetSentOnAatfSiteRequest_DataAccessIsCalled() { var weeeSentOnId = Guid.NewGuid(); var weeeSentOn = new WeeeSentOn(); var weeeSentOnAmount = new List <WeeeSentOnAmount>(); A.CallTo(() => genericDataAccess.GetById <WeeeSentOn>(weeeSentOnId)).Returns(weeeSentOn); A.CallTo(() => obligatedWeeeDataAccess.FetchObligatedWeeeSentOnForReturn(weeeSentOnId)).Returns(weeeSentOnAmount); await handler.HandleAsync(new RemoveWeeeSentOn(weeeSentOnId)); A.CallTo(() => genericDataAccess.Remove(weeeSentOn)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => genericDataAccess.RemoveMany(weeeSentOnAmount)).MustHaveHappened(Repeated.Exactly.Once); }
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); }
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); }