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 RemoveAatf(Guid aatfId) { var aatf = await GetAatfById(aatfId); genericDataAccess.Remove(aatf); foreach (var returnAatf in context.ReturnAatfs.Where(r => r.Aatf.Id == aatfId)) { genericDataAccess.Remove(returnAatf); } await context.SaveChangesAsync(); }
public async Task <bool> HandleAsync(RemoveAatfSite message) { authorization.EnsureCanAccessExternalArea(); var site = await genericDataAccess.GetById <AatfAddress>(message.SiteId); var weeeReusedSiteId = (await genericDataAccess.GetSingleByExpression <WeeeReusedSite>(new WeeeReusedByAddressIdSpecification(message.SiteId))).Id; var weeeReusedSite = await genericDataAccess.GetById <WeeeReusedSite>(weeeReusedSiteId); genericDataAccess.Remove(weeeReusedSite); genericDataAccess.Remove(site); await context.SaveChangesAsync(); return(true); }
public async Task HandleAsync_GivenGetSentOnAatfSiteRequest_DataAccessIsCalled() { var siteAddressId = Guid.NewGuid(); var weeeReusedSiteId = Guid.NewGuid(); var siteAddress = new AatfAddress(); var weeeReusedSite = new WeeeReusedSite(); var weeeReusedSiteReturned = new WeeeReusedSite(); A.CallTo(() => genericDataAccess.GetById <AatfAddress>(siteAddressId)).Returns(siteAddress); A.CallTo(() => genericDataAccess.GetSingleByExpression <WeeeReusedSite>(A <WeeeReusedByAddressIdSpecification> .That.Matches(w => w.SiteId == siteAddressId))).Returns(weeeReusedSite); A.CallTo(() => genericDataAccess.GetById <WeeeReusedSite>(weeeReusedSite.Id)).Returns(weeeReusedSiteReturned); await handler.HandleAsync(new RemoveAatfSite(siteAddressId)); A.CallTo(() => genericDataAccess.Remove(weeeReusedSiteReturned)).MustHaveHappened(Repeated.Exactly.Once) .Then(A.CallTo(() => genericDataAccess.Remove(siteAddress)).MustHaveHappened(Repeated.Exactly.Once)) .Then(A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once)); }
public async void DeleteAatf_DeletesAatf() { var aatfId = Guid.NewGuid(); var aatf = A.Fake <Aatf>(); var returnAatf = A.Fake <ReturnAatf>(); A.CallTo(() => returnAatf.Aatf.Id).Returns(aatfId); A.CallTo(() => aatf.Id).Returns(aatfId); A.CallTo(() => context.Aatfs).Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <Aatf>() { aatf })); A.CallTo(() => context.ReturnAatfs).Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <ReturnAatf>() { returnAatf })); await dataAccess.RemoveAatf(aatfId); A.CallTo(() => genericDataAccess.Remove(aatf)).MustHaveHappened(Repeated.Exactly.Once) .Then(A.CallTo(() => genericDataAccess.Remove(returnAatf)).MustHaveHappened(Repeated.Exactly.Once)) .Then(A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once)); }
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); }