Пример #1
0
        public async Task CloudFileDirectorySetMetadataAsync()
        {
            CloudFileShare share = GetRandomShareReference();

            try
            {
                await share.CreateAsync();

                CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference("directory1");
                await directory.CreateAsync();

                CloudFileDirectory directory2 = share.GetRootDirectoryReference().GetDirectoryReference("directory1");
                await directory2.FetchAttributesAsync();

                Assert.AreEqual(0, directory2.Metadata.Count);

                directory.Metadata["key1"] = null;
                OperationContext context = new OperationContext();
                await TestHelper.ExpectedExceptionAsync(
                    async() => await directory.SetMetadataAsync(null /* accessConditions */, null /* options */, context),
                    context,
                    "Metadata keys should have a non-null value",
                    HttpStatusCode.Unused);

                directory.Metadata["key1"] = "";
                await TestHelper.ExpectedExceptionAsync(
                    async() => await directory.SetMetadataAsync(null /* accessConditions */, null /* options */, context),
                    context,
                    "Metadata keys should have a non-empty value",
                    HttpStatusCode.Unused);

                directory.Metadata["key1"] = "value1";
                await directory.SetMetadataAsync(null /* accessConditions */, null /* options */, context);

                await directory2.FetchAttributesAsync();

                Assert.AreEqual(1, directory2.Metadata.Count);
                Assert.AreEqual("value1", directory2.Metadata["key1"]);

                directory.Metadata.Clear();
                await directory.SetMetadataAsync(null /* accessConditions */, null /* options */, context);

                await directory2.FetchAttributesAsync();

                Assert.AreEqual(0, directory2.Metadata.Count);
            }
            finally
            {
                share.DeleteIfExistsAsync().Wait();
            }
        }
Пример #2
0
        public async Task CloudFileDirectorySASAsync()
        {
            CloudFileDirectory dir  = this.testShare.GetRootDirectoryReference().GetDirectoryReference("dirfile");
            CloudFile          file = dir.GetFileReference("dirfile");

            await dir.CreateAsync();

            await file.CreateAsync(512);

            SharedAccessFilePolicy policy = new SharedAccessFilePolicy()
            {
                SharedAccessStartTime  = DateTimeOffset.UtcNow.AddMinutes(-5),
                SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                Permissions            = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.List
            };

            string             sasToken = file.GetSharedAccessSignature(policy);
            CloudFileDirectory sasDir   = new CloudFileDirectory(new Uri(dir.Uri.AbsoluteUri + sasToken));
            OperationContext   context  = new OperationContext();
            await TestHelper.ExpectedExceptionAsync(
                async() => await sasDir.FetchAttributesAsync(null /* accessCondition */, null /* options */, context),
                context,
                "Fetching attributes of a directory using a file SAS should fail",
                HttpStatusCode.Forbidden,
                "");

            sasToken = this.testShare.GetSharedAccessSignature(policy);
            sasDir   = new CloudFileDirectory(new Uri(dir.Uri.AbsoluteUri + sasToken));
            await sasDir.FetchAttributesAsync();
        }
Пример #3
0
        public async Task CloudFileDirectoryApisInShareSnapshotAsync()
        {
            CloudFileShare share = GetRandomShareReference();
            await share.CreateAsync();

            CloudFileDirectory dir = share.GetRootDirectoryReference().GetDirectoryReference("dir1");
            await dir.CreateAsync();

            dir.Metadata["key1"] = "value1";
            await dir.SetMetadataAsync(null, null, null);

            CloudFileShare snapshot = await share.SnapshotAsync();

            CloudFileDirectory snapshotDir = snapshot.GetRootDirectoryReference().GetDirectoryReference("dir1");

            dir.Metadata["key2"] = "value2";
            await dir.SetMetadataAsync(null, null, null);

            await snapshotDir.FetchAttributesAsync();

            Assert.IsTrue(snapshotDir.Metadata.Count == 1 && snapshotDir.Metadata["key1"].Equals("value1"));
            Assert.IsNotNull(snapshotDir.Properties.ETag);

            await dir.FetchAttributesAsync();

            Assert.IsTrue(dir.Metadata.Count == 2 && dir.Metadata["key2"].Equals("value2"));
            Assert.IsNotNull(dir.Properties.ETag);
            Assert.AreNotEqual(dir.Properties.ETag, snapshotDir.Properties.ETag);

            await snapshot.DeleteAsync();

            await share.DeleteAsync();
        }
 public Task FetchDirectoryAttributesAsync(CloudFileDirectory directory, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken token)
 {
     return directory.FetchAttributesAsync(accessCondition, options, operationContext, token);
 }
Пример #5
0
        public async Task CloudFileDirectorySASAsync()
        {
            CloudFileDirectory dir = this.testShare.GetRootDirectoryReference().GetDirectoryReference("dirfile");
            CloudFile file = dir.GetFileReference("dirfile");

            await dir.CreateAsync();
            await file.CreateAsync(512);

            SharedAccessFilePolicy policy = new SharedAccessFilePolicy()
            {
                SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.List
            };

            string sasToken = file.GetSharedAccessSignature(policy);
            CloudFileDirectory sasDir = new CloudFileDirectory(new Uri(dir.Uri.AbsoluteUri + sasToken));
            OperationContext context = new OperationContext();
            await TestHelper.ExpectedExceptionAsync(
                async () => await sasDir.FetchAttributesAsync(null /* accessCondition */, null /* options */, context),
                context,
                "Fetching attributes of a directory using a file SAS should fail",
                HttpStatusCode.Forbidden,
                "");

            sasToken = this.testShare.GetSharedAccessSignature(policy);
            sasDir = new CloudFileDirectory(new Uri(dir.Uri.AbsoluteUri + sasToken));
            await sasDir.FetchAttributesAsync();
        }