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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); } }