예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
            }
        }