示例#1
0
        public async Task <bool> RestoreDataWithAuditingWhenDoesNotExistButIndexingFails()
        {
            MockDataStream
            .SetupSequence(x => x.Exists <AuditedEntity>(ExpectedAuditedEntity.Id))
            .ReturnsAsync(false)
            .ReturnsAsync(true);
            MockDataStream
            .Setup(x => x.Undelete <AuditedEntity>(ExpectedAuditedEntity.Id))
            .ReturnsAsync(true);
            MockAudit
            .Setup(x => x.UndeleteEvent(ExpectedAuditedEntity))
            .ReturnsAsync(true);
            MockAudit
            .Setup(x => x.CommitEvents(ExpectedAuditedEntity))
            .ReturnsAsync(true);
            MockIndexer
            .Setup(x => x.Index(ExpectedAuditedEntity))
            .ReturnsAsync(false);
            var result = await DataManager.Restore <AuditedEntity>(ExpectedAuditedEntity.Id);

            MockAudit
            .Verify(x => x.RollbackEvent(ExpectedAuditedEntity), Times.Once);
            MockDataStream
            .Verify(x => x.Delete <AuditedEntity>(ExpectedAuditedEntity.Id), Times.Once);
            return(result);
        }
示例#2
0
 public async Task <bool> DeleteDataUnindexFails()
 {
     MockIndexer
     .Setup(x => x.Unindex(ExpectedBasicEntity1))
     .ReturnsAsync(false);
     return(await DataManager.Delete <BasicEntity>(ExpectedBasicEntity1.Id));
 }
示例#3
0
        public async Task ReadKeysWhenIndexDoesNotExist()
        {
            MockIndexer.Setup(x => x.IndexExist <IndexedEntity>("IndexedValue")).ReturnsAsync(false);
            var data   = DataManager.ReadIndexKeys <IndexedEntity, string>(x => x.IndexedValue);
            var result = new List <IndexKey <string> >();

            await foreach (var d in data)
            {
                result.Add(d);
            }
            Assert.IsEmpty(result);
        }
示例#4
0
        public async Task <bool> DeleteDataWithAuditUnindexFails()
        {
            MockIndexer
            .Setup(x => x.Unindex(ExpectedAuditedEntity))
            .ReturnsAsync(false);
            var result = await DataManager.Delete <AuditedEntity>(ExpectedAuditedEntity.Id);

            MockDataStream
            .Verify(x => x.Rollback(ExpectedAuditedEntity.Id, ExpectedAuditedEntity), Times.Once);
            MockAudit
            .Verify(x => x.RollbackEvent(ExpectedAuditedEntity), Times.Once);
            return(result);
        }
示例#5
0
        public async Task ReadKeysWhenIndexHasNoValue()
        {
            MockIndexer
            .Setup(
                x => x.GetKeysFromIndex <IndexedEntity, string>("IndexedValue"))
            .Returns(EmptyIndexKeysEntityList);
            var data    = DataManager.ReadIndexKeys <IndexedEntity, string>(x => x.IndexedValue);
            var results = new List <IndexKey <string> >();

            await foreach (var d in data)
            {
                results.Add(d);
            }
            Assert.IsFalse(results.Any());
        }
示例#6
0
        public async Task ReadWhenIndexHasAValueButThereNoData()
        {
            MockIndexer
            .Setup(
                x => x.GetIdsFromIndex <IndexedEntity, string>("IndexedValue", ExpectedIndexedEntity.IndexedValue))
            .Returns(RandomIndexEntityList);
            var data = DataManager.ReadIndex <IndexedEntity, string>(ExpectedIndexedEntity.IndexedValue,
                                                                     x => x.IndexedValue);
            var results = new List <IndexedEntity>();

            await foreach (var d in data)
            {
                results.Add(d);
            }
            Assert.IsFalse(results.Any(x => x != null));
        }
示例#7
0
        public async Task <bool> WriteDataWithAuditWhenIndexingFails()
        {
            MockIndexer
            .Setup(x => x.Index(ExpectedAuditedEntity))
            .ReturnsAsync(false);
            var result = await DataManager.Write(ExpectedAuditedEntity);

            MockDataStream
            .Verify(x => x.Rollback(ExpectedAuditedEntity.Id, ExpectedAuditedEntity), Times.Once);
            MockIndexer
            .Verify(x => x.Index(ExpectedAuditedEntity), Times.Once);
            MockAudit
            .Verify(x => x.RollbackEvent(ExpectedAuditedEntity), Times.Once);
            MockAudit
            .Verify(x => x.CreationEvent(It.IsAny <DataEntity>()), Times.Never);
            return(result);
        }
示例#8
0
 public async Task <bool> RestoreDataWithAuditingWhenDoesNotExistAndRestoredSuccessfully()
 {
     MockDataStream
     .SetupSequence(x => x.Exists <AuditedEntity>(ExpectedAuditedEntity.Id))
     .ReturnsAsync(false)
     .ReturnsAsync(true);
     MockDataStream
     .Setup(x => x.Undelete <AuditedEntity>(ExpectedAuditedEntity.Id))
     .ReturnsAsync(true);
     MockAudit
     .Setup(x => x.UndeleteEvent(ExpectedAuditedEntity))
     .ReturnsAsync(true);
     MockAudit
     .Setup(x => x.CommitEvents(ExpectedAuditedEntity))
     .ReturnsAsync(true);
     MockIndexer
     .Setup(x => x.Index(ExpectedAuditedEntity))
     .ReturnsAsync(true);
     return(await DataManager.Restore <AuditedEntity>(ExpectedAuditedEntity.Id));
 }
示例#9
0
        public async Task <bool> WriteNewDataWithNoAuditIndexingFails()
        {
            MockDataStream
            .Setup(x => x.Read <IndexedEntity>(ExpectedIndexedEntity.Id))
            .ReturnsAsync((IndexedEntity)null);
            MockIndexer
            .Setup(x => x.Index(It.IsAny <DataEntity>()))
            .ReturnsAsync(false);
            var result = await DataManager.Write(ExpectedIndexedEntity);

            MockDataStream
            .Verify(x => x.Rollback(ExpectedIndexedEntity.Id, (DataEntity)null));
            MockAudit
            .Verify(x => x.CreationEvent(It.IsAny <DataEntity>()), Times.Never);
            MockAudit
            .Verify(x => x.UpdateEvent(It.IsAny <DataEntity>(), It.IsAny <DataEntity>()), Times.Never);
            MockAudit
            .Verify(x => x.CommitEvents(It.IsAny <DataEntity>()), Times.Never);
            return(result);
        }
示例#10
0
        public async Task <bool> RestoreDataWhenDoesNotExistRestoredSuccessfully()
        {
            MockDataStream
            .SetupSequence(x => x.Exists <BasicEntity>(ExpectedBasicEntity1.Id))
            .ReturnsAsync(false)
            .ReturnsAsync(true);
            MockDataStream
            .Setup(x => x.Undelete <BasicEntity>(ExpectedBasicEntity1.Id))
            .ReturnsAsync(true);
            MockAudit
            .Setup(x => x.UndeleteEvent(ExpectedBasicEntity1))
            .ReturnsAsync(true);
            MockIndexer
            .Setup(x => x.Index(ExpectedBasicEntity1))
            .ReturnsAsync(true);
            var result = await DataManager.Restore <BasicEntity>(ExpectedBasicEntity1.Id);

            MockDataStream
            .Verify(x => x.Delete <BasicEntity>(ExpectedBasicEntity1.Id), Times.Never);
            return(result);
        }