public async void UpdateAddress_GivenAddressToUpdate_ContextShouldContainUpdatedAddress() { using (var database = new DatabaseWrapper()) { var context = database.WeeeContext; var country = await context.Countries.SingleAsync(c => c.Name == "France"); var aatfAddress = AddressHelper.GetAatfAddress(database); var dataAccess = new AatfSiteDataAccess(context, A.Fake <IGenericDataAccess>()); var returnData = await CreateWeeeReusedSite(dataAccess, aatfAddress, database); var oldAddress = (context.WeeeReusedSite .Where(t => t.WeeeReused.ReturnId == returnData.Item1 && t.WeeeReused.Aatf.Id == returnData.Item2).FirstOrDefault()).Address; var newAddress = new SiteAddressData("Site1", "Address11", "Address21", "Town1", "County1", "PO12ST341", country.Id, country.Name); var newCountry = await context.Countries.SingleAsync(c => c.Name == "Germany"); await dataAccess.Update(oldAddress, newAddress, newCountry); AssertUpdated(context, returnData, newAddress, newCountry); } }
private async Task <Tuple <Guid, Guid> > CreateWeeeReusedSite(AatfSiteDataAccess dataAccess, AatfAddress aatfAddress, DatabaseWrapper database) { var organisation = ObligatedWeeeIntegrationCommon.CreateOrganisation(); var scheme = ObligatedWeeeIntegrationCommon.CreateScheme(organisation); var aatf = ObligatedWeeeIntegrationCommon.CreateAatf(database, organisation); var @return = ObligatedWeeeIntegrationCommon.CreateReturn(organisation, database.Model.AspNetUsers.First().Id); database.WeeeContext.Organisations.Add(organisation); database.WeeeContext.Schemes.Add(scheme); database.WeeeContext.Aatfs.Add(aatf); database.WeeeContext.Returns.Add(@return); await database.WeeeContext.SaveChangesAsync(); var weeeReused = new WeeeReused(aatf.Id, @return.Id); database.WeeeContext.WeeeReused.Add(weeeReused); foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>()) { database.WeeeContext.WeeeReusedAmount.Add(new WeeeReusedAmount(weeeReused, (int)category, (int)category, (int)category + 1)); } await database.WeeeContext.SaveChangesAsync(); var weeeReusedSite = new WeeeReusedSite(weeeReused, aatfAddress); await dataAccess.Submit(weeeReusedSite); return(Tuple.Create(@return.Id, aatf.Id)); }
public AatfSiteDataAccessTests() { context = A.Fake <WeeeContext>(); genericDataAccess = A.Fake <IGenericDataAccess>(); dataAccess = new AatfSiteDataAccess(context, genericDataAccess); dbContextHelper = new DbContextHelper(); aatfId = A.Dummy <Guid>(); }
public async Task CanCreateAatfAddressEntry() { using (var database = new DatabaseWrapper()) { var context = database.WeeeContext; var aatfAddress = AddressHelper.GetAatfAddress(database); var dataAccess = new AatfSiteDataAccess(context, A.Fake <IGenericDataAccess>()); var returnData = await CreateWeeeReusedSite(dataAccess, aatfAddress, database); AssertSubmitted(context, aatfAddress.Country, returnData, aatfAddress); } }
private static async Task CreateWeeeReusedAmounts( ObligatedReusedDataAccess obligatedReusedDataAccess, AatfSiteDataAccess aatfSiteDataAccess, Return @return, Aatf aatf, AatfAddress address) { var weeeReused = new WeeeReused(aatf.Id, @return.Id); var weeeReusedAmount = new List <WeeeReusedAmount>(); foreach (var category in Enum.GetValues(typeof(WeeeCategory)).Cast <WeeeCategory>()) { weeeReusedAmount.Add(new WeeeReusedAmount(weeeReused, (int)category, (int)category, (int)category + 1)); } var weeeReusedSite = new WeeeReusedSite(weeeReused, address); await obligatedReusedDataAccess.Submit(weeeReusedAmount); await aatfSiteDataAccess.Submit(weeeReusedSite); }