Exemple #1
0
        public void TestGetSubDirectoriesAndFiles()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile("forms/form_123/kitty.jpg", Stream.Null);
            provider.AddFile("forms/form_123/dog.jpg", Stream.Null);
            provider.AddFile("forms/form_456/panda.jpg", Stream.Null);

            // Act
            var subfolders = provider.GetDirectories("forms");
            var actual     = new List <string>();

            foreach (var folder in subfolders)
            {
                // Get files in subfolder and add to a single collection
                actual.AddRange(provider.GetFiles(folder));
            }

            // Assert
            string[] expected = { "forms/form_123/dog.jpg", "forms/form_123/kitty.jpg", "forms/form_456/panda.jpg" };
            Assert.IsTrue(expected.SequenceEqual(actual));

            // Tidy up after test
            provider.DeleteDirectory("forms");
        }
Exemple #2
0
        public void InsuffientSasTokenPermissions()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem(containerName: "xxx", useDefaultRoute: "false");

            // Act & Assert
            Assert.Throws <Microsoft.WindowsAzure.Storage.StorageException>(() => provider.AddFile("1010/image.jpg", Stream.Null));
        }
Exemple #3
0
 protected void CreateSut()
 {
     Sut = new AzureBlobFileSystem(
         MockRepository.GenerateStub <ILogger>(),
         Account,
         ContainerName,
         BlobUrl
         );
 }
 protected void CreateSut()
 {
     Sut = new AzureBlobFileSystem(
         MockRepository.GenerateStub<ILogger>(),
         Account,
         ContainerName,
         BlobUrl
         );
 }
Exemple #5
0
        public void TestValidDirectory()
        {
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile("testvalid/test.txt", Stream.Null);
            Assert.IsTrue(provider.DirectoryExists("testvalid"));

            // Tidy up after test
            provider.DeleteDirectory("testvalid");
        }
        public void ResolveUrlPrefixed()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            string actual = provider.GetUrl($"{this.ContainerName}/110/image.jpg");

            // Assert
            Assert.AreEqual($"/{this.ContainerName}/110/image.jpg", actual);
        }
Exemple #7
0
        public void ResolveFullPathPrefixed()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            string actual = provider.GetFullPath("media/1010/media.jpg");

            // Assert
            Assert.AreEqual("http://127.0.0.1:10000/devstoreaccount1/media/1010/media.jpg", actual);
        }
Exemple #8
0
        public void ResolveRelativePath()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            string actual = provider.GetRelativePath("1010/media.jpg");

            // Assert
            Assert.AreEqual("/media/1010/media.jpg", actual);
        }
Exemple #9
0
        public void ResolveFullPath()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            string actual = provider.GetFullPath("1010/image.jpg");

            // Assert
            Assert.AreEqual($"{this.RootUrl}{this.ContainerName}/1010/image.jpg", actual);
        }
Exemple #10
0
        public void TestGetFilesInvalidPath()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            IEnumerable <string> actual = provider.GetFiles("/somethingmissing", "*.jpg");

            // Assert
            Assert.IsEmpty(actual);
        }
Exemple #11
0
        public void TestAddFilePrefixed()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            provider.AddFile($"{this.ContainerName}/1010/image.jpg", Stream.Null);

            // Assert
            Assert.IsTrue(provider.FileExists("1010/image.jpg"));
        }
Exemple #12
0
        public void ResolveRelativePathWithAppVirtualPath()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem(false, "/test");

            // Act
            string actual = provider.GetRelativePath("1010/image.jpg");

            // Assert
            Assert.AreEqual($"/test/{this.ContainerName}/1010/image.jpg", actual);
        }
        public void ResolveUrlPrefixed()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            string actual = provider.GetUrl("media/1010/media.jpg");

            // Assert
            Assert.AreEqual("/media/1010/media.jpg", actual);
        }
Exemple #14
0
        public void TestAddFilePrefixed()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            provider.AddFile("media/1010/media.jpg", Stream.Null);

            // Assert
            Assert.IsTrue(provider.FileExists("1010/media.jpg"));
        }
