/// <summary> /// Clears the database. /// </summary> /// <param name="context">The context.</param> public static void ClearDatabase(TestEntities context) { foreach (var e in context.Entities) context.Entities.Remove(e); foreach (var net in context.NamedEntityTypes) context.NamedEntityTypes.Remove(net); foreach (var o in context.Orders) context.Orders.Remove(o); context.SaveChanges(); }
/// <summary> /// Seeds the database. /// </summary> /// <param name="context">The context.</param> public static void SeedDatabase(TestEntities context) { // Create some data for tests. var nets = new[] { CreateNamedEntityType(1), CreateNamedEntityType(2), CreateNamedEntityType(3) }; var nes = new[] { CreateNamedEntity(nets[0], 1), CreateNamedEntity(nets[2], 2), CreateNamedEntity(nets[1]), CreateNamedEntity(nets[2]), CreateNamedEntity(nets[1]), CreateNamedEntity(nets[0]) }; var ads = new[] { CreateAddress(), CreateAddress(), CreateAddress() }; var cs = new[] { CreateLongNoCompany(nets[1]), CreateLongNoCompany(nets[2]), CreateCompany(nets[1]), CreateCompany(nets[2]), CreateCompany(nets[0]) }; var os = new[] { CreateOrder(42), CreateOrder(), CreateOrder() }; // add created data to context Array.ForEach(nets, net => context.NamedEntityTypes.Add(net)); Array.ForEach(ads, ad => context.Entities.Add(ad)); Array.ForEach(nes, ne => context.Entities.Add(ne)); Array.ForEach(cs, c => context.Entities.Add(c)); Array.ForEach(os, o => context.Orders.Add(o)); // save all data context.SaveChanges(); }