Example #1
0
        public async Task GetCurrent_WithMissingMetadata_ReturnsExpectedTimestamp()
        {
            var primaryHostMock = new Mock <IPrimaryHostStateProvider>();

            primaryHostMock.Setup(p => p.IsPrimary).Returns(true);

            CloudBlockBlob analysisBlob = await GetAnalysisBlobReference(_hostIdProvider);

            await analysisBlob.DeleteIfExistsAsync();

            await analysisBlob.UploadTextAsync(string.Empty);

            var stateProvider = new BlobChangeAnalysisStateProvider(_configuration, _hostIdProvider, NullLogger <BlobChangeAnalysisStateProvider> .Instance);

            ChangeAnalysisState result = await stateProvider.GetCurrentAsync(CancellationToken.None);

            Assert.Equal(DateTimeOffset.MinValue, result.LastAnalysisTime);
        }
Example #2
0
        public async Task SetTimestamp_PersistsMetadata()
        {
            DateTimeOffset lastAnalysisTestTime = DateTimeOffset.UtcNow;

            var primaryHostMock = new Mock <IPrimaryHostStateProvider>();

            primaryHostMock.Setup(p => p.IsPrimary).Returns(true);

            ICloudBlob analysisBlob = await GetAnalysisBlobReference(_hostIdProvider);

            var stateProvider = new BlobChangeAnalysisStateProvider(_configuration, _hostIdProvider, NullLogger <BlobChangeAnalysisStateProvider> .Instance);

            await stateProvider.SetTimestampAsync(lastAnalysisTestTime, analysisBlob, CancellationToken.None);

            analysisBlob = await analysisBlob.ServiceClient.GetBlobReferenceFromServerAsync(analysisBlob.Uri);

            DateTimeOffset.TryParse(analysisBlob.Metadata[BlobChangeAnalysisStateProvider.AnalysisTimestampMetadataName], out DateTimeOffset result);

            Assert.Equal(lastAnalysisTestTime, result);
        }
Example #3
0
        public async Task GetCurrent_ReadsTimestamp()
        {
            DateTimeOffset lastAnalysisTestTime = DateTimeOffset.UtcNow;

            var primaryHostMock = new Mock <IPrimaryHostStateProvider>();

            primaryHostMock.Setup(p => p.IsPrimary).Returns(true);

            CloudBlockBlob analysisBlob = await GetAnalysisBlobReference(_hostIdProvider);

            await analysisBlob.UploadTextAsync(string.Empty);

            analysisBlob.Metadata.Add(BlobChangeAnalysisStateProvider.AnalysisTimestampMetadataName, lastAnalysisTestTime.ToString("O"));
            await analysisBlob.SetMetadataAsync();

            var stateProvider = new BlobChangeAnalysisStateProvider(_configuration, _hostIdProvider, NullLogger <BlobChangeAnalysisStateProvider> .Instance);

            ChangeAnalysisState result = await stateProvider.GetCurrentAsync(CancellationToken.None);

            Assert.Equal(lastAnalysisTestTime, result.LastAnalysisTime);
        }
Example #4
0
        public async Task SetTimestamp_WithNoBlob_PersistsMetadata()
        {
            TimeSpan timePrecision        = new TimeSpan(0, 0, 1);
            long     dateTimeTicks        = (DateTime.UtcNow.Ticks / timePrecision.Ticks) * timePrecision.Ticks;
            DateTime lastAnalysisTestTime = new DateTime(dateTimeTicks);

            var primaryHostMock = new Mock <IPrimaryHostStateProvider>();

            primaryHostMock.Setup(p => p.IsPrimary).Returns(true);

            ICloudBlob analysisBlob = await GetAnalysisBlobReference(_hostIdProvider);

            await analysisBlob.DeleteIfExistsAsync();

            var stateProvider = new BlobChangeAnalysisStateProvider(_configuration, _hostIdProvider, NullLogger <BlobChangeAnalysisStateProvider> .Instance);

            await stateProvider.SetTimestampAsync(lastAnalysisTestTime, analysisBlob, CancellationToken.None);

            analysisBlob = await analysisBlob.ServiceClient.GetBlobReferenceFromServerAsync(analysisBlob.Uri);

            DateTime.TryParse(analysisBlob.Metadata[BlobChangeAnalysisStateProvider.AnalysisTimestampMetadataName], out DateTime result);

            Assert.Equal(lastAnalysisTestTime, result);
        }