private void DoCloudQueueAddUpdateEncryptedMessageAPM(IKey key, DictionaryKeyResolver keyResolver) { CloudQueueClient client = GenerateCloudQueueClient(); CloudQueue queue = client.GetQueueReference(GenerateNewQueueName()); try { queue.CreateIfNotExists(); string messageStr = Guid.NewGuid().ToString(); CloudQueueMessage message = new CloudQueueMessage(messageStr); QueueEncryptionPolicy policy = new QueueEncryptionPolicy(key, null); QueueRequestOptions createOptions = new QueueRequestOptions() { EncryptionPolicy = policy }; using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { // Add message IAsyncResult result = queue.BeginAddMessage(message, null, null, createOptions, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); queue.EndAddMessage(result); policy = new QueueEncryptionPolicy(null, keyResolver); QueueRequestOptions retrieveOptions = new QueueRequestOptions() { EncryptionPolicy = policy }; // Retrieve message result = queue.BeginGetMessage(null, retrieveOptions, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); CloudQueueMessage retrMessage = queue.EndGetMessage(result); Assert.AreEqual(messageStr, retrMessage.AsString); // Update message string updatedMessage = Guid.NewGuid().ToString("N"); retrMessage.SetMessageContent(updatedMessage); result = queue.BeginUpdateMessage(retrMessage, TimeSpan.FromSeconds(0), MessageUpdateFields.Content | MessageUpdateFields.Visibility, createOptions, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); queue.EndUpdateMessage(result); // Retrieve updated message result = queue.BeginGetMessage(null, retrieveOptions, null, ar => waitHandle.Set(), null); waitHandle.WaitOne(); retrMessage = queue.EndGetMessage(result); Assert.AreEqual(updatedMessage, retrMessage.AsString); } } finally { queue.DeleteIfExists(); } }