Beispiel #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();
        }
        public async Task CloudFileDirectoryCloseHandleTask()
        {
            // TODO add non-zero test cases if OpenHandle is ever available over REST
            CloudFileShare share = GetRandomShareReference();

            try
            {
                await share.CreateAsync();

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

                share = await share.SnapshotAsync();

                dir = share.GetRootDirectoryReference().GetDirectoryReference("mydir");;

                FileContinuationToken token    = null;
                int          handlesClosed     = 0;
                const string nonexistentHandle = "12345";

                do
                {
                    CloseFileHandleResultSegment response = await dir.CloseHandleSegmentedAsync(nonexistentHandle, token);

                    handlesClosed += response.NumHandlesClosed;
                    token          = response.ContinuationToken;
                } while (token != null && token.NextMarker != null);

                Assert.AreEqual(handlesClosed, 0);
            }
            finally
            {
                await share.DeleteIfExistsAsync();
            }
        }
        public async Task CloudFileDirectoryListHandlesNullCaseTask()
        {
            // TODO add non-zero test cases if OpenHandle is ever available over REST
            CloudFileShare share = GetRandomShareReference();

            try
            {
                await share.CreateAsync();

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

                share = await share.SnapshotAsync();

                dir = share.GetRootDirectoryReference().GetDirectoryReference("mydir");

                FileContinuationToken token   = null;
                List <FileHandle>     handles = new List <FileHandle>();

                do
                {
                    FileHandleResultSegment response = await dir.ListHandlesSegmentedAsync(token, null, null, null, null, null, CancellationToken.None);

                    handles.AddRange(response.Results);
                    token = response.ContinuationToken;
                } while (token.NextMarker != null);

                Assert.AreEqual(0, handles.Count);
            }
            finally
            {
                await share.DeleteIfExistsAsync();
            }
        }
Beispiel #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();
        }
Beispiel #5
0
        public async Task CloudFileListSharesWithSnapshotAsync()
        {
            CloudFileShare share = GetRandomShareReference();
            await share.CreateAsync();

            share.Metadata["key1"] = "value1";
            await share.SetMetadataAsync();

            CloudFileShare snapshot = await share.SnapshotAsync();

            share.Metadata["key2"] = "value2";
            await share.SetMetadataAsync();

            CloudFileClient       client       = GenerateCloudFileClient();
            List <CloudFileShare> listedShares = new List <CloudFileShare>();
            FileContinuationToken token        = null;

            do
            {
                ShareResultSegment resultSegment = await client.ListSharesSegmentedAsync(share.Name, ShareListingDetails.All, null, token, null, null);

                token = resultSegment.ContinuationToken;

                foreach (CloudFileShare listResultShare in resultSegment.Results)
                {
                    listedShares.Add(listResultShare);
                }
            }while (token != null);

            int  count         = 0;
            bool originalFound = false;
            bool snapshotFound = false;

            foreach (CloudFileShare listShareItem in listedShares)
            {
                if (listShareItem.Name.Equals(share.Name) && !listShareItem.IsSnapshot && !originalFound)
                {
                    count++;
                    originalFound = true;
                    Assert.AreEqual(2, listShareItem.Metadata.Count);
                    Assert.AreEqual("value2", listShareItem.Metadata["key2"]);
                    // Metadata keys should be case-insensitive
                    Assert.AreEqual("value2", listShareItem.Metadata["KEY2"]);
                    Assert.AreEqual("value1", listShareItem.Metadata["key1"]);
                    Assert.AreEqual(share.StorageUri, listShareItem.StorageUri);
                }
                else if (listShareItem.Name.Equals(share.Name) &&
                         listShareItem.IsSnapshot && !snapshotFound)
                {
                    count++;
                    snapshotFound = true;
                    Assert.AreEqual(1, listShareItem.Metadata.Count);
                    Assert.AreEqual("value1", listShareItem.Metadata["key1"]);
                    Assert.AreEqual(snapshot.StorageUri, listShareItem.StorageUri);
                }
            }

            Assert.AreEqual(2, count);

            await snapshot.DeleteAsync();

            await share.DeleteAsync();
        }