public void Dispose() { foreach (var testqueue in _queueClient.ListQueuesSegmentedAsync(TestArtifactPrefix, null).Result.Results) { testqueue.DeleteAsync().Wait(); } }
private async Task Clean() { CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); var queuesResult = await queueClient.ListQueuesSegmentedAsync(TestArtifactsPrefix, null); foreach (var queue in queuesResult.Results) { await queue.DeleteAsync(); } CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer hostContainer = blobClient.GetContainerReference("azure-webjobs-hosts"); var blobs = await hostContainer.ListBlobsSegmentedAsync(string.Format("locks/{0}", TestHostId), useFlatBlobListing : true, blobListingDetails : BlobListingDetails.None, maxResults : null, currentToken : null, options : null, operationContext : null); foreach (CloudBlockBlob lockBlob in blobs.Results) { try { await lockBlob.DeleteAsync(); } catch (StorageException) { // best effort - might fail if there is an active // lease on the blob } } }
private async Task Copy(CloudQueueClient sourceClient, IHydra target, CancellationToken token) { var response = await sourceClient.ListQueuesSegmentedAsync(null); do { foreach (var sourceItem in response.Results.Where(x => string.IsNullOrWhiteSpace(Options.Object) || x.Name.EqualsCi(Options.Object))) { _logger.LogInformation($"Processing {sourceItem.GetType().Name} '{sourceItem.Name}'."); var targetClient = target.CreateQueueClient(sourceItem.Name); var targetItem = targetClient.GetQueueReference(sourceItem.Name); await _policyCreate.ExecuteAsync(async() => await targetItem.CreateIfNotExistsAsync()); } response = await sourceClient.ListQueuesSegmentedAsync(response.ContinuationToken); }while (response.ContinuationToken != null && !token.IsCancellationRequested); }
private async Task Clear(CloudQueueClient target, CancellationToken token) { var response = await target.ListQueuesSegmentedAsync(null); do { foreach (var sourceItem in response.Results.Where(x => string.IsNullOrWhiteSpace(Options.Object) || x.Name.EqualsCi(Options.Object))) { var targetItem = target.GetQueueReference(sourceItem.Name); _logger.LogInformation($"Deleting {sourceItem.GetType().Name} '{sourceItem.Name}'..."); await targetItem.DeleteAsync(); } response = await target.ListQueuesSegmentedAsync(response.ContinuationToken); }while (response.ContinuationToken != null && !token.IsCancellationRequested); }
public static async Task <List <CloudQueue> > ListQueuesAsync(this CloudQueueClient client) { QueueContinuationToken continuationToken = null; List <CloudQueue> results = new List <CloudQueue>(); do { var response = await client.ListQueuesSegmentedAsync(continuationToken); continuationToken = response.ContinuationToken; results.AddRange(response.Results); }while (continuationToken != null); return(results); }
public void Dispose() { _functionStarted.Dispose(); _functionCompleted.Dispose(); if (_storageAccount != null) { CloudQueueClient queueClient = _storageAccount.CreateCloudQueueClient(); foreach (var testQueue in queueClient.ListQueuesSegmentedAsync(TestArtifactPrefix, null).Result.Results) { testQueue.DeleteAsync().Wait(); } } }
/// <summary> /// List storage queues /// </summary> /// <param name="prefix">Queue name prefix</param> /// <param name="queueListingDetails">Queue listing details</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> /// <returns>An enumerable collection of the queues in the storage account.</returns> public IEnumerable <CloudQueue> ListQueues(string prefix, QueueListingDetails queueListingDetails, QueueRequestOptions options, OperationContext operationContext) { //https://ahmet.im/blog/azure-listblobssegmentedasync-listcontainerssegmentedasync-how-to/ QueueContinuationToken continuationToken = null; var results = new List <CloudQueue>(); do { var response = queueClient.ListQueuesSegmentedAsync(prefix, queueListingDetails, null, continuationToken, options, operationContext).Result; continuationToken = response.ContinuationToken; results.AddRange(response.Results); } while (continuationToken != null); return(results); }
public void Dispose() { CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient(); foreach (var testContainer in blobClient.ListContainersSegmentedAsync(TestArtifactsPrefix, null).Result.Results) { testContainer.DeleteAsync().Wait(); } CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient(); foreach (var testQueue in queueClient.ListQueuesSegmentedAsync(TestArtifactsPrefix, null).Result.Results) { testQueue.DeleteAsync().Wait(); } }
public static async Task <List <CloudQueue> > ListFreeQueues() { // list the queues in the account var queues = new List <CloudQueue>(); QueueContinuationToken continuationToken = null; do { var segment = await QueueClient.ListQueuesSegmentedAsync("free-", continuationToken); queues.AddRange(segment.Results); continuationToken = segment.ContinuationToken; } while (continuationToken != null); return(queues); }
public static async Task <List <string> > ListQueuesAsync(string account, string key) { CloudQueueClient queueClient = Client.GetQueueClient(account, key); QueueContinuationToken continuationToken = null; List <CloudQueue> results = new List <CloudQueue>(); do { var response = await queueClient.ListQueuesSegmentedAsync(continuationToken); continuationToken = response.ContinuationToken; results.AddRange(response.Results); }while (continuationToken != null); return(results.Select(t => t.Name).ToList()); }
public async Task <IReadOnlyCollection <string> > ListChannelsAsync(CancellationToken cancellationToken = default) { var queueNames = new List <string>(); QueueContinuationToken token = null; do { QueueResultSegment page = await _client.ListQueuesSegmentedAsync(token).ConfigureAwait(false); queueNames.AddRange(page.Results.Select(q => q.Name)); token = page.ContinuationToken; }while(token != null); return(queueNames); }
private async static Task Clean(StorageAccount account) { CloudBlobClient blobClient = account.CreateCloudBlobClient(); foreach (var testContainer in (await blobClient.ListContainersSegmentedAsync(TestArtifactPrefix, null)).Results) { await testContainer.DeleteAsync(); } CloudTableClient tableClient = account.CreateCloudTableClient(); foreach (var table in await tableClient.ListTablesSegmentedAsync(TestArtifactPrefix, null)) { await table.DeleteAsync(); } CloudQueueClient queueClient = account.CreateCloudQueueClient(); foreach (var queue in (await queueClient.ListQueuesSegmentedAsync(TestArtifactPrefix, null)).Results) { await queue.DeleteAsync(); } }
/// <summary> /// Create, list and delete queues /// </summary> /// <param name="cloudQueueClient"></param> /// <returns></returns> private static async Task ListQueuesSample(CloudQueueClient cloudQueueClient) { // Create 3 queues. // Create the queue name -- use a guid in the name so it's unique. string baseQueueName = "demotest-" + System.Guid.NewGuid().ToString(); // Keep a list of the queues so you can compare this list // against the list of queues that we retrieve. List <string> queueNames = new List <string>(); for (int i = 0; i < 3; i++) { // Set the name of the queue, then add it to the generic list. string queueName = baseQueueName + "-0" + i; queueNames.Add(queueName); // Create the queue with this name. Console.WriteLine("Creating queue with name {0}", queueName); CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(queueName); try { await cloudQueue.CreateIfNotExistsAsync(); Console.WriteLine(" Queue created successfully."); } catch (StorageException exStorage) { Common.WriteException(exStorage); Console.WriteLine( "Please make sure your storage account is specified correctly in the app.config - then restart the sample."); Console.WriteLine("Press any key to exit"); Console.ReadLine(); throw; } catch (Exception ex) { Console.WriteLine(" Exception thrown creating queue."); Common.WriteException(ex); throw; } } Console.WriteLine(string.Empty); Console.WriteLine("List of queues in the storage account:"); // List the queues for this storage account QueueContinuationToken token = null; List <CloudQueue> cloudQueueList = new List <CloudQueue>(); do { QueueResultSegment segment = await cloudQueueClient.ListQueuesSegmentedAsync(baseQueueName, token); token = segment.ContinuationToken; cloudQueueList.AddRange(segment.Results); }while (token != null); try { foreach (CloudQueue cloudQ in cloudQueueList) { Console.WriteLine("Cloud Queue name = {0}", cloudQ.Name); } } catch (Exception ex) { Console.WriteLine(" Exception thrown listing queues."); Common.WriteException(ex); throw; } // Now clean up after yourself, using the list of queues that you created in case there were other queues in the account. foreach (string oneQueueName in queueNames) { CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(oneQueueName); cloudQueue.DeleteIfExists(); } }
public async Task RunQueueStorageOperationsAsync() { // string queueName = "queue-" + System.Guid.NewGuid().ToString(); string queueName = "queue"; Console.WriteLine(); CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(Microsoft.Azure.CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference(queueName); try { await queue.CreateIfNotExistsAsync(); } catch { Console.WriteLine("If you are running with the default configuration please make sure you have started the storage emulator. Press the Windows key and type Azure Storage to select and run it from the list of applications - then restart the sample."); Console.ReadLine(); throw; } Console.WriteLine("QUEUE created with NAME : " + queue.Name.ToString() + "\n"); Console.WriteLine("*** MENU ***"); Console.WriteLine("1 : Insert a message into a queue"); Console.WriteLine("2 : See messages in a queue"); Console.WriteLine("3 : De-queue the next message"); Console.WriteLine("4 : Change the contents of a queued message"); Console.WriteLine("5 : Enqueue a limited number of messages"); Console.WriteLine("6 : Get the queue length"); Console.WriteLine("7 : Delete the Queue"); Console.WriteLine("8 : listing and comparing queues "); Console.WriteLine("9 : Get Service Properties of Queue"); Console.WriteLine("10 : adding and restoring CORS rules sample"); Console.WriteLine("11 : QUEUE MetaData"); Console.WriteLine("12 : exit app"); var selectedValue = Console.ReadLine(); Regex regex = new Regex("^[0-9]+$"); if (regex.IsMatch(selectedValue.ToString())) { int selection = Convert.ToInt32(selectedValue); while (selection != 0) { switch (selection) { case 1: //Insert a message into a queue Console.WriteLine("Enter a message"); await queue.AddMessageAsync(new CloudQueueMessage(Console.ReadLine())); break; case 2: //Peek messages in a queue CloudQueueMessage peekedMessage = await queue.PeekMessageAsync(); if (peekedMessage != null) { Console.WriteLine("The peeked message is: {0}", peekedMessage.AsString); } else { Console.WriteLine("No messages exist"); } break; case 3: //De-queue the next message CloudQueueMessage message = await queue.GetMessageAsync(); if (message != null) { Console.WriteLine("Processing & deleting message with content: {0}", message.AsString); await queue.DeleteMessageAsync(message); } else { Console.WriteLine("No messages exist"); } break; case 4: //Change the contents of a queued message CloudQueueMessage message1 = await queue.GetMessageAsync(); if (message1 != null) { Console.WriteLine("Enter content to be updated !"); message1.SetMessageContent(Console.ReadLine().ToString()); await queue.UpdateMessageAsync(message1, TimeSpan.Zero, MessageUpdateFields.Content | MessageUpdateFields.Visibility); CloudQueueMessage peekedMessage1 = await queue.PeekMessageAsync(); if (peekedMessage1 != null) { Console.WriteLine("The modified message is: {0}", peekedMessage1.AsString); } } else { Console.WriteLine("No messages exist"); } break; case 5: //Enqueue a limited number of messages Console.WriteLine("Input the count of the messages : "); var messageCount = Console.ReadLine(); if (regex.IsMatch(messageCount.ToString())) { for (int i = 0; i < Convert.ToInt32(messageCount); i++) { Console.WriteLine("Enter the message no : " + i); var newMsg = Console.ReadLine(); await queue.AddMessageAsync(new CloudQueueMessage(newMsg)); } } else { Console.WriteLine("Please Input a number"); } break; case 6: //Get the queue length queue.FetchAttributes(); int? count = queue.ApproximateMessageCount; if (count != null && count > 0) { Console.WriteLine("Message count = " + count); } else { Console.WriteLine("No messages exist"); } break; case 7: //Delete the Queue await queue.DeleteIfExistsAsync(); Console.WriteLine("Queue deleted !!"); break; case 8: //listing and comparing queues Console.WriteLine("Enter the no of queues u want to create"); var queueCount = Console.ReadLine(); List<string> lstQueueNames = new List<string>(); if (regex.IsMatch(queueCount.ToString())) { for (int i = 0; i < Convert.ToInt32(queueCount); i++) { string qName = queueName + "-ls-" + i; lstQueueNames.Add(qName); CloudQueue cloudQueue = queueClient.GetQueueReference(queueName); try { await cloudQueue.CreateIfNotExistsAsync(); } catch (StorageException exStorage) { Common.WriteException(exStorage); Console.WriteLine( "Please make sure your storage account is specified correctly in the app.config - then restart the sample."); Console.WriteLine("Press any key to exit"); Console.ReadLine(); throw; } catch (Exception ex) { Console.WriteLine(" Exception thrown while creating queue."); Common.WriteException(ex); throw; } } QueueContinuationToken queueContinuationToken = null; List<CloudQueue> lstCloudQueues = new List<CloudQueue>(); do { QueueResultSegment queueResultSegment = await queueClient.ListQueuesSegmentedAsync(queueName, queueContinuationToken); queueContinuationToken = queueResultSegment.ContinuationToken; lstCloudQueues.AddRange(queueResultSegment.Results); } while (queueContinuationToken != null); foreach (string qNames in lstQueueNames) { CloudQueue cloudQueue = queueClient.GetQueueReference(qNames); cloudQueue.DeleteIfExists(); } } else { Console.WriteLine("Enter a numeric value"); } break; case 9: // get the service properties - sample only ServiceProperties orignalServiceProperties = await queueClient.GetServicePropertiesAsync(); Console.WriteLine("Original service properties :"); Console.WriteLine("Logging operations : " + orignalServiceProperties.Logging.LoggingOperations); Console.WriteLine("Logging RetentionDays : " + orignalServiceProperties.Logging.RetentionDays); Console.WriteLine("Logging Version : " + orignalServiceProperties.Logging.Version); Console.WriteLine("HourMetrics MetricsLevel : " + orignalServiceProperties.HourMetrics.MetricsLevel); Console.WriteLine("HourMetrics Retention Days : " + orignalServiceProperties.HourMetrics.RetentionDays); Console.WriteLine("HourMetrics Version : " + orignalServiceProperties.HourMetrics.Version); Console.WriteLine("MinuteMetrics MetricsLevel : " + orignalServiceProperties.MinuteMetrics.MetricsLevel); Console.WriteLine("MinuteMetrics Retention Days : " + orignalServiceProperties.MinuteMetrics.RetentionDays); Console.WriteLine("MinuteMetrics Version : " + orignalServiceProperties.MinuteMetrics.Version); try { Console.WriteLine(); Console.WriteLine("After changing values"); //change the service properties ServiceProperties serviceProperties = await queueClient.GetServicePropertiesAsync(); serviceProperties.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write; serviceProperties.Logging.RetentionDays = 10; serviceProperties.Logging.Version = Constants.AnalyticsConstants.LoggingVersionV1; serviceProperties.HourMetrics.MetricsLevel = MetricsLevel.Service; serviceProperties.HourMetrics.RetentionDays = 10; serviceProperties.HourMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1; serviceProperties.MinuteMetrics.MetricsLevel = MetricsLevel.Service; serviceProperties.MinuteMetrics.RetentionDays = 10; serviceProperties.MinuteMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1; await queueClient.SetServicePropertiesAsync(serviceProperties); Console.WriteLine("Logging operations : " + serviceProperties.Logging.LoggingOperations); Console.WriteLine("Logging RetentionDays : " + serviceProperties.Logging.RetentionDays); Console.WriteLine("Logging Version : " + serviceProperties.Logging.Version); Console.WriteLine("HourMetrics MetricsLevel : " + serviceProperties.HourMetrics.MetricsLevel); Console.WriteLine("HourMetrics Retention Days : " + serviceProperties.HourMetrics.RetentionDays); Console.WriteLine("HourMetrics Version : " + serviceProperties.HourMetrics.Version); Console.WriteLine("MinuteMetrics MetricsLevel : " + serviceProperties.MinuteMetrics.MetricsLevel); Console.WriteLine("MinuteMetrics Retention Days : " + serviceProperties.MinuteMetrics.RetentionDays); Console.WriteLine("MinuteMetrics Version : " + serviceProperties.MinuteMetrics.Version); } finally { await queueClient.SetServicePropertiesAsync(orignalServiceProperties); } break; case 10: //adding and restoring CORS rules ServiceProperties orignalServicePropertiesCors = await queueClient.GetServicePropertiesAsync(); Console.WriteLine("Original service properties :"); Console.WriteLine("existing CORS count :" + orignalServicePropertiesCors.Cors.CorsRules.Count); try { Console.WriteLine(); Console.WriteLine("adding CORS Rules"); Console.WriteLine("AllowedHeaders = any"); Console.WriteLine("AllowedMethods = Get"); Console.WriteLine("AllowedOrigins = any"); Console.WriteLine("ExposedHeaders = any"); Console.WriteLine("MaxAgeInSeconds = 3600"); // * for any CorsRule corsRule = new CorsRule { AllowedHeaders = new List<string> { "*" }, AllowedMethods = CorsHttpMethods.Get, AllowedOrigins = new List<string> { "*" }, ExposedHeaders = new List<string> { "*" }, MaxAgeInSeconds = 3600 }; //change the service properties ServiceProperties serviceProperties = await queueClient.GetServicePropertiesAsync(); serviceProperties.Cors.CorsRules.Add(corsRule); Console.WriteLine("new CORS count :" + serviceProperties.Cors.CorsRules.Count); await queueClient.SetServicePropertiesAsync(serviceProperties); } finally { await queueClient.SetServicePropertiesAsync(orignalServicePropertiesCors); Console.WriteLine("restoring CORS rules :" + orignalServicePropertiesCors.Cors.CorsRules.Count); } break; case 11: //QUEUE MetaData string quName = "q-" + Guid.NewGuid(); Console.WriteLine("Setting queue metadata"); queue.Metadata.Add("key1", "value1"); queue.Metadata.Add("key2", "value2"); Console.WriteLine("Creating queue with name {0}", quName); await queue.CreateIfNotExistsAsync(); await queue.FetchAttributesAsync(); Console.WriteLine("Get queue metadata:"); foreach (var keyValue in queue.Metadata) { Console.WriteLine(" {0}: {1}", keyValue.Key, keyValue.Value); } Console.WriteLine("Deleting queue with name {0}", quName); queue.DeleteIfExists(); break; case 12: await queue.DeleteIfExistsAsync(); Environment.Exit(0); break; default: Environment.Exit(0); break; } Console.WriteLine(); Console.WriteLine("Select another option or press 0 to exit"); var newSelection = Console.ReadLine(); if (regex.IsMatch(newSelection.ToString())) { selection = Convert.ToInt32(newSelection); } else { Console.WriteLine("Please select a number"); Console.Clear(); await RunQueueStorageOperationsAsync(); } Console.WriteLine(); } } else { Console.WriteLine("Please select a number"); Console.Clear(); await RunQueueStorageOperationsAsync(); } }
public async Task RunPermissionsTestQueues(SharedAccessAccountPolicy policy) { CloudQueueClient queueClient = GenerateCloudQueueClient(); string queueName = "q" + Guid.NewGuid().ToString("N"); try { CloudStorageAccount account = new CloudStorageAccount(queueClient.Credentials, false); string accountSASToken = account.GetSharedAccessSignature(policy); StorageCredentials accountSAS = new StorageCredentials(accountSASToken); CloudStorageAccount accountWithSAS = new CloudStorageAccount(accountSAS, null, queueClient.StorageUri, null, null); CloudQueueClient queueClientWithSAS = accountWithSAS.CreateCloudQueueClient(); CloudQueue queueWithSAS = queueClientWithSAS.GetQueueReference(queueName); CloudQueue queue = queueClient.GetQueueReference(queueName); // General pattern - If current perms support doing a thing with SAS, do the thing with SAS and validate with shared // Otherwise, make sure SAS fails and then do the thing with shared key. // Things to do: // Create the queue (Create or Write perms, Container RT) // List queues (List perms, Service RT) // Set queue metadata (Write perms, Container RT) // Insert a message (Add perms, Object RT) // Peek a message (Read perms, Object RT) // Get a message (Process perms, Object RT) // Update a message (Update perms, Object RT) // Clear all messages (Delete perms, Object RT) if ((((policy.Permissions & SharedAccessAccountPermissions.Create) == SharedAccessAccountPermissions.Create) || ((policy.Permissions & SharedAccessAccountPermissions.Write) == SharedAccessAccountPermissions.Write)) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Container) == SharedAccessAccountResourceTypes.Container)) { await queueWithSAS.CreateAsync(); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => await queueWithSAS.CreateAsync(), "Creating a queue with SAS should fail without Add and Container-level permissions."); await queue.CreateAsync(); } Assert.IsTrue(await queue.ExistsAsync()); if (((policy.Permissions & SharedAccessAccountPermissions.List) == SharedAccessAccountPermissions.List) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Service) == SharedAccessAccountResourceTypes.Service)) { Assert.AreEqual(queueName, (await queueClientWithSAS.ListQueuesSegmentedAsync(queueName, null)).Results.First().Name); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => (await queueClientWithSAS.ListQueuesSegmentedAsync(queueName, null)).Results.First(), "Listing queues with SAS should fail without Read and Service-level permissions."); } queueWithSAS.Metadata["metadatakey"] = "metadatavalue"; if (((policy.Permissions & SharedAccessAccountPermissions.Write) == SharedAccessAccountPermissions.Write) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Container) == SharedAccessAccountResourceTypes.Container)) { await queueWithSAS.SetMetadataAsync(); await queue.FetchAttributesAsync(); Assert.AreEqual("metadatavalue", queue.Metadata["metadatakey"]); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => await queueWithSAS.SetMetadataAsync(), "Setting a queue's metadata with SAS should fail without Write and Container-level permissions."); } string messageText = "messageText"; CloudQueueMessage message = new CloudQueueMessage(messageText); if (((policy.Permissions & SharedAccessAccountPermissions.Add) == SharedAccessAccountPermissions.Add) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object)) { await queueWithSAS.AddMessageAsync(message); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => await queueWithSAS.AddMessageAsync(message), "Adding a queue message should fail with SAS without Add and Object-level permissions."); await queue.AddMessageAsync(message); } Assert.AreEqual(messageText, ((await queue.PeekMessageAsync()).AsString)); if (((policy.Permissions & SharedAccessAccountPermissions.Read) == SharedAccessAccountPermissions.Read) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object)) { Assert.AreEqual(messageText, (await queueWithSAS.PeekMessageAsync()).AsString); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => await queueWithSAS.PeekMessageAsync(), "Peeking a queue message should fail with SAS without Read and Object-level permissions."); } CloudQueueMessage messageResult = null; if (((policy.Permissions & SharedAccessAccountPermissions.ProcessMessages) == SharedAccessAccountPermissions.ProcessMessages) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object)) { messageResult = await queueWithSAS.GetMessageAsync(); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => await queueWithSAS.GetMessageAsync(), "Getting a message should fail with SAS without Process and Object-level permissions."); messageResult = await queue.GetMessageAsync(); } Assert.AreEqual(messageText, messageResult.AsString); string newMessageContent = "new content"; messageResult.SetMessageContent(newMessageContent); if (((policy.Permissions & SharedAccessAccountPermissions.Update) == SharedAccessAccountPermissions.Update) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object)) { await queueWithSAS.UpdateMessageAsync(messageResult, TimeSpan.Zero, MessageUpdateFields.Content | MessageUpdateFields.Visibility); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => await queueWithSAS.UpdateMessageAsync(messageResult, TimeSpan.Zero, MessageUpdateFields.Content | MessageUpdateFields.Visibility), "Updating a message should fail with SAS without Update and Object-level permissions."); await queue.UpdateMessageAsync(messageResult, TimeSpan.Zero, MessageUpdateFields.Content | MessageUpdateFields.Visibility); } messageResult = await queue.PeekMessageAsync(); Assert.AreEqual(newMessageContent, messageResult.AsString); if (((policy.Permissions & SharedAccessAccountPermissions.Delete) == SharedAccessAccountPermissions.Delete) && ((policy.ResourceTypes & SharedAccessAccountResourceTypes.Object) == SharedAccessAccountResourceTypes.Object)) { await queueWithSAS.ClearAsync(); } else { await TestHelper.ExpectedExceptionAsync <StorageException>(async() => await queueWithSAS.ClearAsync(), "Clearing messages should fail with SAS without delete and Object-level permissions."); } } finally { queueClient.GetQueueReference(queueName).DeleteIfExistsAsync().Wait(); } }