Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task <bool> DeleteDataWithAuditWhenItDoesNotExist()
        {
            MockDataStream
            .Setup(x => x.Exists <AuditedEntity>(ExpectedAuditedEntity.Id))
            .ReturnsAsync(false);
            var result = await DataManager.Delete <AuditedEntity>(ExpectedAuditedEntity.Id);

            MockAudit
            .Verify(x => x.DeleteEvent(ExpectedAuditedEntity), Times.Never);
            MockDataStream
            .Verify(x => x.Delete <AuditedEntity>(It.IsAny <int>()), Times.Never);
            return(result);
        }
Ejemplo n.º 4
0
        public async Task <bool> DeleteDataWithAuditDeleteFails()
        {
            MockDataStream
            .Setup(x => x.Delete <AuditedEntity>(ExpectedAuditedEntity.Id))
            .ReturnsAsync(false);
            var result = await DataManager.Delete <AuditedEntity>(ExpectedAuditedEntity.Id);

            MockAudit
            .Verify(x => x.CommitEvents(ExpectedAuditedEntity), Times.Never);
            MockAudit
            .Verify(x => x.DiscardEvents(ExpectedAuditedEntity), Times.Once);
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <bool> WriteDataWithNoAuditButIndexSuccess()
        {
            var result = await DataManager.Write(ExpectedIndexedEntity);

            MockDataStream
            .Verify(x => x.Rollback(It.IsAny <int>(), It.IsAny <DataEntity>()), Times.Never);
            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);
        }
Ejemplo n.º 6
0
        public async Task <bool> WriteDataWithAuditWhenIndexingSuccess()
        {
            var result = await DataManager.Write(ExpectedAuditedEntity);

            MockDataStream
            .Verify(x => x.Rollback(ExpectedAuditedEntity.Id, ExpectedAuditedEntity), Times.Never);
            MockIndexer
            .Verify(x => x.Index(ExpectedAuditedEntity), Times.Once);
            MockAudit
            .Verify(x => x.RollbackEvent(ExpectedAuditedEntity), Times.Never);
            MockAudit
            .Verify(x => x.CreationEvent(It.IsAny <DataEntity>()), Times.Never);
            return(result);
        }
Ejemplo n.º 7
0
        public async Task <bool> WriteDataWithAuditWhenAuditCommitFails()
        {
            MockAudit
            .Setup(x => x.CommitEvents(ExpectedAuditedEntity))
            .ReturnsAsync(false);
            var result = await DataManager.Write(ExpectedAuditedEntity);

            MockDataStream
            .Verify(x => x.Rollback(ExpectedAuditedEntity.Id, ExpectedAuditedEntity), Times.Once);
            MockIndexer
            .Verify(x => x.Index(It.IsAny <DataEntity>()), Times.Never);
            MockAudit
            .Verify(x => x.CreationEvent(It.IsAny <DataEntity>()), Times.Never);
            return(result);
        }
Ejemplo n.º 8
0
        public async Task <bool> WriteNewDataWithAuditWhenIndexingSuccess()
        {
            MockDataStream
            .Setup(x => x.Exists <AuditedEntity>(ExpectedAuditedEntity.Id))
            .ReturnsAsync(false);
            var result = await DataManager.Write(ExpectedAuditedEntity);

            MockDataStream
            .Verify(x => x.Rollback(ExpectedAuditedEntity.Id, (DataEntity)null), Times.Never);
            MockIndexer
            .Verify(x => x.Index(ExpectedAuditedEntity), Times.Once);
            MockAudit
            .Verify(x => x.RollbackEvent(ExpectedAuditedEntity), Times.Never);
            MockAudit
            .Verify(x => x.UpdateEvent(It.IsAny <DataEntity>(), It.IsAny <DataEntity>()), Times.Never);
            return(result);
        }
Ejemplo n.º 9
0
        public async Task <bool> WriteDataWithNoAuditFails()
        {
            MockDataStream
            .Setup(x => x.WriteAndCommit(It.IsAny <int>(), It.IsAny <DataEntity>()))
            .ReturnsAsync(false);
            var result = await DataManager.Write(ExpectedBasicEntity1);

            MockDataStream
            .Verify(x => x.Rollback(It.IsAny <int>(), It.IsAny <DataEntity>()), Times.Never);
            MockIndexer
            .Verify(x => x.Index(It.IsAny <DataEntity>()), Times.Never);
            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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public async Task <bool> WriteDataWithAuditUpdateEventFails()
        {
            MockAudit
            .Setup(x => x.UpdateEvent(ExpectedAuditedEntity, ExpectedAuditedEntity))
            .ReturnsAsync(false);
            var result = await DataManager.Write(ExpectedAuditedEntity);

            MockDataStream
            .Verify(x => x.DiscardChanges <BasicEntity>(ExpectedAuditedEntity.Id));
            MockDataStream
            .Verify(x => x.Commit <BasicEntity>(It.IsAny <int>()), Times.Never);
            MockDataStream
            .Verify(x => x.Rollback(It.IsAny <int>(), It.IsAny <DataEntity>()), Times.Never);
            MockIndexer
            .Verify(x => x.Index(It.IsAny <DataEntity>()), Times.Never);
            MockAudit
            .Verify(x => x.CreationEvent(It.IsAny <DataEntity>()), Times.Never);
            MockAudit
            .Verify(x => x.CommitEvents(It.IsAny <DataEntity>()), Times.Never);
            return(result);
        }