Esempio n. 1
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();
        }
Esempio n. 2
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();
            }
        }
        public async Task TestFileDirectoryEncryptionAsync()
        {
            bool requestFound = false;

            OperationContext ctxt  = new OperationContext();
            CloudFileShare   share = GetRandomShareReference();

            try
            {
                await share.CreateIfNotExistsAsync();

                ctxt.RequestCompleted += (sender, args) =>
                {
                    Assert.IsTrue(args.RequestInformation.IsRequestServerEncrypted);
                    requestFound = true;
                };

                CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference("dir");

                await directory.CreateAsync(null, ctxt);

                Assert.IsTrue(requestFound);

                requestFound = false;
                await directory.SetMetadataAsync(null, null, ctxt);

                Assert.IsTrue(requestFound);
            }
            finally
            {
                share.DeleteIfExistsAsync().Wait();
            }
        }
Esempio n. 4
0
        public async Task CloudFileDirectoryApisInvalidApisInShareSnapshotAsync()
        {
            CloudFileShare share = GetRandomShareReference();
            await share.CreateAsync();

            CloudFileShare snapshot = await share.SnapshotAsync();

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

            try
            {
                dir.CreateAsync().Wait();
                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                dir.DeleteAsync().Wait();
                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                dir.SetMetadataAsync(null, null, null).Wait();
                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }

            snapshot.DeleteAsync().Wait();
            share.DeleteAsync().Wait();
        }