コード例 #1
0
        public async Task ShouldDownloadBigFileFromAzure()
        {
            var path = DirectoryHelpers.GetNewTestFolder()[0];

            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var progress = new Progress <StorageProgressDto>();

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            await azureStorageClient.DownloadDirectoryAsync(path, Constants.AzureFileShareWithBigFile, progress);

            var fileEntries = Directory.GetFileSystemEntries(path, "*.*", SearchOption.AllDirectories);
            var directories = fileEntries
                              .Where(fileEntry => File.GetAttributes(fileEntry).HasFlag(FileAttributes.Directory)).ToList();
            var files = fileEntries.Except(directories).ToList();

            Assert.AreEqual(1, fileEntries.Length);
            Assert.AreEqual(0, directories.Count);
            Assert.AreEqual(1, files.Count);

            var fileInfo = new FileInfo(files[0]);

            Assert.AreEqual(52428800, fileInfo.Length);
            Assert.AreEqual("bigFile.dat", fileInfo.Name);
        }
コード例 #2
0
        public void ShouldBuildAzureStorageClientAndReturnInstance()
        {
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var azureStorageClient = AzureStorageClientBuilder.Build(settings);

            Assert.IsNotNull(azureStorageClient);
        }
コード例 #3
0
        public void ShouldThrowExceptionIfStoragePathIsEmptyDuringDownloading()
        {
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var azureStorageClient = AzureStorageClientBuilder.Build(settings);

            Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                       await azureStorageClient.DownloadDirectoryAsync("C:\\", string.Empty));
        }
コード例 #4
0
        public async Task ShouldUploadDirectoryToAzure()
        {
            var path     = @"F:\Test\06102018220836329\0";
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var progress = new Progress <StorageProgressDto>();

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            await azureStorageClient.UploadDirectoryAsync(path, Constants.AzureFileShareWithBigFile, progress);
        }
コード例 #5
0
        public void ShouldThrowExceptionIfLocalPathIsEmptyDuringUploading()
        {
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);

            Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                       await azureStorageClient.UploadDirectoryAsync(string.Empty, Constants.AzureFileShareWithBigFile));
        }
コード例 #6
0
        public async Task ShouldUploadFileToAzure()
        {
            var localPath   = @"F:\Test\06102018220836329\0\fileInDir2b.txt";
            var storagePath = "bigfile/1/2/fileInDir2b.txt";
            var settings    = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var progress = new Progress <StorageProgressDto>();

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            await azureStorageClient.UploadFileAsync(localPath, storagePath, progress);
        }
コード例 #7
0
        public void ShouldThrowExceptionIfStoragePathIsEmptyDuringUploading()
        {
            var path     = @"F:\Test\06102018220836329\0";
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);

            Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                       await azureStorageClient.UploadDirectoryAsync(path, string.Empty));
        }
コード例 #8
0
        public void ShouldThrowExceptionIfDirectoryIsNotEmptyDuringDownloading()
        {
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            var localPath          = "F:\\Test";

            var exception = Assert.ThrowsAsync <IOException>(async() =>
                                                             await azureStorageClient.DownloadDirectoryAsync(localPath, "sth"));

            Assert.AreEqual($"The directory '{localPath}' is not empty.", exception.Message);
        }
コード例 #9
0
        public async Task ShouldDownloadFileFromAzure()
        {
            var localPath   = @"F:\Test\06102018220836329\0";
            var storagePath = "bigfile/Dir2/Dir2b/fileInDir2b.txt";
            var settings    = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var progress = new Progress <StorageProgressDto>();

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            await azureStorageClient.DownloadFileAsync(localPath, storagePath, progress);

            Assert.IsTrue(File.Exists($@"{localPath}\fileInDir2b.txt"));
        }
