Example #1
0
        public async Task DownloadTextReturnsNullIfBlobDoesntExist()
        {
            var target = new CloudBlobWrapper(_cloudBlobMock.Object);

            _cloudBlobMock
            .Setup(cb => cb.DownloadTextAsync())
            .ThrowsAsync(CreateBlobNotFoundException())
            .Verifiable();

            var result = await target.DownloadTextIfExistsAsync();

            Assert.Null(result);
        }
Example #2
0
        public async Task FetchAttributesIfExistsAsyncReturnsFalseOnNoBlob()
        {
            var target = new CloudBlobWrapper(_cloudBlobMock.Object);

            _cloudBlobMock
            .Setup(cb => cb.FetchAttributesAsync())
            .ThrowsAsync(CreateBlobNotFoundException())
            .Verifiable();

            var result = await target.FetchAttributesIfExistsAsync();

            _cloudBlobMock.VerifyAll();
            Assert.False(result);
        }
Example #3
0
        public async Task FetchAttributesIfExistsAsyncReturnsTrueOnSuccess()
        {
            var target = new CloudBlobWrapper(_cloudBlobMock.Object);

            _cloudBlobMock
            .Setup(cb => cb.FetchAttributesAsync())
            .Returns(Task.CompletedTask)
            .Verifiable();

            var result = await target.FetchAttributesIfExistsAsync();

            _cloudBlobMock.VerifyAll();
            Assert.True(result);
        }
Example #4
0
        public async Task DownloadTextPassesThroughExceptions()
        {
            var target    = new CloudBlobWrapper(_cloudBlobMock.Object);
            var exception = new TestException();

            _cloudBlobMock
            .Setup(cb => cb.DownloadTextAsync())
            .ThrowsAsync(exception)
            .Verifiable();

            var thrownException = await Assert.ThrowsAsync <TestException>(() => target.DownloadTextIfExistsAsync());

            Assert.Same(exception, thrownException);
        }
Example #5
0
        public async Task OpenReadIfExistsAsyncReturnsNullOnNoBlob()
        {
            var target = new CloudBlobWrapper(_cloudBlobMock.Object);

            _cloudBlobMock
            .Setup(cb => cb.OpenReadAsync(It.IsAny <AccessCondition>(), It.IsAny <BlobRequestOptions>(), It.IsAny <OperationContext>()))
            .ThrowsAsync(CreateBlobNotFoundException())
            .Verifiable();

            var returnedStream = await target.OpenReadIfExistsAsync();

            _cloudBlobMock.VerifyAll();
            Assert.Null(returnedStream);
        }
Example #6
0
        public async Task DownloadsText()
        {
            var          target = new CloudBlobWrapper(_cloudBlobMock.Object);
            const string text   = "sometext";

            _cloudBlobMock
            .Setup(cb => cb.DownloadTextAsync())
            .ReturnsAsync(text)
            .Verifiable();

            var result = await target.DownloadTextIfExistsAsync();

            _cloudBlobMock.VerifyAll();
            Assert.Equal(text, result);
        }
Example #7
0
        public async Task OpenReadIfExistsAsyncPassesThroughExceptions()
        {
            var target    = new CloudBlobWrapper(_cloudBlobMock.Object);
            var exception = new TestException();

            _cloudBlobMock
            .Setup(cb => cb.OpenReadAsync(It.IsAny <AccessCondition>(), It.IsAny <BlobRequestOptions>(), It.IsAny <OperationContext>()))
            .ThrowsAsync(exception)
            .Verifiable();

            var thrownException = await Assert.ThrowsAsync <TestException>(() => target.OpenReadIfExistsAsync());

            _cloudBlobMock.VerifyAll();
            Assert.Same(exception, thrownException);
        }
Example #8
0
        public async Task FetchAttributesIfExistsAsyncPassesThroughExceptions()
        {
            var target    = new CloudBlobWrapper(_cloudBlobMock.Object);
            var exception = new TestException();

            _cloudBlobMock
            .Setup(cb => cb.FetchAttributesAsync())
            .ThrowsAsync(exception)
            .Verifiable();

            var thrownException = await Assert.ThrowsAsync <TestException>(() => target.FetchAttributesIfExistsAsync());

            _cloudBlobMock.VerifyAll();
            Assert.Same(exception, thrownException);
        }
Example #9
0
        public async Task OpenReadIfExistsAsyncReturnsStream()
        {
            var target = new CloudBlobWrapper(_cloudBlobMock.Object);

            using (var stream = new MemoryStream())
            {
                _cloudBlobMock
                .Setup(cb => cb.OpenReadAsync(It.IsAny <AccessCondition>(), It.IsAny <BlobRequestOptions>(), It.IsAny <OperationContext>()))
                .ReturnsAsync(stream)
                .Verifiable();

                var returnedStream = await target.OpenReadIfExistsAsync();

                _cloudBlobMock.VerifyAll();
                Assert.Same(stream, returnedStream);
            }
        }