public void OneTimeSetUp() { Database.SetInitializer(new DropCreateDatabaseAlways <TestPersistenceContext>()); context = new TestPersistenceContext(); testEntityEqComp = new TestEntityEqualityComparer(); }
public void Update_UpdatesEntities() { TestEntity testEntityOne = new TestEntity { Name = "Test Entity One", Field1 = "not updated" }; TestEntity testEntityTwo = new TestEntity { Name = "Test Entity Two", Field1 = "not updated" }; context.Entities.Add(testEntityOne); context.Entities.Add(testEntityTwo); context.SaveChanges(); testEntityOne.Field1 = "updated"; testEntityTwo.Field1 = "updated"; var repo = new DataRepositoryUsingTestPersistenceContext <TestEntity>(); repo.Update(testEntityOne, testEntityTwo); // Get new test entities from new context to check values have been changed in database. // A given context will only ever have a single object reference for a given entity. using (var tempContext = new TestPersistenceContext()) { testEntityOne = tempContext.Entities.Single(e => e.Name == "Test Entity One"); testEntityTwo = tempContext.Entities.Single(e => e.Name == "Test Entity Two"); } Assert.AreEqual("updated", testEntityOne.Field1); Assert.AreEqual("updated", testEntityTwo.Field1); }