public async Task TestSaveChangesAsync_CheckConcurrency_MutlipleEntitiesWithEqualIds() { using (ShimsContext.Create()) { var exceptionCaught = false; var concurrentEntity1 = new ConcurrentEntity { Id = 1, }; var concurrentEntity2 = new ConcurrentEntity { Id = 1, }; var shimEntry1 = new System.Data.Entity.Infrastructure.Fakes.ShimDbEntityEntry { EntityGet = () => { return(concurrentEntity1); } }; var shimEntry2 = new System.Data.Entity.Infrastructure.Fakes.ShimDbEntityEntry { EntityGet = () => { return(concurrentEntity2); } }; try { System.Data.Entity.Infrastructure.Fakes.ShimDbUpdateException.AllInstances.EntriesGet = (exc) => { var list = new List <DbEntityEntry> { shimEntry1, shimEntry2 }; return(list); }; System.Data.Entity.Fakes.ShimDbContext.AllInstances.SaveChangesAsync = (c) => { throw new DbUpdateConcurrencyException(); }; var service = new DbContextService <ConcurrentDbContext>(new ConcurrentDbContext()); await service.SaveChangesAsync(); } catch (NotSupportedException e) { exceptionCaught = true; } Assert.IsTrue(exceptionCaught); } }
public async Task TestSaveChangesAsync_CheckConcurrency() { using (ShimsContext.Create()) { var exceptionCaught = false; var concurrentEntity = new ConcurrentEntity { Id = 1, }; var shimEntry = new System.Data.Entity.Infrastructure.Fakes.ShimDbEntityEntry { EntityGet = () => { return(concurrentEntity); } }; try { System.Data.Entity.Infrastructure.Fakes.ShimDbUpdateException.AllInstances.EntriesGet = (exc) => { var list = new List <DbEntityEntry> { shimEntry }; return(list); }; System.Data.Entity.Fakes.ShimDbContext.AllInstances.SaveChangesAsync = (c) => { throw new DbUpdateConcurrencyException(); }; var service = new DbContextService <ConcurrentDbContext>(new ConcurrentDbContext()); await service.SaveChangesAsync(); } catch (EcaDbUpdateConcurrencyException e) { exceptionCaught = true; var entries = e.Entries; Assert.AreEqual(1, entries.Count()); Assert.AreEqual(1, e.ConcurrentEntities.Count()); Assert.IsTrue(Object.ReferenceEquals(concurrentEntity, e.ConcurrentEntities.First())); } Assert.IsTrue(exceptionCaught); } }