Example #1
0
        public void CloudFileDirectoryHierarchicalTraversal()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            ////Traverse hierarchically starting with length 1
            CloudFileDirectory directory1 = share.GetRootDirectoryReference().GetDirectoryReference("Dir1");
            CloudFileDirectory subdir1    = directory1.GetDirectoryReference("Dir2");
            CloudFileDirectory parent1    = subdir1.Parent;

            Assert.AreEqual(parent1.Name, directory1.Name);

            CloudFileDirectory subdir2 = subdir1.GetDirectoryReference("Dir3");
            CloudFileDirectory parent2 = subdir2.Parent;

            Assert.AreEqual(parent2.Name, subdir1.Name);

            CloudFileDirectory subdir3 = subdir2.GetDirectoryReference("Dir4");
            CloudFileDirectory parent3 = subdir3.Parent;

            Assert.AreEqual(parent3.Name, subdir2.Name);

            CloudFileDirectory subdir4 = subdir3.GetDirectoryReference("Dir5");
            CloudFileDirectory parent4 = subdir4.Parent;

            Assert.AreEqual(parent4.Name, subdir3.Name);
        }
Example #2
0
        public async Task CloudFileDirectoryFileCreateWithoutDirectoryAsync()
        {
            CloudFileClient    client        = GenerateCloudFileClient();
            string             name          = GetRandomShareName();
            CloudFileShare     share         = client.GetShareReference(name);
            CloudFileDirectory rootDirectory = share.GetRootDirectoryReference();

            try
            {
                await share.CreateAsync();

                CloudFileDirectory dir     = rootDirectory.GetDirectoryReference("Dir1");
                CloudFile          file    = dir.GetFileReference("file1");
                OperationContext   context = new OperationContext();
                await TestHelper.ExpectedExceptionAsync(
                    async() => await file.CreateAsync(0, null, null, context),
                    context,
                    "Creating a file when the directory has not been created should throw",
                    HttpStatusCode.NotFound,
                    "ParentNotFound");

                // File creation directly in the share should pass.
                CloudFile file2 = rootDirectory.GetFileReference("file2");
                await file2.CreateAsync(0);

                await dir.CreateAsync();

                await file.CreateAsync(0);
            }
            finally
            {
                share.DeleteAsync().Wait();
            }
        }
Example #3
0
        public void CloudFileDirectoryGetEmptySubDirectory()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            CloudFileDirectory root = share.GetRootDirectoryReference().GetDirectoryReference("TopDir1/");

            TestHelper.ExpectedException <ArgumentException>(
                () => root.GetDirectoryReference(String.Empty),
                "Try to get a reference to an empty sub-directory");
        }
Example #4
0
        public void CloudFileDirectoryGetSubdirectoryAndTraverseBackToParent()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            CloudFileDirectory directory    = share.GetRootDirectoryReference().GetDirectoryReference("TopDir1");
            CloudFileDirectory subDirectory = directory.GetDirectoryReference("MidDir1");
            CloudFileDirectory parent       = subDirectory.Parent;

            Assert.AreEqual(parent.Name, directory.Name);
            Assert.AreEqual(parent.Uri, directory.Uri);
        }
        public void MyTestInitialize()
        {
            if (TestBase.FileBufferManager != null)
            {
                TestBase.FileBufferManager.OutstandingBufferCount = 0;
            }

            this.share = GetRandomShareReference();
            this.share.CreateIfNotExists();
            CloudFileDirectory directory = share.GetRootDirectoryReference();

            this.directory = directory.GetDirectoryReference("directory");
            this.directory.Create();
            this.file = this.directory.GetFileReference("file");
            this.file.UploadText("test");
        }
Example #6
0
        public void CloudFileClientObjects()
        {
            CloudFileClient fileClient = GenerateCloudFileClient();
            CloudFileShare  share      = fileClient.GetShareReference("share");

            Assert.AreEqual(fileClient, share.ServiceClient);
            CloudFileDirectory rootDirectory = share.GetRootDirectoryReference();

            Assert.AreEqual(fileClient, rootDirectory.ServiceClient);
            CloudFileDirectory directory = rootDirectory.GetDirectoryReference("directory");

            Assert.AreEqual(fileClient, directory.ServiceClient);
            CloudFile file = directory.GetFileReference("file");

            Assert.AreEqual(fileClient, file.ServiceClient);

            CloudFileShare share2 = GetRandomShareReference();

            Assert.AreNotEqual(fileClient, share2.ServiceClient);
        }
Example #7
0
        private async Task <bool> CloudFileDirectorySetupAsync(CloudFileShare share)
        {
            try
            {
                CloudFileDirectory rootDirectory = share.GetRootDirectoryReference();
                for (int i = 1; i < 3; i++)
                {
                    CloudFileDirectory topDirectory = rootDirectory.GetDirectoryReference("TopDir" + i);
                    await topDirectory.CreateAsync();

                    for (int j = 1; j < 3; j++)
                    {
                        CloudFileDirectory midDirectory = topDirectory.GetDirectoryReference("MidDir" + j);
                        await midDirectory.CreateAsync();

                        for (int k = 1; k < 3; k++)
                        {
                            CloudFileDirectory endDirectory = midDirectory.GetDirectoryReference("EndDir" + k);
                            await endDirectory.CreateAsync();

                            CloudFile file1 = endDirectory.GetFileReference("EndFile" + k);
                            await file1.CreateAsync(0);
                        }
                    }

                    CloudFile file2 = topDirectory.GetFileReference("File" + i);
                    await file2.CreateAsync(0);
                }

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }