public void ShouldIdicateEmptyEvenIfSeveralEntitiesHaveAttached() { unitOfWork.Attach(SimpleEntity.CreateStandard(), markAsUnchanged: true); unitOfWork.Attach(Entity.CreateStandard(), markAsUnchanged: true); var bulkUpdateBatch = CreateBulkUpdateBatch(); Assert.False(unitOfWork.ApplyChanges(bulkUpdateBatch)); Assert.True(bulkUpdateBatch.IsEmpty); }
public void ShouldNotUpdateIfPersistedDocumentHaveNotChanged() { var entity = SimpleEntity.CreateStandard(); unitOfWork.Attach(entity, markAsUnchanged: true); var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); // Mock will throw on any call }
public void ShouldReturnCachedEntityByIdAndExactType() { var entity = SimpleEntity.CreateStandard(); unitOfWork.Attach(entity); object cachedEntity; Assert.True(unitOfWork.TryGetByEntityIdAndType(entity.Id, typeof(SimpleEntity), out cachedEntity)); Assert.Same(entity, cachedEntity); }
public void ShouldNotIndicateEmptyIfDelete() { var entity = SimpleEntity.CreateStandard(); unitOfWork.Attach(entity); unitOfWork.MarkAsRemoved(entity); var bulkUpdateBatch = CreateBulkUpdateBatch(); Assert.True(unitOfWork.ApplyChanges(bulkUpdateBatch)); Assert.False(bulkUpdateBatch.IsEmpty); }
public void ShouldNotUpdateEntitesUnderUser() { var entity = SimpleEntity.CreateStandard(); entity.Age = 43; unitOfWork.Attach(entity); unitOfWork.UpdateWithDocument(SimpleEntity.CreateDocument()); object cachedEntity; Assert.True(unitOfWork.TryGetByDocumentId(SimpleEntity.StandardDocId, out cachedEntity)); Assert.IsType <SimpleEntity>(cachedEntity); Assert.NotNull(cachedEntity); Assert.Equal(43, ((SimpleEntity)cachedEntity).Age); }
public void ShouldBeEmptyAfterUpdatingRevisionForDeletion() { var entity = SimpleEntity.CreateStandard(); unitOfWork.Attach(entity, markAsUnchanged: true); unitOfWork.MarkAsRemoved(entity); unitOfWork.ApplyChanges(CreateBulkUpdateBatch()); // Starting saving changes unitOfWork.UpdateRevisions( // Returned from server after changes have been saved new[] { new DocumentInfo(SimpleEntity.StandardDocId, "2-cc2c5ab22cfa4a0faad27a0cb9ca7968") }); var bulkUpdateBatch = CreateBulkUpdateBatch(); Assert.False(unitOfWork.ApplyChanges(bulkUpdateBatch)); Assert.True(bulkUpdateBatch.IsEmpty); }
public void ShouldNotCallCreateOrUpdateIfDocumentEntityHaveDeleted() { var persistedEntity = SimpleEntity.CreateStandard(); unitOfWork.Attach(persistedEntity); var trancientEntity = SimpleEntity.CreateStandardWithoutRevision(); unitOfWork.AddNew(trancientEntity); unitOfWork.MarkAsRemoved(trancientEntity); unitOfWork.MarkAsRemoved(persistedEntity); var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Delete(It.IsAny <string>(), It.IsAny <string>())).Callback <string, string>((id, rev) => { }); //Should throw if methods other than Delete() have been called unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); }
public void ShouldDeleteDocumentOnlyOnce() { var entity = SimpleEntity.CreateStandard(); unitOfWork.MarkAsRemoved(entity); unitOfWork.MarkAsRemoved(entity); int callTimes = 0; var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Delete(It.IsAny <string>(), It.IsAny <string>())) .Callback <string, string>( (id, rev) => { callTimes++; }); unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); Assert.Equal(1, callTimes); }
public void ShouldDeleteEntitiesDocument() { unitOfWork.MarkAsRemoved(SimpleEntity.CreateStandard()); string deletedDocId = null; string deletedDocRevision = null; var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Delete(It.IsAny <string>(), It.IsAny <string>())) .Callback <string, string>( (id, rev) => { deletedDocId = id; deletedDocRevision = rev; }); unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); Assert.Equal(SimpleEntity.StandardDocId, deletedDocId); Assert.Equal(SimpleEntity.StandardRevision, deletedDocRevision); }
public void ShouldUpdatePersistedDocumens() { var entity = SimpleEntity.CreateStandard(); entity.Age = 24; unitOfWork.Attach(entity); Document savedDoc = null; var bulkUpdateUnitOfWorkMock = new Mock <IBulkUpdateBatch>(MockBehavior.Strict); bulkUpdateUnitOfWorkMock .Setup(u => u.Update(It.IsAny <Document>())) .Callback <Document>(d => { savedDoc = d; }); unitOfWork.ApplyChanges(bulkUpdateUnitOfWorkMock.Object); Assert.NotNull(savedDoc); var expectedDoc = new { _id = SimpleEntity.StandardDocId, _rev = SimpleEntity.StandardRevision, type = SimpleEntity.DocType, age = 24 }.ToDocument(); Assert.Equal(expectedDoc, savedDoc); }
public void ShouldThrowIfPersistedDocumentEntityAddedAsNew() { Assert.Throws <ArgumentException>(() => unitOfWork.AddNew(SimpleEntity.CreateStandard())); }