public void StorageFileDownloadInfo_Dispose() { MockStream stream = new MockStream(); StorageFileDownloadInfo storageFileDownloadInfo = FilesModelFactory.StorageFileDownloadInfo(content: stream); Assert.IsFalse(stream.IsDisposed); storageFileDownloadInfo.Dispose(); Assert.IsTrue(stream.IsDisposed); }
public async Task DownloadAsync() { // Create a temporary Lorem Ipsum file on disk that we can upload string originalPath = CreateTempFile(SampleFileContent); // Get a temporary path on disk where we can download the file string downloadPath = CreateTempPath(); // Get a connection string to our Azure Storage account. string connectionString = ConnectionString; // Get a reference to a share named "sample-share" and then create it ShareClient share = new ShareClient(connectionString, Randomize("sample-share")); await share.CreateAsync(); try { // Get a reference to a directory named "sample-dir" and then create it DirectoryClient directory = share.GetDirectoryClient(Randomize("sample-dir")); await directory.CreateAsync(); // Get a reference to a file named "sample-file" in directory "sample-dir" FileClient file = directory.GetFileClient(Randomize("sample-file")); // Upload the file using (FileStream stream = File.OpenRead(originalPath)) { await file.CreateAsync(stream.Length); await file.UploadRangeAsync( FileRangeWriteType.Update, new HttpRange(0, stream.Length), stream); } // Download the file StorageFileDownloadInfo download = await file.DownloadAsync(); using (FileStream stream = File.OpenWrite(downloadPath)) { await download.Content.CopyToAsync(stream); } // Verify the contents Assert.AreEqual(SampleFileContent, File.ReadAllText(downloadPath)); } finally { // Clean up after the test when we're finished await share.DeleteAsync(); } }