Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
 public void ShouldThrowIfPersistedDocumentEntityAddedAsNew()
 {
     Assert.Throws <ArgumentException>(() => unitOfWork.AddNew(SimpleEntity.CreateStandard()));
 }