示例#1
0
        public async Task WhenExecutingFullStateActionsThenFlowCompletesSuccesfully()
        {
            Dictionary <string, string>       repository = new Dictionary <string, string>();
            Mock <ICloudBlobContainerWrapper> cloudBlobContainerWrapperMock = new Mock <ICloudBlobContainerWrapper>();

            cloudBlobContainerWrapperMock
            .Setup(m => m.UploadBlobAsync(It.IsAny <string>(), It.IsAny <string>(), CancellationToken.None))
            .Returns <string, string, CancellationToken>((blobName, blobContent, token) => { repository[blobName] = blobContent; return(Task.FromResult <ICloudBlob>(null)); });
            cloudBlobContainerWrapperMock
            .Setup(m => m.DownloadBlobContentAsync(It.IsAny <string>(), CancellationToken.None))
            .Returns <string, CancellationToken>((blobName, token) =>
            {
                if (repository.ContainsKey(blobName))
                {
                    return(Task.FromResult <string>(repository[blobName]));
                }
                else
                {
                    StorageException ex = new StorageException(new RequestResult(), string.Empty, null);
                    ex.RequestInformation.HttpStatusCode = (int)HttpStatusCode.NotFound;
                    throw ex;
                }
            });
            cloudBlobContainerWrapperMock
            .Setup(m => m.DeleteBlobIfExistsAsync(It.IsAny <string>(), CancellationToken.None))
            .Returns <string, CancellationToken>((blobName, token) => { repository.Remove(blobName); return(Task.CompletedTask); });

            ICloudStorageProviderFactory cloudStorageProviderFactoryMock = Mock.Of <ICloudStorageProviderFactory>(m => m.GetSmartDetectorStateStorageContainer() == cloudBlobContainerWrapperMock.Object);

            BlobStateRepository blobStateRepository = new BlobStateRepository("TestSignal", cloudStorageProviderFactoryMock, (new Mock <ITracer>()).Object);

            await TestFullFlow(blobStateRepository);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BlobStateRepository"/> class
        /// </summary>
        /// <param name="smartDetectorId">The id of the Smart Detector</param>
        /// <param name="cloudStorageProviderFactory">The cloud storage provider factory</param>
        /// <param name="tracer">The tracer</param>
        public BlobStateRepository(string smartDetectorId, ICloudStorageProviderFactory cloudStorageProviderFactory, ITracer tracer)
        {
            Diagnostics.EnsureArgumentNotNull(() => smartDetectorId);

            this.smartDetectorId           = smartDetectorId;
            this.cloudBlobContainerWrapper = cloudStorageProviderFactory.GetSmartDetectorStateStorageContainer();
            this.tracer = tracer;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the<see cref="AlertRuleStore"/> class.
        /// </summary>
        /// <param name="storageProviderFactory">The Azure Storage provider factory</param>
        /// <param name="tracer">Log wrapper</param>
        public AlertRuleStore(ICloudStorageProviderFactory storageProviderFactory, ITracer tracer)
        {
            this.tracer = tracer;

            // create the cloud table instance
            ICloudTableClientWrapper tableClient = storageProviderFactory.GetSmartDetectorStorageTableClient();

            this.alertRulesTable = tableClient.GetTableReference(TableName);
            this.alertRulesTable.CreateIfNotExists();
        }
        /// <summary>
        /// Initializes a new instance of the<see cref="SignalRunsTracker"/> class.
        /// </summary>
        /// <param name="storageProviderFactory">The Azure Storage provider factory</param>
        /// <param name="tracer">Log wrapper</param>
        public SignalRunsTracker(ICloudStorageProviderFactory storageProviderFactory, ITracer tracer)
        {
            this.tracer = tracer;

            // create the cloud table instance
            ICloudTableClientWrapper tableClient = storageProviderFactory.GetSmartSignalStorageTableClient();

            this.trackingTable = tableClient.GetTableReference(TableName);
            this.trackingTable.CreateIfNotExists();
        }
示例#5
0
        public async Task WhenStorageIsBrokenThenAnAppropriateExceptionIsThrownOnGetState()
        {
            Mock <ICloudBlobContainerWrapper> cloudBlobContainerWrapperMock = new Mock <ICloudBlobContainerWrapper>();

            cloudBlobContainerWrapperMock
            .Setup(m => m.DownloadBlobContentAsync(It.IsAny <string>(), CancellationToken.None))
            .Returns(() => throw new StorageException(new RequestResult(), string.Empty, null));

            ICloudStorageProviderFactory cloudStorageProviderFactoryMock = Mock.Of <ICloudStorageProviderFactory>(m => m.GetSmartDetectorStateStorageContainer() == cloudBlobContainerWrapperMock.Object);

            BlobStateRepository blobStateRepository = new BlobStateRepository("TestSignal", cloudStorageProviderFactoryMock, (new Mock <ITracer>()).Object);

            await blobStateRepository.GetStateAsync <TestState>("key", CancellationToken.None);
        }
示例#6
0
        public async Task WhenExecutingBasicStateActionsThenFlowCompletesSuccesfully()
        {
            Dictionary <string, string>       repository = new Dictionary <string, string>();
            Mock <ICloudBlobContainerWrapper> cloudBlobContainerWrapperMock = new Mock <ICloudBlobContainerWrapper>();

            cloudBlobContainerWrapperMock
            .Setup(m => m.UploadBlobAsync(It.IsAny <string>(), It.IsAny <string>(), CancellationToken.None))
            .Returns <string, string, CancellationToken>((blobName, blobContent, token) => { repository[blobName] = blobContent; return(Task.FromResult <ICloudBlob>(null)); });
            cloudBlobContainerWrapperMock
            .Setup(m => m.DownloadBlobContentAsync(It.IsAny <string>(), CancellationToken.None))
            .Returns <string, CancellationToken>((blobName, token) =>
            {
                if (repository.ContainsKey(blobName))
                {
                    return(Task.FromResult <string>(repository[blobName]));
                }
                else
                {
                    StorageException ex = new StorageException(new RequestResult(), string.Empty, null);
                    ex.RequestInformation.HttpStatusCode = (int)HttpStatusCode.NotFound;
                    throw ex;
                }
            });
            cloudBlobContainerWrapperMock
            .Setup(m => m.DeleteBlobIfExistsAsync(It.IsAny <string>(), CancellationToken.None))
            .Returns <string, CancellationToken>((blobName, token) => { repository.Remove(blobName); return(Task.CompletedTask); });

            ICloudStorageProviderFactory cloudStorageProviderFactoryMock = Mock.Of <ICloudStorageProviderFactory>(m => m.GetSmartDetectorStateStorageContainer() == cloudBlobContainerWrapperMock.Object);

            BlobStateRepository blobStateRepository = new BlobStateRepository("TestSignal", cloudStorageProviderFactoryMock, (new Mock <ITracer>()).Object);

            var originalState = new TestState
            {
                Field1 = "testdata",
                Field2 = new List <DateTime> {
                    new DateTime(2018, 02, 15)
                },
                Field3 = true
            };

            await blobStateRepository.StoreStateAsync("key", originalState, CancellationToken.None);

            var retrievedState = await blobStateRepository.GetStateAsync <TestState>("key", CancellationToken.None);

            // validate
            Assert.AreEqual(originalState.Field1, retrievedState.Field1);
            CollectionAssert.AreEquivalent(originalState.Field2, retrievedState.Field2);
            Assert.AreEqual(originalState.Field3, retrievedState.Field3);
            Assert.AreEqual(originalState.Field4, retrievedState.Field4);
        }
示例#7
0
        public async Task WhenStateIsUnserializableThenAnAppropriateExceptionIsThrownOnStoreState()
        {
            Mock <ICloudBlobContainerWrapper> cloudBlobContainerWrapperMock = new Mock <ICloudBlobContainerWrapper>();

            ICloudStorageProviderFactory cloudStorageProviderFactoryMock = Mock.Of <ICloudStorageProviderFactory>(m => m.GetSmartDetectorStateStorageContainer() == cloudBlobContainerWrapperMock.Object);

            BlobStateRepository blobStateRepository = new BlobStateRepository("TestSignal", cloudStorageProviderFactoryMock, (new Mock <ITracer>()).Object);

            var state = new UnserializableState
            {
                Property = "Hello"
            };

            await blobStateRepository.StoreStateAsync("key", state, CancellationToken.None);
        }
示例#8
0
        public async Task WhenExecutingFullStateActionsThenFlowCompletesSuccesfullyWithRealStorage()
        {
            var                storageConnectionString = "****";
            CloudBlobClient    cloudBlobClient         = CloudStorageAccount.Parse(storageConnectionString).CreateCloudBlobClient();
            CloudBlobContainer cloudBlobContainer      = cloudBlobClient.GetContainerReference("tessignalstatecontainer");
            await cloudBlobContainer.CreateIfNotExistsAsync();

            CloudBlobContainerWrapper cloudBlobContainerWrapper = new CloudBlobContainerWrapper(cloudBlobContainer);

            ICloudStorageProviderFactory cloudStorageProviderFactoryMock = Mock.Of <ICloudStorageProviderFactory>(m => m.GetSmartDetectorStateStorageContainer() == cloudBlobContainerWrapper);

            BlobStateRepository blobStateRepository = new BlobStateRepository("TestSignal", cloudStorageProviderFactoryMock, (new Mock <ITracer>()).Object);

            await TestFullFlow(blobStateRepository);

            // delete all remaining blobs
            foreach (var blob in cloudBlobContainer.ListBlobs(useFlatBlobListing: true))
            {
                var blockblob = blob as CloudBlockBlob;
                await blockblob?.DeleteIfExistsAsync();
            }
        }
示例#9
0
        public async Task WhenStorageIsBrokenThenAnAppropriateExceptionIsThrownOnDeleteState()
        {
            Mock <ICloudBlobContainerWrapper> cloudBlobContainerWrapperMock = new Mock <ICloudBlobContainerWrapper>();

            cloudBlobContainerWrapperMock
            .Setup(m => m.DeleteBlobIfExistsAsync(It.IsAny <string>(), CancellationToken.None))
            .Returns(() => throw new StorageException(new RequestResult(), string.Empty, null));

            ICloudStorageProviderFactory cloudStorageProviderFactoryMock = Mock.Of <ICloudStorageProviderFactory>(m => m.GetSmartDetectorStateStorageContainer() == cloudBlobContainerWrapperMock.Object);

            BlobStateRepository blobStateRepository = new BlobStateRepository("TestSignal", cloudStorageProviderFactoryMock, (new Mock <ITracer>()).Object);

            var state = new TestState
            {
                Field1 = "testdata",
                Field2 = new List <DateTime> {
                    new DateTime(2018, 02, 15)
                },
                Field3 = true
            };

            await blobStateRepository.DeleteStateAsync("key", CancellationToken.None);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BlobStateRepositoryFactory"/> class
 /// </summary>
 /// <param name="cloudStorageProviderFactory">The cloud storage provider factory</param>
 /// <param name="tracer">The tracer</param>
 public BlobStateRepositoryFactory(ICloudStorageProviderFactory cloudStorageProviderFactory, IExtendedTracer tracer)
 {
     this.cloudStorageProviderFactory = Diagnostics.EnsureArgumentNotNull(() => cloudStorageProviderFactory);
     this.tracer = tracer;
 }
 public BlobStateRepository(string smartDetectorId, string alertRuleResourceId, ICloudStorageProviderFactory cloudStorageProviderFactory, ITracer tracer)
 {
     this.smartDetectorId           = Diagnostics.EnsureStringNotNullOrWhiteSpace(() => smartDetectorId);
     this.alertRuleResourceId       = Diagnostics.EnsureStringNotNullOrWhiteSpace(() => alertRuleResourceId).ToLowerInvariant();
     this.cloudBlobContainerWrapper = cloudStorageProviderFactory.GetSmartDetectorStateStorageContainerAsync().Result;
     this.tracer = tracer;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SmartDetectorRepository"/> class.
 /// </summary>
 /// <param name="tracer">Log wrapper</param>
 /// <param name="storageProviderFactory">The Azure storage provider factory</param>
 public SmartDetectorRepository(IExtendedTracer tracer, ICloudStorageProviderFactory storageProviderFactory)
 {
     this.tracer          = Diagnostics.EnsureArgumentNotNull(() => tracer);
     this.containerClient = storageProviderFactory.GetSmartDetectorGlobalStorageContainer();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SmartSignalResultPublisher"/> class.
 /// </summary>
 /// <param name="tracer">The tracer to use.</param>
 /// <param name="storageProviderFactory">The Azure storage provider factory.</param>
 public SmartSignalResultPublisher(ITracer tracer, ICloudStorageProviderFactory storageProviderFactory)
 {
     this.tracer          = Diagnostics.EnsureArgumentNotNull(() => tracer);
     this.containerClient = storageProviderFactory.GetSmartSignalResultStorageContainer();
 }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SignalResultApi"/> class.
 /// </summary>
 /// <param name="storageProviderFactory">The storage provider factory.</param>
 /// <param name="applicationInsightsClientFactory">The application insights client factory.</param>
 public SignalResultApi(ICloudStorageProviderFactory storageProviderFactory, IApplicationInsightsClientFactory applicationInsightsClientFactory)
 {
     this.signalResultStorageContainer = storageProviderFactory.GetSmartSignalResultStorageContainer();
     this.applicationInsightsClient    = applicationInsightsClientFactory.GetApplicationInsightsClient();
 }