public void CloudFileClientListSharesSegmentedPrefixContinuationToken() { int shareCount = 3; string shareNamePrefix = GetRandomShareName(); List <string> shareNames = new List <string>(shareCount); CloudFileClient fileClient = GenerateCloudFileClient(); string prefix = shareNamePrefix; FileContinuationToken continuationToken = null; try { for (int i = 0; i < shareCount; ++i) { string shareName = shareNamePrefix + i.ToString(); shareNames.Add(shareName); fileClient.GetShareReference(shareName).CreateAsync().Wait(); } int totalCount = 0; do { ShareResultSegment resultSegment = fileClient.ListSharesSegmentedAsync(prefix, continuationToken).Result; continuationToken = resultSegment.ContinuationToken; foreach (CloudFileShare share in resultSegment.Results) { if (shareNames.Contains(share.Name)) { ++totalCount; } } }while (continuationToken != null); Assert.AreEqual(shareCount, totalCount); } finally { foreach (string shareName in shareNames) { fileClient.GetShareReference(shareName).DeleteAsync().Wait(); } } }
public void CloudFileClientListSharesSegmentedAPM() { 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); fileClient.GetShareReference(shareName).Create(); } List <string> listedShareNames = new List <string>(); FileContinuationToken token = null; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { IAsyncResult result; do { result = fileClient.BeginListSharesSegmented(token, ar => waitHandle.Set(), null); waitHandle.WaitOne(); ShareResultSegment resultSegment = fileClient.EndListSharesSegmented(result); token = resultSegment.ContinuationToken; foreach (CloudFileShare share in resultSegment.Results) { listedShareNames.Add(share.Name); } }while (token != null); foreach (string shareName in listedShareNames) { if (shareNames.Remove(shareName)) { fileClient.GetShareReference(shareName).Delete(); } } Assert.AreEqual(0, shareNames.Count); } }
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); }
public void CloudFileClientListSharesSegmented() { AssertSecondaryEndpoint(); 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); fileClient.GetShareReference(shareName).Create(); } List <string> listedShareNames = new List <string>(); FileContinuationToken token = null; do { ShareResultSegment resultSegment = fileClient.ListSharesSegmented(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)) { fileClient.GetShareReference(shareName).Delete(); } } Assert.AreEqual(0, shareNames.Count); }
public async Task CloudFileShareSetMetadataAsync() { CloudFileShare share = GetRandomShareReference(); try { await share.CreateAsync(); CloudFileShare share2 = share.ServiceClient.GetShareReference(share.Name); await share2.FetchAttributesAsync(); Assert.AreEqual(0, share2.Metadata.Count); share.Metadata.Add("key1", "value1"); await share.SetMetadataAsync(); await share2.FetchAttributesAsync(); Assert.AreEqual(1, share2.Metadata.Count); Assert.AreEqual("value1", share2.Metadata["key1"]); ShareResultSegment results = await share.ServiceClient.ListSharesSegmentedAsync(share.Name, ShareListingDetails.Metadata, null, null, null, null); CloudFileShare share3 = results.Results.First(); Assert.AreEqual(1, share3.Metadata.Count); Assert.AreEqual("value1", share3.Metadata["key1"]); share.Metadata.Clear(); await share.SetMetadataAsync(); await share2.FetchAttributesAsync(); Assert.AreEqual(0, share2.Metadata.Count); } finally { share.DeleteIfExistsAsync().Wait(); } }
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(); } }
public void CloudFileClientListSharesSegmentedTask() { 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); fileClient.GetShareReference(shareName).CreateAsync().Wait(); } List <string> listedShareNames = new List <string>(); FileContinuationToken token = null; do { ShareResultSegment resultSegment = fileClient.ListSharesSegmentedAsync(token).Result; token = resultSegment.ContinuationToken; foreach (CloudFileShare share in resultSegment.Results) { listedShareNames.Add(share.Name); } }while (token != null); foreach (string shareName in listedShareNames) { if (shareNames.Remove(shareName)) { fileClient.GetShareReference(shareName).DeleteAsync().Wait(); } } Assert.AreEqual(0, shareNames.Count); }
public void CloudFileClientListSharesWithPrefixSegmented2() { 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); fileClient.GetShareReference(shareName).Create(); } List <string> listedShareNames = new List <string>(); FileContinuationToken token = null; do { ShareResultSegment resultSegment = fileClient.ListSharesSegmented(name, token); token = resultSegment.ContinuationToken; int count = 0; foreach (CloudFileShare share in resultSegment.Results) { count++; listedShareNames.Add(share.Name); } }while (token != null); Assert.AreEqual(shareNames.Count, listedShareNames.Count); foreach (string shareName in listedShareNames) { Assert.IsTrue(shareNames.Remove(shareName)); fileClient.GetShareReference(shareName).Delete(); } Assert.AreEqual(0, shareNames.Count); }
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"]); 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(); }