public async Task RemoveReturnScheme_GivenSchemeIdsAndReturn_EntitiesShouldBeRemoved() { using (var database = new DatabaseWrapper()) { var helper = new ModelHelper(database.Model); var domainHelper = new DomainHelper(database.WeeeContext); var dataAccess = new ReturnSchemeDataAccess(database.WeeeContext); var @return = ObligatedWeeeIntegrationCommon.CreateReturn(null, database.Model.AspNetUsers.First().Id, FacilityType.Aatf); var aatf = ObligatedWeeeIntegrationCommon.CreateAatf(database, @return.Organisation); var scheme = new EA.Weee.Domain.Scheme.Scheme(@return.Organisation); var weeeReceived = new EA.Weee.Domain.AatfReturn.WeeeReceived(scheme, aatf, @return); var weeeReceivedAmounts = new Domain.AatfReturn.WeeeReceivedAmount(weeeReceived, 1, null, null); var returnScheme = new Domain.AatfReturn.ReturnScheme(scheme, @return); database.WeeeContext.Returns.Add(@return); database.WeeeContext.Organisations.Add(@return.Organisation); database.WeeeContext.Aatfs.Add(aatf); database.WeeeContext.Schemes.Add(scheme); database.WeeeContext.WeeeReceived.Add(weeeReceived); database.WeeeContext.WeeeReceivedAmount.Add(weeeReceivedAmounts); database.WeeeContext.ReturnScheme.Add(returnScheme); await database.WeeeContext.SaveChangesAsync(); await dataAccess.RemoveReturnScheme(new List <Guid>() { scheme.Id }, @return.Id); database.WeeeContext.ReturnScheme.Count(r => r.SchemeId == scheme.Id).Should().Be(0); database.WeeeContext.WeeeReceived.Count(r => r.SchemeId == scheme.Id).Should().Be(0); database.WeeeContext.WeeeReceivedAmount.Count(r => r.WeeeReceived.Id == weeeReceived.Id).Should().Be(0); database.WeeeContext.Schemes.Count(s => s.Id == scheme.Id).Should().Be(1); database.WeeeContext.Returns.Count(r => r.Id == @return.Id).Should().Be(1); } }
public async Task CanCreateReturnScheme() { using (var database = new DatabaseWrapper()) { var context = database.WeeeContext; var name = "Test Name" + Guid.NewGuid(); var tradingName = "Test Trading Name" + Guid.NewGuid(); const string crn = "ABC12345"; var organisation = Organisation.Organisation.CreateRegisteredCompany(name, crn, tradingName); context.Organisations.Add(organisation); await context.SaveChangesAsync(); var scheme = new Scheme(organisation.Id); context.Schemes.Add(scheme); var quarter = new Quarter(2019, QuarterType.Q1); var @return = new Return(organisation, quarter, database.Model.AspNetUsers.First().Id, FacilityType.Aatf); context.Returns.Add(@return); await context.SaveChangesAsync(); var dataAccess = new ReturnSchemeDataAccess(database.WeeeContext); var returnScheme = new ReturnScheme(scheme, @return); await dataAccess.Submit(new List <ReturnScheme> { returnScheme }); var returnSchemeReturned = context.ReturnScheme.First(o => o.Id == returnScheme.Id); returnSchemeReturned.Should().NotBeNull(); returnSchemeReturned.ReturnId.Should().Be(@return.Id); returnSchemeReturned.SchemeId.Should().Be(scheme.Id); } }