public void RunInExpectedTime() { // Arrange. DbContextMock dbContext = new DbContextMock(); PersonDataEntityMock[] entities = new PersonDataEntityMock[] { new PersonDataEntityMock() { Id = 1}, new PersonDataEntityMock() { Id = 2}, new PersonDataEntityMock() { Id = 3}, new PersonDataEntityMock() { Id = 4}, new PersonDataEntityMock() { Id = 5}, }; dbContext.Entry(entities[0]).State = EntityState.Detached; dbContext.Entry(entities[1]).State = EntityState.Unchanged; dbContext.Entry(entities[2]).State = EntityState.Added; dbContext.Entry(entities[3]).State = EntityState.Deleted; dbContext.Entry(entities[4]).State = EntityState.Modified; // Act & Assert. Ensure.ActionRunsInExpectedTime( () => { dbContext.DetachAll(); }, ExecutionTimeType.Normal); }
public void DetachAllTrackedEntities_WhenDbContextArgumentIsValid() { // Arrange. DbContextMock dbContext = new DbContextMock(); PersonDataEntityMock[] entities = new PersonDataEntityMock[] { new PersonDataEntityMock() { Id = 1}, new PersonDataEntityMock() { Id = 2}, new PersonDataEntityMock() { Id = 3}, new PersonDataEntityMock() { Id = 4}, new PersonDataEntityMock() { Id = 5}, }; dbContext.Entry(entities[0]).State = EntityState.Detached; dbContext.Entry(entities[1]).State = EntityState.Unchanged; dbContext.Entry(entities[2]).State = EntityState.Added; dbContext.Entry(entities[3]).State = EntityState.Deleted; dbContext.Entry(entities[4]).State = EntityState.Modified; // Act. dbContext.DetachAll(); // Assert. foreach (PersonDataEntityMock entity in entities) { Assert.AreEqual(EntityState.Detached, dbContext.Entry(entity).State); } }
public void ThrowArgumentException_WhenEntityStateIsModified() { // Arrange. DbContextMock dbContext = new DbContextMock(); PersonDataEntityMock entity = new PersonDataEntityMock(); dbContext.Entry(entity).State = EntityState.Modified; // Act & Assert. Ensure.ArgumentExceptionIsThrown(() => { dbContext.ThrowIfAttached(entity); }, "entity"); }
public void ReturnTrue_WhenEntityStateIsModified() { // Arrange. DbContextMock dbContext = new DbContextMock(); PersonDataEntityMock entity = new PersonDataEntityMock(); dbContext.Entry(entity).State = EntityState.Modified; // Act. bool result = dbContext.IsAttached(entity); // Assert. Assert.IsTrue(result); }
public void DoNotThrowException_WhenEntityStateIsDetached() { // Arrange. DbContextMock dbContext = new DbContextMock(); PersonDataEntityMock entity = new PersonDataEntityMock(); dbContext.Entry(entity).State = EntityState.Detached; // Act & Assert. Ensure.NoExceptionIsThrown(() => { dbContext.ThrowIfAttached(entity); }); }
public void RunInExpectedTime() { // Arrange. DbContextMock dbContext = new DbContextMock(); PersonDataEntityMock entity = new PersonDataEntityMock(); dbContext.Entry(entity).State = EntityState.Detached; // Act & Assert. Ensure.ActionRunsInExpectedTime( () => { dbContext.ThrowIfAttached(entity); }, ExecutionTimeType.Normal); }