コード例 #10
0
        public async Task ShouldDownloadDirectoryFromAzure()
        {
            var path = DirectoryHelpers.GetNewTestFolder()[0];

            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var progress = new Progress <StorageProgressDto>();

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            await azureStorageClient.DownloadDirectoryAsync(path, Constants.AzureFileShareWithStructure, progress);

            var fileEntries = Directory.GetFileSystemEntries(path, "*.*", SearchOption.AllDirectories);

            var directories = fileEntries
                              .Where(fileEntry => File.GetAttributes(fileEntry).HasFlag(FileAttributes.Directory)).ToList();
            var files = fileEntries.Except(directories).ToList();

            Assert.IsTrue(Directory.Exists(path));

            Assert.AreEqual(14, fileEntries.Length);
            Assert.AreEqual(6, directories.Count);
            Assert.AreEqual(8, files.Count);

            Assert.IsTrue(files.Contains($"{path}\\Dir1\\Dir1a\\file2InDir1a.txt"));
            Assert.IsTrue(files.Contains($"{path}\\Dir1\\Dir1a\\fileInDir1a.txt"));
            Assert.IsTrue(files.Contains($"{path}\\Dir1\\Dir1b\\fileI2nDir1b.txt"));
            Assert.IsTrue(files.Contains($"{path}\\Dir1\\Dir1b\\fileInDir1b.txt"));
            Assert.IsTrue(files.Contains($"{path}\\Dir1\\fileInDir1.txt"));
            Assert.IsTrue(files.Contains($"{path}\\Dir2\\fileInDir2.txt"));
            Assert.IsTrue(files.Contains($"{path}\\Dir2\\Dir2a\\fileInDir2a.txt"));
            Assert.IsTrue(files.Contains($"{path}\\Dir2\\Dir2b\\fileInDir2b.txt"));

            Assert.IsTrue(directories.Contains($"{path}\\Dir1\\Dir1b"));
            Assert.IsTrue(directories.Contains($"{path}\\Dir1\\Dir1b"));
            Assert.IsTrue(directories.Contains($"{path}\\Dir1"));
            Assert.IsTrue(directories.Contains($"{path}\\Dir2"));
            Assert.IsTrue(directories.Contains($"{path}\\Dir2\\Dir2a"));
            Assert.IsTrue(directories.Contains($"{path}\\Dir2\\Dir2b"));

            Assert.IsTrue(new FileInfo($"{path}\\Dir1\\Dir1a\\file2InDir1a.txt").Length > 0);
            Assert.IsTrue(new FileInfo($"{path}\\Dir1\\Dir1a\\fileInDir1a.txt").Length > 0);
            Assert.IsTrue(new FileInfo($"{path}\\Dir1\\Dir1b\\fileI2nDir1b.txt").Length > 0);
            Assert.IsTrue(new FileInfo($"{path}\\Dir1\\Dir1b\\fileInDir1b.txt").Length > 0);
            Assert.IsTrue(new FileInfo($"{path}\\Dir1\\fileInDir1.txt").Length > 0);
            Assert.IsTrue(new FileInfo($"{path}\\Dir2\\fileInDir2.txt").Length > 0);
            Assert.IsTrue(new FileInfo($"{path}\\Dir2\\Dir2a\\fileInDir2a.txt").Length > 0);
            Assert.IsTrue(new FileInfo($"{path}\\Dir2\\Dir2b\\fileInDir2b.txt").Length > 0);
        }
コード例 #11
0
        public void ShouldThrowExceptionIfCancelIsRequestedDuringUploading()
        {
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            var path = @"F:\Test\06102018220836329\0";
            var cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Cancel();

            Assert.ThrowsAsync <TaskCanceledException>(async() =>
                                                       await azureStorageClient.UploadDirectoryAsync(path, Constants.AzureFileShareWithBigFile,
                                                                                                     cancellationToken: cancellationTokenSource.Token));
        }
コード例 #12
0
        public void ShouldThrowExceptionIfCancelIsRequestedDuringDownloading()
        {
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var azureStorageClient      = AzureStorageClientBuilder.Build(settings);
            var progress                = new Progress <StorageProgressDto>();
            var localPath               = $"F:\\Test\\{DateTime.Now:hhmmsst}";
            var cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Cancel();

            Assert.ThrowsAsync <TaskCanceledException>(async() =>
                                                       await azureStorageClient.DownloadDirectoryAsync(localPath, "sth", progress,
                                                                                                       cancellationTokenSource.Token));
        }
コード例 #13
0
        public async Task ShouldReportDuringDownloading()
        {
            var events = new List <StorageProgressDto>();
            var path   = DirectoryHelpers.GetNewTestFolder()[0];

            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var progress = new Progress <StorageProgressDto>();

            progress.ProgressChanged += (s, e) => { events.Add(e); };

            var azureStorageClient = AzureStorageClientBuilder.Build(settings);
            await azureStorageClient.DownloadDirectoryAsync(path, Constants.AzureFileShareWithStructure, progress);

            Assert.AreEqual(38, events.Count);
        }
コード例 #14
0
        public void ShouldReportDuringCancelIsRequested()
        {
            var events   = new List <StorageProgressDto>();
            var settings = new StorageSettings {
                ConnectionString = Constants.ConnectionString
            };
            var azureStorageClient      = AzureStorageClientBuilder.Build(settings);
            var localPath               = $"F:\\Test\\{DateTime.Now:hhmmsst}";
            var cancellationTokenSource = new CancellationTokenSource();

            cancellationTokenSource.Cancel();

            var progress = new Progress <StorageProgressDto>();

            progress.ProgressChanged += (s, e) => { events.Add(e); };

            Assert.ThrowsAsync <TaskCanceledException>(async() =>
                                                       await azureStorageClient.DownloadDirectoryAsync(localPath, "sth",
                                                                                                       progress, cancellationTokenSource.Token));

            Assert.AreEqual(1, events.Count);
            Assert.AreEqual(StorageProgressJobType.CleanDirectory, events[0].StorageProgressJobType);
        }