/// <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 List <NamedEntityType> { CreateNamedEntityType(1), CreateNamedEntityType(2), CreateNamedEntityType(3) }; var nes = new List <NamedEntity> { CreateNamedEntity(nets[0], 1), CreateNamedEntity(nets[2], 2), CreateNamedEntity(nets[1]), CreateNamedEntity(nets[2]), CreateNamedEntity(nets[1]), CreateNamedEntity(nets[0]) }; var ads = new List <Address> { CreateAddress(), CreateAddress(), CreateAddress() }; var cs = new List <Company> { CreateLongNoCompany(nets[1]), CreateLongNoCompany(nets[2]), CreateCompany(nets[1]), CreateCompany(nets[2]), CreateCompany(nets[0]) }; var os = new List <Order> { CreateOrder(1, 42), CreateOrder(2), CreateOrder(3) }; // add created data to context nets.ForEach(net => context.NamedEntityTypes.Add(net)); ads.ForEach(ad => context.Set <Address>().Add(ad)); nes.ForEach(ne => context.Set <NamedEntity>().Add(ne)); cs.ForEach(c => context.Set <Company>().Add(c)); os.ForEach(o => context.Orders.Add(o)); // save all data context.SaveChanges(); }