public async Task LoadFileTestSecureURLAsync() { MemoryStream stream = new MemoryStream(); string fileLoc = Path.Combine(configuration["TestFolderAddress"], "LoadFile", "TestFile.txt"); using (var file = File.OpenRead(fileLoc)) { file.Position = 0; await file.CopyToAsync(stream); } var azureBlob = new AzureBlob(); FileSetOptions fileSetOptions = new FileSetOptions() { FileAccess = FileAccessLevel._public, ConfigurationString = configuration["AzureStorageConnectionString"], Folder = "LoadFilePrivate", Key = "TestFile.txt", _stream = stream }; var fileName = await azureBlob.SaveAsync(fileSetOptions); FileGetOptions fileGetOptions = new FileGetOptions() { ConfigurationString = configuration["AzureStorageConnectionString"], Folder = "LoadFilePrivate", Key = "TestFile.txt", FileTransfer = FileTransferOptions.SecureUrl, SecureLinkTimeToLive = new TimeSpan(0, 0, 5) }; FileData data = await azureBlob.GetAsync(fileGetOptions); HttpClient webClient = new HttpClient(); var fileData = await webClient.GetStringAsync(data.Loc); Assert.IsTrue(fileData.Length > 0); }
protected async Task <AzureBlob> GetAzureBlobAsync(bool setupInitialBlobData = true) { var logger = new NullLogger <AzureBlob>(); var blob = new AzureBlob("UseDevelopmentStorage=true", "test-container", logger); if (setupInitialBlobData) { // Do we have the image already? if (await blob.GetAsync(TestImageName) == null) { var image = await File.ReadAllBytesAsync("2018-tesla-model-x-p100d.jpg"); await blob.AddAsync(image, TestImageName); } if (await blob.GetAsync <SomeFakeUser>(TestClassInstanceName) == null) { await blob.AddAsync(TestUser, TestClassInstanceName); } } return(blob); }
public async Task GetWhenAttachmentDoesntExistsThrows() { // TODO: Improve exception await Assert.ThrowsAnyAsync <StorageException>(async() => await _sut.GetAsync(_lightAttachment.ResourceId, _lightAttachment.Id)); }