public async void DownloadBlob_StreamShouldReturn() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); var blobContainerClient = new BlobContainerClient(ConnectionString, uniqueContainerName); var blobClient = blobContainerClient.GetBlobClient(blobName); string blobContent = "example"; // create a new blob using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(blobContent))) { var isCreated = await blobProvider.CreateBlobAsync(blobName, stream, CancellationToken.None); Assert.True(isCreated); Assert.True(blobClient.Exists()); } using Stream downloadStream = await blobProvider.GetBlobAsync(blobName, CancellationToken.None); using var reader = new StreamReader(downloadStream); Assert.Equal(blobContent, reader.ReadToEnd()); await blobContainerClient.DeleteAsync(); }
public async void AccessBlobProvider_WhenContainerNoExists_ExceptionShouldBeThrown() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); // call function of blobProvider using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("example"))) { Assert.True(await blobProvider.CreateBlobAsync(blobName, stream, CancellationToken.None)); } var blobServiceClient = new BlobServiceClient(ConnectionString); // delete the created container blobServiceClient.DeleteBlobContainer(uniqueContainerName); // call CreateBlobAsync() after the container is deleted by others using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("new example"))) { await Assert.ThrowsAsync <AzureBlobOperationFailedException>(() => blobProvider.CreateBlobAsync(blobName, stream, CancellationToken.None)); } // call UploadStreamToBlobAsync()after the container is deleted by others using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes("new example"))) { await Assert.ThrowsAsync <AzureBlobOperationFailedException>(() => blobProvider.UpdateBlobAsync(blobName, stream, CancellationToken.None)); } // call GetBlobAsync() after the container is deleted by others await Assert.ThrowsAsync <AzureBlobOperationFailedException>(() => blobProvider.GetBlobAsync(blobName, CancellationToken.None)); }
public async void DownloadNoExistingBlob_StreamShouldReturn() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); var blobContainerClient = new BlobContainerClient(ConnectionString, uniqueContainerName); var blobClient = blobContainerClient.GetBlobClient(blobName); Assert.False(blobClient.Exists()); using Stream downloadStream = await blobProvider.GetBlobAsync(blobName, CancellationToken.None); Assert.Null(downloadStream); await blobContainerClient.DeleteAsync(); }