public void InsertSimpleEntityFollowedByAnUpdate() { // Arrange const string updatedValue = "Updated Value"; FakeDbContext dbContext = new FakeDbContext(); SimpleEntityRepository entityRepository = new SimpleEntityRepository(dbContext); SimpleEntity simpleEntity = new SimpleEntity { Id = 1, SomeProperty = "Initial value" }; // Act entityRepository.Insert(simpleEntity); simpleEntity.SomeProperty = updatedValue; entityRepository.Update(simpleEntity); // Assert Assert.IsNotNull(entityRepository.DbContext); Assert.AreEqual(1, entityRepository.DbContext.ChangeTracker.Entries().Count()); // Ensure the entity in cache is still at a state of 'Added' but has the updated properties DbEntityEntry entry = entityRepository.DbContext.ChangeTracker.Entries().ToList()[0]; Assert.AreEqual(EntityState.Added, entry.State); Assert.AreEqual(updatedValue, ((SimpleEntity)entry.Entity).SomeProperty); }
public void InsertMultipleSimpleEntities() { // Arrange FakeDbContext dbContext = new FakeDbContext(); SimpleEntityRepository entityRepository = new SimpleEntityRepository(dbContext); SimpleEntity simpleEntity1 = new SimpleEntity { SomeProperty = "Some property 1" }; SimpleEntity simpleEntity2 = new SimpleEntity { SomeProperty = "Some property 2" }; // Act entityRepository.Insert(simpleEntity1); entityRepository.Insert(simpleEntity2); // Assert Assert.IsNotNull(entityRepository.DbContext); Assert.AreEqual(2, entityRepository.DbContext.ChangeTracker.Entries().Count()); entityRepository.DbContext.ChangeTracker.Entries().ToList().ForEach(entry => Assert.AreEqual(EntityState.Added, entry.State)); }
public void AddSimpleEntity() { // Arrange FakeDbContext dbContext = new FakeDbContext(); SimpleEntityRepository entityRepository = new SimpleEntityRepository(dbContext); SimpleEntity simpleEntity = new SimpleEntity { SomeProperty = "Some property" }; // Act entityRepository.Insert(simpleEntity); // Assert Assert.IsNotNull(entityRepository.DbContext); Assert.AreEqual(1, entityRepository.DbContext.ChangeTracker.Entries().Count()); Assert.AreEqual(EntityState.Added, entityRepository.DbContext.ChangeTracker.Entries().ToList()[0].State); }