Exemplo n.º 1
0
        public void FileWriteStreamOpenAndClose()
        {
            CloudFileShare share = GetRandomShareReference();

            try
            {
                share.Create();

                CloudFile file = share.GetRootDirectoryReference().GetFileReference("file");
                TestHelper.ExpectedException(
                    () => file.OpenWrite(null),
                    "Opening a file stream with no size should fail on a file that does not exist",
                    HttpStatusCode.NotFound);
                using (Stream fileStream = file.OpenWrite(1024))
                {
                }
                using (Stream fileStream = file.OpenWrite(null))
                {
                }

                CloudFile file2 = share.GetRootDirectoryReference().GetFileReference("file");
                file2.FetchAttributes();
                Assert.AreEqual(1024, file2.Properties.Length);
            }
            finally
            {
                share.Delete();
            }
        }
Exemplo n.º 2
0
        public void CloudFileDirectoryFileCreateWithoutDirectory()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            try
            {
                share.Create();
                CloudFileDirectory dir  = share.GetRootDirectoryReference().GetDirectoryReference("Dir1");
                CloudFile          file = dir.GetFileReference("file1");
                TestHelper.ExpectedException(
                    () => file.Create(0),
                    "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 = share.GetRootDirectoryReference().GetFileReference("file2");
                file2.Create(0);

                dir.Create();
                file.Create(0);
            }
            finally
            {
                share.Delete();
            }
        }
Exemplo n.º 3
0
        public void CloudFileDirectoryWithFilesDelete()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            try
            {
                share.Create();
                if (CloudFileDirectorySetup(share))
                {
                    CloudFileDirectory dir1  = share.GetRootDirectoryReference().GetDirectoryReference("TopDir1/MidDir1/EndDir1");
                    CloudFile          file1 = dir1.GetFileReference("EndFile1");
                    TestHelper.ExpectedException(
                        () => dir1.Delete(),
                        "Delete a non-empty directory",
                        HttpStatusCode.Conflict);

                    file1.Delete();
                    dir1.Delete();
                    Assert.IsFalse(file1.Exists());
                    Assert.IsFalse(dir1.Exists());
                }
            }
            finally
            {
                share.Delete();
            }
        }
