private void AddNewPersonsWithAnimals() { using (var dbContext = new PersonModelContext()) { dbContext.Persons.AddRange(persons); dbContext.SaveChanges(); } }
public void Should_return_the_collection_saved() { using (var dbContext = new PersonModelContext()) { var persons = dbContext.Persons.ToListAsync().Result; Check.That(persons.Count()).IsEqualTo(persons.Count); } }
private void CleanPersonsAndAnimals() { using (var dbContext = new PersonModelContext()) { var deleteAnimals = $"delete from Animal"; dbContext.Database.ExecuteSqlRaw(deleteAnimals); var deletePersons = $"delete from Persons"; dbContext.Database.ExecuteSqlRaw(deletePersons); } }
public void Should_Throw_an_object_disposed_exception_when_get_enumerable_elements_after_disposing_dbcontext() { IEnumerable <Person> queriedPersons = null; using (var dbContext = new PersonModelContext()) { queriedPersons = GetPersons(dbContext); } Check.ThatCode(() => queriedPersons.Count()) .Throws <ObjectDisposedException>(); }
private static IEnumerable <Person> GetPersons(PersonModelContext dbContext) { var persons = dbContext.Persons.Where(person => person.Id % 2 == 0); return(persons.Skip(1)); }