public async Task TestAddOrUpdateAll() { Assert.AreEqual(1, batchSize); var instance1 = new SimpleEntity(); var instance2 = new SimpleEntity(); context.SimpleEntities.Add(instance1); context.SimpleEntities.Add(instance2); var totalCount = context.SimpleEntities.Count(); var counter = 0; var counterAsync = 0; Action <List <SimpleEntity> > documentsToAddOrUpdateCallback = (docs) => { Assert.AreEqual(1, docs.Count); Assert.IsTrue(Object.ReferenceEquals(docs.First(), context.SimpleEntities.ToList()[counter])); counter++; }; Action <List <SimpleEntity> > documentsToAddOrUpdateAsyncCallback = (docs) => { Assert.AreEqual(1, docs.Count); Assert.IsTrue(Object.ReferenceEquals(docs.First(), context.SimpleEntities.ToList()[counterAsync])); counterAsync++; }; indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()) .Returns(new SimpleEntityConfiguration()); indexService.Setup(x => x.AddOrUpdate <SimpleEntity>(It.IsAny <List <SimpleEntity> >())) .Callback(documentsToAddOrUpdateCallback); indexService.Setup(x => x.AddOrUpdateAsync <SimpleEntity>(It.IsAny <List <SimpleEntity> >())) .ReturnsAsync(new DocumentIndexResponse()) .Callback(documentsToAddOrUpdateAsyncCallback); service.AddOrUpdateAll(); await service.AddOrUpdateAllAsync(); notificationService.Verify(x => x.StartedProcessingAllDocuments(It.IsAny <string>()), Times.Exactly(2)); notificationService.Verify(x => x.ProcessedSomeOfAllDocuments(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(4)); notificationService.Verify(x => x.ProcessAllDocumentsFinished(It.IsAny <string>()), Times.Exactly(2)); indexService.Verify(x => x.CreateIndex <SimpleEntity>(), Times.Once()); indexService.Verify(x => x.CreateIndexAsync <SimpleEntity>(), Times.Once()); }
public void TestGetDocumentEntities_NoEntitiesOfState() { using (ShimsContext.Create()) { var entity = new SimpleEntity { Id = 1, }; System.Data.Entity.Infrastructure.Fakes.ShimDbChangeTracker.AllInstances.Entries = (tracker) => { var entries = new List <DbEntityEntry>(); entries.Add(new System.Data.Entity.Infrastructure.Fakes.ShimDbEntityEntry { EntityGet = () => entity, StateGet = () => EntityState.Modified }); return(entries); }; var entities = saveAction.GetDocumentEntities(context, EntityState.Added); Assert.AreEqual(0, entities.Count); } }
public void TestBeforeSaveChanges() { using (ShimsContext.Create()) { var entity = new SimpleEntity { Id = 1, }; System.Data.Entity.Infrastructure.Fakes.ShimDbChangeTracker.AllInstances.Entries = (tracker) => { var entries = new List <DbEntityEntry>(); entries.Add(new System.Data.Entity.Infrastructure.Fakes.ShimDbEntityEntry { EntityGet = () => entity, StateGet = () => EntityState.Added }); return(entries); }; context.SimpleEntities.Add(entity); saveAction.BeforeSaveChanges((DbContext)context); Assert.AreEqual(1, saveAction.CreatedEntities.Count); Assert.IsTrue(Object.ReferenceEquals(entity, saveAction.CreatedEntities.First())); } }
public void TestGetDeletedDocumentEntities_EntitiesExcluded() { using (ShimsContext.Create()) { var entity = new SimpleEntity { Id = 1, }; saveAction.IsDeletedEntityActuallyExcluded = true; System.Data.Entity.Infrastructure.Fakes.ShimDbChangeTracker.AllInstances.Entries = (tracker) => { var entries = new List <DbEntityEntry>(); entries.Add(new System.Data.Entity.Infrastructure.Fakes.ShimDbEntityEntry { EntityGet = () => entity, StateGet = () => EntityState.Deleted }); return(entries); }; context.SimpleEntities.Add(entity); var entities = saveAction.GetDeletedDocumentEntities(context); Assert.AreEqual(0, entities.Count); } }