Exemplo n.º 4
0
        public void CloudFileDirectoryCreateAndDeleteAPM()
        {
            CloudFileShare share = GetRandomShareReference();

            try
            {
                share.Create();
                using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                {
                    CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference("directory1");
                    IAsyncResult       result    = directory.BeginCreate(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    directory.EndCreate(result);
                    Assert.IsTrue(directory.Exists());
                    result = directory.BeginDelete(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    directory.EndDelete(result);
                    Assert.IsFalse(directory.Exists());
                }
            }
            finally
            {
                share.Delete();
            }
        }
        public void CloudFileShareCreate()
        {
            CloudFileShare share = GetRandomShareReference();

            share.Create();
            TestHelper.ExpectedException(
                () => share.Create(),
                "Creating already exists share should fail",
                HttpStatusCode.Conflict);
            share.Delete();
        }
Exemplo n.º 6
0
        public void CloudFileClientCreateShareSharedKeyLite()
        {
            CloudFileClient fileClient = GenerateCloudFileClient();

            fileClient.AuthenticationScheme = AuthenticationScheme.SharedKeyLite;

            string         shareName = GetRandomShareName();
            CloudFileShare share     = fileClient.GetShareReference(shareName);

            share.Create();

            bool exists = share.Exists();

            Assert.IsTrue(exists);

            share.Delete();
        }
Exemplo n.º 7
0
        public void CloudFileDirectoryWithFilesDeleteAPM()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            try
            {
                share.Create();
                if (CloudFileDirectorySetup(share))
                {
                    CloudFileDirectory dir1  = share.GetRootDirectoryReference().GetDirectoryReference("TopDir1/MidDir1/EndDir1");
                    CloudFile          file1 = dir1.GetFileReference("EndFile1");
                    using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                    {
                        IAsyncResult result = dir1.BeginDelete(
                            ar => waitHandle.Set(),
                            null);
                        waitHandle.WaitOne();
                        TestHelper.ExpectedException(
                            () => dir1.EndDelete(result),
                            "Delete a non-empty directory",
                            HttpStatusCode.Conflict);

                        result = file1.BeginDelete(
                            ar => waitHandle.Set(),
                            null);
                        waitHandle.WaitOne();
                        file1.EndDelete(result);

                        result = dir1.BeginDelete(
                            ar => waitHandle.Set(),
                            null);
                        waitHandle.WaitOne();
                        dir1.EndDelete(result);
                    }

                    Assert.IsFalse(file1.Exists());
                    Assert.IsFalse(dir1.Exists());
                }
            }
            finally
            {
                share.Delete();
            }
        }
Exemplo n.º 8
0
        public void CloudFileDirectoryDeleteIfExists()
        {
            CloudFileShare share = GetRandomShareReference();

            share.Create();

            try
            {
                CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference("directory1");
                Assert.IsFalse(directory.DeleteIfExists());
                directory.Create();
                Assert.IsTrue(directory.DeleteIfExists());
                Assert.IsFalse(directory.DeleteIfExists());
            }
            finally
            {
                share.Delete();
            }
        }
Exemplo n.º 9
0
        private void FileDirectoryEscapingTest(string directoryName, string fileName)
        {
            CloudFileClient service = GenerateCloudFileClient();
            CloudFileShare  share   = GetRandomShareReference();

            try
            {
                share.Create();
                string text = Guid.NewGuid().ToString();

                // Create from CloudFileShare.
                CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference(directoryName);
                directory.Create();
                CloudFile originalFile = directory.GetFileReference(fileName);
                originalFile.Create(0);

                // List directories from share.
                IListFileItem directoryFromShareListingFiles = share.GetRootDirectoryReference().ListFilesAndDirectories().First();
                Assert.AreEqual(directory.Uri, directoryFromShareListingFiles.Uri);

                // List files from directory.
                IListFileItem fileFromDirectoryListingFiles = directory.ListFilesAndDirectories().First();
                Assert.AreEqual(originalFile.Uri, fileFromDirectoryListingFiles.Uri);

                // Check Name
                Assert.AreEqual <string>(fileName, originalFile.Name);

                // Absolute URI access from CloudFile
                CloudFile fileInfo = new CloudFile(originalFile.Uri, service.Credentials);
                fileInfo.FetchAttributes();

                // Access from CloudFileDirectory
                CloudFileDirectory cloudFileDirectory         = share.GetRootDirectoryReference().GetDirectoryReference(directoryName);
                CloudFile          fileFromCloudFileDirectory = cloudFileDirectory.GetFileReference(fileName);
                Assert.AreEqual(fileInfo.Uri, fileFromCloudFileDirectory.Uri);
            }
            finally
            {
                share.Delete();
            }
        }
        public void CloudFileShareExists()
        {
            CloudFileShare share  = GetRandomShareReference();
            CloudFileShare share2 = share.ServiceClient.GetShareReference(share.Name);

            Assert.IsFalse(share2.Exists());

            share.Create();

            try
            {
                Assert.IsTrue(share2.Exists());
                Assert.IsNotNull(share2.Properties.ETag);
            }
            finally
            {
                share.Delete();
            }

            Assert.IsFalse(share2.Exists());
        }
        public void CloudFileShareCreateAPM()
        {
            CloudFileShare share = GetRandomShareReference();

            using (AutoResetEvent waitHandle = new AutoResetEvent(false))
            {
                IAsyncResult result = share.BeginCreate(
                    ar => waitHandle.Set(),
                    null);
                waitHandle.WaitOne();
                share.EndCreate(result);
                result = share.BeginCreate(
                    ar => waitHandle.Set(),
                    null);
                waitHandle.WaitOne();
                TestHelper.ExpectedException(
                    () => share.EndCreate(result),
                    "Creating already exists share should fail",
                    HttpStatusCode.Conflict);
            }
            share.Delete();
        }
Exemplo n.º 12
0
        public void CloudFileDirectoryCreateDirectoryUsingPrefix()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            try
            {
                share.Create();
                CloudFileDirectory dir1 = share.GetRootDirectoryReference().GetDirectoryReference("Dir1");
                CloudFileDirectory dir2 = share.GetRootDirectoryReference().GetDirectoryReference("Dir1/Dir2");
                TestHelper.ExpectedException(
                    () => dir2.Create(),
                    "Try to create directory hierarchy by specifying prefix",
                    HttpStatusCode.NotFound);

                dir1.Create();
                dir2.Create();
            }
            finally
            {
                share.Delete();
            }
        }
        public void CloudFileShareExistsAPM()
        {
            CloudFileShare share  = GetRandomShareReference();
            CloudFileShare share2 = share.ServiceClient.GetShareReference(share.Name);

            using (AutoResetEvent waitHandle = new AutoResetEvent(false))
            {
                IAsyncResult result = share2.BeginExists(
                    ar => waitHandle.Set(),
                    null);
                waitHandle.WaitOne();
                Assert.IsFalse(share2.EndExists(result));

                share.Create();

                try
                {
                    result = share2.BeginExists(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    Assert.IsTrue(share2.EndExists(result));
                    Assert.IsNotNull(share2.Properties.ETag);
                }
                finally
                {
                    share.Delete();
                }

                result = share2.BeginExists(
                    ar => waitHandle.Set(),
                    null);
                waitHandle.WaitOne();
                Assert.IsFalse(share2.EndExists(result));
            }
        }