static async Task Run(Options options) { IBlobClientFactory factory = new BlobClientFactory(options.StorageConnectionString); ICommand command = new UploadBlobCommand(factory, options.ContainerName); BlobRequestOptions requestOptions = new BlobRequestOptions() { RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(5), 3) }; IDictionary <string, object> commandParameters = new Dictionary <string, object> { { "options", requestOptions }, { "blobPath", Path.GetFileName(options.FilePath) }, { "filePath", options.FilePath }, { "contentType", options.ContentType } }; await command.Run(commandParameters); }
public async Task ShouldUploadBlob() { // Arrange string containerName = "container"; string blobPath = "foo.txt"; string filePath = "c:\\foo.txt"; string contentType = "txt"; BlobRequestOptions options = new BlobRequestOptions(); Mock <IBlockBlob> blobMock = new Mock <IBlockBlob>(); Mock <IBlobContainer> containerMock = new Mock <IBlobContainer>(); containerMock.Setup(m => m.GetBlockBlobReference(blobPath)).Returns(blobMock.Object); Mock <IBlobClient> clientMock = new Mock <IBlobClient>(); clientMock.Setup(m => m.GetContainerReference(containerName)).Returns(containerMock.Object); Mock <IBlobClientFactory> factoryMock = new Mock <IBlobClientFactory>(); factoryMock.Setup(m => m.CreateBlobClient()).Returns(clientMock.Object); ICommand command = new UploadBlobCommand(factoryMock.Object, containerName); IDictionary <string, object> commandParameters = new Dictionary <string, object> { { "options", options }, { "blobPath", blobPath }, { "filePath", filePath }, { "contentType", contentType } }; // Act await command.Run(commandParameters); // Assert containerMock.Verify(m => m.CreateIfNotExistsAsync(options), Times.Once); blobMock.Verify(m => m.UploadFromFileAsync(filePath, contentType), Times.Once); }