public void MarkEntityAsModified_WhenCalled() { // Arrange var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "MarkEntityAsModified_WhenCalled") .Options; var testMovie = new Movie { Name = "TestMovie" }; //Act using (var context = new AlphaCinemaContext(contextOptions)) { var movieRepo = new Repository <Movie>(context); movieRepo.Update(testMovie); EntityEntry entry = context.Entry(testMovie); //Assert Assert.AreEqual(EntityState.Modified, entry.State); } }
public void ChangeStateToUnchanged_WhenEntityIsAdded() { // Arrange var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "ChangeStateToAdded_WhenEntityIsModified") .Options; var testMovie = new Movie { Name = "TestMovie" }; //Act using (var context = new AlphaCinemaContext(contextOptions)) { var movieRepo = new Repository <Movie>(context); movieRepo.Add(testMovie); context.SaveChanges(); EntityEntry entry = context.Entry(testMovie); //Assert Assert.AreEqual(EntityState.Unchanged, entry.State); } }