Exemple #15
0
        public void TestFileExists()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            provider.AddFile("1010/image.jpg", Stream.Null);

            // Assert
            Assert.IsTrue(provider.FileExists("1010/image.jpg"));
            Assert.IsFalse(provider.FileExists("1010/media1.jpg"));
        }
Exemple #16
0
        public AzureFS(string inputConnectionString)
        {
            _inputFS = _azure;

            if (String.IsNullOrEmpty(inputConnectionString))
            {
                throw new ArgumentNullException(nameof(inputConnectionString));
            }

            _inputFS.AddStorageAccount("azure", inputConnectionString);
            _inputFS.SetWorkingFolder("wasb://azure/web");
        }
Exemple #17
0
        public void SuffientSasTokenPermissions()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem(containerName: "xxx", useDefaultRoute: "false");

            // Act
            provider.AddFile("1010/image.jpg", Stream.Null);

            // Assert
            Assert.IsTrue(provider.FileExists("1010/image.jpg"));
            Assert.IsFalse(provider.FileExists("1010/media1.jpg"));
        }
Exemple #18
0
        public void TestGetFiles()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile("1010/media.jpg", Stream.Null);

            // Act
            IEnumerable <string> actual = provider.GetFiles("/1010");

            // Assert
            string[] expected = { "1010/media.jpg" };
            Assert.IsTrue(expected.SequenceEqual(actual));
        }
Exemple #19
0
        public void TestGetDirectoriesPrefixed()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile($"{this.ContainerName}/1010/image.jpg", Stream.Null);
            provider.AddFile($"{this.ContainerName}/1011/image.jpg", Stream.Null);
            provider.AddFile($"{this.ContainerName}/1012/image.jpg", Stream.Null);

            // Act
            IEnumerable <string> actual = provider.GetDirectories("/");

            // Assert
            string[] expected = { "1010", "1011", "1012" };
            Assert.IsTrue(expected.SequenceEqual(actual));
        }
Exemple #20
0
        public void TestOpenFilePrefixed()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            using (MemoryStream expected = new MemoryStream(Encoding.UTF8.GetBytes("test")))
            {
                // Act
                provider.AddFile("media/1010/media.jpg", expected);

                // Assert
                using (Stream actual = provider.OpenFile("media/1010/media.jpg"))
                {
                    Assert.AreEqual(expected, actual);
                }
            }
        }
Exemple #21
0
        public AzureFS(string inputConnectionString, string container)
        {
            _inputFS = _azure;

            if (String.IsNullOrEmpty(inputConnectionString))
            {
                throw new ArgumentNullException(nameof(inputConnectionString));
            }

            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            _inputFS.AddStorageAccount("azure", inputConnectionString);
            _inputFS.SetWorkingFolder($"wasb://azure/{container}");
        }
Exemple #22
0
        public void TestGetFilesFromRootFiltered()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile("1010/media.jpg", Stream.Null);
            provider.AddFile("1011/media.jpg", Stream.Null);
            provider.AddFile("1012/media.jpg", Stream.Null);

            // Act
            IEnumerable <string> actual    = provider.GetFiles("/", "*.jpg");
            IEnumerable <string> alternate = provider.GetFiles("/", "*.png");

            // Assert
            string[] expected = { "1010/media.jpg", "1011/media.jpg", "1012/media.jpg" };
            Assert.IsTrue(expected.SequenceEqual(actual));
            Assert.IsFalse(expected.SequenceEqual(alternate));
        }
Exemple #23
0
        public AzureFS(string inputConnectionString, string outputConnectionString)
        {
            _inputFS  = _azure;
            _outputFS = _azure;

            if (String.IsNullOrEmpty(inputConnectionString))
            {
                throw new ArgumentNullException(nameof(inputConnectionString));
            }

            if (String.IsNullOrEmpty(outputConnectionString))
            {
                throw new ArgumentNullException(nameof(outputConnectionString));
            }

            _inputFS.AddStorageAccount("input", inputConnectionString);
            _outputFS.AddStorageAccount("output", outputConnectionString);
        }
Exemple #24
0
        public void TestDeleteDirectory()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            provider.AddFile("1010/image.jpg", Stream.Null);

            // Assert
            Assert.IsTrue(provider.DirectoryExists("1010/"));

            // Act
            provider.DeleteDirectory("1010/");

            // Assert
            Assert.IsFalse(provider.DirectoryExists("1010/"));
            Assert.IsFalse(provider.FileExists("1010/image.jpg"));
        }
