示例#1
0
        public async Task CloudFileClientListSharesSegmentedAsync()
        {
            string                name                  = GetRandomShareName();
            List <string>         shareNames            = new List <string>();
            DelegatingHandlerImpl delegatingHandlerImpl = new DelegatingHandlerImpl(new DelegatingHandlerImpl());
            CloudFileClient       fileClient            = GenerateCloudFileClient(delegatingHandlerImpl);

            for (int i = 0; i < 3; i++)
            {
                string shareName = name + i.ToString();
                shareNames.Add(shareName);
                await fileClient.GetShareReference(shareName).CreateAsync();
            }

            List <string>         listedShareNames = new List <string>();
            FileContinuationToken token            = null;

            do
            {
                ShareResultSegment resultSegment = await fileClient.ListSharesSegmentedAsync(token);

                token = resultSegment.ContinuationToken;

                foreach (CloudFileShare share in resultSegment.Results)
                {
                    Assert.IsTrue(fileClient.GetShareReference(share.Name).StorageUri.Equals(share.StorageUri));
                    listedShareNames.Add(share.Name);
                }
            }while (token != null);

            foreach (string shareName in listedShareNames)
            {
                if (shareNames.Remove(shareName))
                {
                    await fileClient.GetShareReference(shareName).DeleteAsync();
                }
            }

            Assert.AreEqual(0, shareNames.Count);
            Assert.AreNotEqual(0, delegatingHandlerImpl.CallCount);
        }
示例#2
0
        public async Task CloudFileClientListSharesSegmentedWithPrefixAsync()
        {
            string          name       = GetRandomShareName();
            List <string>   shareNames = new List <string>();
            CloudFileClient fileClient = GenerateCloudFileClient();

            for (int i = 0; i < 3; i++)
            {
                string shareName = name + i.ToString();
                shareNames.Add(shareName);
                await fileClient.GetShareReference(shareName).CreateAsync();
            }

            List <string>         listedShareNames = new List <string>();
            FileContinuationToken token            = null;

            do
            {
                ShareResultSegment resultSegment = await fileClient.ListSharesSegmentedAsync(name, ShareListingDetails.None, 1, token, null, null);

                token = resultSegment.ContinuationToken;

                int count = 0;
                foreach (CloudFileShare share in resultSegment.Results)
                {
                    count++;
                    listedShareNames.Add(share.Name);
                }
                Assert.IsTrue(count <= 1);
            }while (token != null);

            Assert.AreEqual(shareNames.Count, listedShareNames.Count);
            foreach (string shareName in listedShareNames)
            {
                Assert.IsTrue(shareNames.Remove(shareName));
                await fileClient.GetShareReference(shareName).DeleteAsync();
            }
        }
示例#3
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();
        }