Exemple #25
0
        public void TestDeleteDirectoryRelative()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            provider.AddFile("media/1010/media.jpg", Stream.Null);

            // Assert
            Assert.IsTrue(provider.DirectoryExists("media/1010"));

            // Act
            provider.DeleteDirectory("\\media\\1010");

            // Assert
            Assert.IsFalse(provider.DirectoryExists("media/1010/"));
            Assert.IsFalse(provider.FileExists("media/1010/media.jpg"));
        }
Exemple #26
0
        public void TestDeleteDirectoryRelative()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            // Act
            provider.AddFile($"{this.ContainerName}/1010/image.jpg", Stream.Null);

            // Assert
            Assert.IsTrue(provider.DirectoryExists($"{this.ContainerName}/1010"));

            // Act
            provider.DeleteDirectory($"\\{this.ContainerName}\\1010");

            // Assert
            Assert.IsFalse(provider.DirectoryExists($"{this.ContainerName}/1010/"));
            Assert.IsFalse(provider.FileExists($"{this.ContainerName}/1010/image.jpg"));
        }
Exemple #27
0
        public void Run(string inputStorageAccount, string queueStorageAccount, string queueName)
        {
            _inputStorageAccount = inputStorageAccount;
            _queueStorageAccount = queueStorageAccount;
            _queueName           = queueName;

            var input = new AzureBlobFileSystem();

            input.AddStorageAccount("input", inputStorageAccount);
            input.SetWorkingFolder("wasb://input");
            var container = input.GetFolder("pdf");

            var itens = container.EnumItems();

            var itens_added = ProcessItensAsync(itens, "pdf").GetAwaiter().GetResult();

            Console.WriteLine($"{itens_added} message(s) added to the queue !");
        }
Exemple #28
0
        static void Main(string[] args)
        {
            Console.WriteLine("Console Queue");

            _config = new Config(args);

            var input = new AzureBlobFileSystem();

            input.AddStorageAccount("input", _config.Get("INPUT_STORAGE_ACCOUNT"));
            input.SetWorkingFolder("wasb://input");
            var container = input.GetFolder("pdf");

            var itens = container.EnumItems();

            var itens_added = ProcessItensAsync(itens, "pdf").GetAwaiter().GetResult();

            Console.WriteLine($"{itens_added} message(s) added to the queue !");
        }
Exemple #29
0
        public void TestGetSubDirectories()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile("forms/form_123/kitty.jpg", Stream.Null);
            provider.AddFile("forms/form_123/dog.jpg", Stream.Null);
            provider.AddFile("forms/form_456/panda.jpg", Stream.Null);

            // Act
            IEnumerable <string> actual = provider.GetDirectories("forms");

            // Assert
            string[] expected = { "forms/form_123", "forms/form_456" };
            Assert.IsTrue(expected.SequenceEqual(actual));

            // Tidy up after test
            provider.DeleteDirectory("forms");
        }
Exemple #30
0
        public void TestGetCreated()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile("1010/media.jpg", Stream.Null);

            // Act
            DateTimeOffset original = provider.GetCreated("1010/media.jpg");

            // Assert
            Assert.AreNotEqual(original, DateTimeOffset.MinValue);

            // Act
            provider.AddFile("1010/media.jpg", Stream.Null);
            DateTimeOffset updated = provider.GetCreated("1010/media.jpg");

            // Assert
            Assert.AreEqual(original, updated);
        }
Exemple #31
0
        public void TestGetLastModified()
        {
            // Arrange
            AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();

            provider.AddFile("1010/media.jpg", Stream.Null);

            // Act
            DateTimeOffset original = provider.GetLastModified("1010/media.jpg");

            // Assert
            Assert.AreNotEqual(original, DateTimeOffset.MinValue);

            Thread.Sleep(TimeSpan.FromSeconds(1.1));

            // Act
            provider.AddFile("1010/media.jpg", Stream.Null);
            DateTimeOffset updated = provider.GetLastModified("1010/media.jpg");

            // Assert
            Assert.AreNotEqual(original, updated);
        }