public async Task CloudQueueSetGetMetadataAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue       queue  = client.GetQueueReference(GenerateNewQueueName());

            await queue.CreateAsync();

            CloudQueue queueToRetrieve = client.GetQueueReference(queue.Name);
            await queueToRetrieve.FetchAttributesAsync();

            Assert.AreEqual <int>(0, queueToRetrieve.Metadata.Count);

            queue.Metadata.Add("key1", "value1");
            await queue.SetMetadataAsync();

            await queueToRetrieve.FetchAttributesAsync();

            Assert.AreEqual(1, queueToRetrieve.Metadata.Count);
            Assert.AreEqual("value1", queueToRetrieve.Metadata["key1"]);

            queue.Metadata.Clear();
            await queue.SetMetadataAsync();

            await queueToRetrieve.FetchAttributesAsync();

            Assert.AreEqual <int>(0, queueToRetrieve.Metadata.Count);

            await queue.DeleteAsync();
        }
Esempio n. 2
0
        public async Task CloudQueueSetGetMetadataAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue       queue  = client.GetQueueReference(GenerateNewQueueName());

            await queue.CreateAsync();

            CloudQueue queueToRetrieve = client.GetQueueReference(queue.Name);
            await queueToRetrieve.FetchAttributesAsync();

            Assert.AreEqual <int>(0, queueToRetrieve.Metadata.Count);

            queue.Metadata.Add("key1", "value1");
            await queue.SetMetadataAsync();

            await queueToRetrieve.FetchAttributesAsync();

            Assert.AreEqual(1, queueToRetrieve.Metadata.Count);
            Assert.AreEqual("value1", queueToRetrieve.Metadata["key1"]);

            CloudQueue listedQueue = (await client.ListQueuesSegmentedAsync(queue.Name, QueueListingDetails.All, null, null, null, null)).Results.First();

            Assert.AreEqual(1, listedQueue.Metadata.Count);
            Assert.AreEqual("value1", listedQueue.Metadata["key1"]);

            queue.Metadata.Clear();
            await queue.SetMetadataAsync();

            await queueToRetrieve.FetchAttributesAsync();

            Assert.AreEqual <int>(0, queueToRetrieve.Metadata.Count);

            await queue.DeleteAsync();
        }
        public async Task CloudQueuePeekMessagesAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            string           name   = GenerateNewQueueName();
            CloudQueue       queue  = client.GetQueueReference(name);
            await queue.CreateAsync();

            int messageCount = 30;

            List <CloudQueueMessage> emptyMessages = (await queue.PeekMessagesAsync(messageCount)).ToList();

            Assert.AreEqual(0, emptyMessages.Count);

            List <string> messageContentList = new List <string>();

            for (int i = 0; i < messageCount; i++)
            {
                string            messageContent = i.ToString();
                CloudQueueMessage message        = new CloudQueueMessage(messageContent);
                await queue.AddMessageAsync(message);

                messageContentList.Add(messageContent);
            }

            List <CloudQueueMessage> receivedMessages = (await queue.PeekMessagesAsync(messageCount)).ToList();

            Assert.AreEqual(messageCount, receivedMessages.Count);

            for (int i = 0; i < messageCount; i++)
            {
                Assert.IsTrue(messageContentList.Contains(receivedMessages[i].AsString));
            }

            await queue.DeleteAsync();
        }
Esempio n. 4
0
        public async Task QueueSASTestAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue       queue  = client.GetQueueReference(GenerateNewQueueName());
            await queue.CreateAsync();

            string            messageContent = Guid.NewGuid().ToString();
            CloudQueueMessage message        = new CloudQueueMessage(messageContent);
            await queue.AddMessageAsync(message);

            // Prepare SAS authentication with full permissions
            string                       id          = Guid.NewGuid().ToString();
            DateTime                     start       = DateTime.UtcNow;
            DateTime                     expiry      = start.AddMinutes(30);
            QueuePermissions             permissions = new QueuePermissions();
            SharedAccessQueuePermissions queuePerm   = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;

            permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
            {
                SharedAccessStartTime  = start,
                SharedAccessExpiryTime = expiry,
                Permissions            = queuePerm
            });

            await queue.SetPermissionsAsync(permissions);

            await Task.Delay(30 * 1000);

            string             sasTokenFromId = queue.GetSharedAccessSignature(null, id);
            StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);

            CloudStorageAccount sasAcc    = new CloudStorageAccount(sasCredsFromId, null /* blobEndpoint */, new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint), null /* tableEndpoint */, null /* fileEndpoint */);
            CloudQueueClient    sasClient = sasAcc.CreateCloudQueueClient();

            CloudQueue        sasQueueFromSasUri = new CloudQueue(sasClient.Credentials.TransformUri(queue.Uri));
            CloudQueueMessage receivedMessage    = await sasQueueFromSasUri.PeekMessageAsync();

            Assert.AreEqual(messageContent, receivedMessage.AsString);

            CloudQueue        sasQueueFromSasUri1 = new CloudQueue(new Uri(queue.Uri.ToString() + sasTokenFromId));
            CloudQueueMessage receivedMessage1    = await sasQueueFromSasUri1.PeekMessageAsync();

            Assert.AreEqual(messageContent, receivedMessage1.AsString);

            CloudQueue        sasQueueFromId   = new CloudQueue(queue.Uri, sasCredsFromId);
            CloudQueueMessage receivedMessage2 = await sasQueueFromId.PeekMessageAsync();

            Assert.AreEqual(messageContent, receivedMessage2.AsString);

            string             sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
            StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
            CloudQueue         sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
            CloudQueueMessage  receivedMessage3   = await sasQueueFromPolicy.PeekMessageAsync();

            Assert.AreEqual(messageContent, receivedMessage3.AsString);
            await queue.DeleteAsync();
        }
        public async Task CloudQueueCreateAndDeleteAsync()
        {
            string     name  = TestHelper.GenerateNewQueueName();
            CloudQueue queue = DefalutQueueClient.GetQueueReference(name);

            await queue.CreateAsync();

            await queue.DeleteAsync();
        }
        public async Task CloudQueueCreateAndDeleteAsync()
        {
            string           name   = GenerateNewQueueName();
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue       queue  = client.GetQueueReference(name);

            await queue.CreateAsync();

            await queue.DeleteAsync();
        }
        public async Task QueueRegionalSASTestAsync()
        {
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("it-IT");

            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue       queue  = client.GetQueueReference(GenerateNewQueueName());

            try
            {
                await queue.CreateAsync();

                string            messageContent = Guid.NewGuid().ToString();
                CloudQueueMessage message        = new CloudQueueMessage(messageContent);
                await queue.AddMessageAsync(message);

                // Prepare SAS authentication with full permissions
                string                       id          = Guid.NewGuid().ToString();
                DateTime                     start       = DateTime.UtcNow;
                DateTime                     expiry      = start.AddMinutes(30);
                QueuePermissions             permissions = new QueuePermissions();
                SharedAccessQueuePermissions queuePerm   = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
                permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
                {
                    SharedAccessStartTime  = start,
                    SharedAccessExpiryTime = expiry,
                    Permissions            = queuePerm
                });

                await queue.SetPermissionsAsync(permissions);

                await Task.Delay(30 * 1000);

                string             sasTokenFromId   = queue.GetSharedAccessSignature(null, id);
                StorageCredentials sasCredsFromId   = new StorageCredentials(sasTokenFromId);
                CloudQueue         sasQueueFromId   = new CloudQueue(queue.Uri, sasCredsFromId);
                CloudQueueMessage  receivedMessage1 = await sasQueueFromId.PeekMessageAsync();

                Assert.AreEqual(messageContent, receivedMessage1.AsString);

                string             sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
                StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
                CloudQueue         sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
                CloudQueueMessage  receivedMessage2   = await sasQueueFromPolicy.PeekMessageAsync();

                Assert.AreEqual(messageContent, receivedMessage2.AsString);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
                queue.DeleteAsync().Wait();
            }
        }
        public async Task CloudQueueClearMessageAsync()
        {
            string     name  = TestHelper.GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);
            await queue.CreateAsync();

            string            msgContent = Guid.NewGuid().ToString("N");
            CloudQueueMessage message    = new CloudQueueMessage(msgContent);
            await queue.AddMessageAsync(message);

            CloudQueueMessage receivedMessage1 = await queue.PeekMessageAsync();

            Assert.IsTrue(receivedMessage1.AsString == message.AsString);
            await queue.ClearAsync();

            Assert.IsNull(await queue.PeekMessageAsync());
            await queue.DeleteAsync();
        }
        public async Task CloudQueueDeleteMessageWithAddMessagePopReceipt()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue       queue  = client.GetQueueReference(GenerateNewQueueName());

            await queue.CreateAsync();

            string            msgContent = Guid.NewGuid().ToString("N");
            CloudQueueMessage message    = new CloudQueueMessage(msgContent);
            await queue.AddMessageAsync(message);

            VerifyAddMessageResult(message);
            await queue.DeleteMessageAsync(message.Id, message.PopReceipt);

            CloudQueueMessage receivedMessage = await queue.GetMessageAsync();

            Assert.IsNull(receivedMessage);

            await queue.DeleteAsync();
        }
        public async Task CloudQueuePeekMessageAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            string           name   = GenerateNewQueueName();
            CloudQueue       queue  = client.GetQueueReference(name);
            await queue.CreateAsync();

            CloudQueueMessage emptyMessage = await queue.PeekMessageAsync();

            Assert.IsNull(emptyMessage);

            string            msgContent = Guid.NewGuid().ToString("N");
            CloudQueueMessage message    = new CloudQueueMessage(msgContent);
            await queue.AddMessageAsync(message);

            CloudQueueMessage receivedMessage1 = await queue.PeekMessageAsync();

            Assert.IsTrue(receivedMessage1.AsString == message.AsString);

            await queue.DeleteAsync();
        }
Esempio n. 11
0
        public async Task CloudQueueGetSetPermissionsAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue       queue  = client.GetQueueReference(GenerateNewQueueName());

            await queue.CreateAsync();

            QueuePermissions emptyPermission = await queue.GetPermissionsAsync();

            Assert.AreEqual(emptyPermission.SharedAccessPolicies.Count, 0);
            string                       id          = Guid.NewGuid().ToString();
            DateTime                     start       = DateTime.UtcNow;
            DateTime                     expiry      = start.AddMinutes(30);
            QueuePermissions             permissions = new QueuePermissions();
            SharedAccessQueuePermissions queuePerm   = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;

            permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
            {
                SharedAccessStartTime  = start,
                SharedAccessExpiryTime = expiry,
                Permissions            = queuePerm
            });

            await queue.SetPermissionsAsync(permissions);

            await Task.Delay(30 * 1000);

            await queue.FetchAttributesAsync();

            CloudQueue       queueToRetrieve       = client.GetQueueReference(queue.Name);
            QueuePermissions permissionsToRetrieve = await queueToRetrieve.GetPermissionsAsync();

            Assert.AreEqual(permissions.SharedAccessPolicies.Count, permissionsToRetrieve.SharedAccessPolicies.Count);
            //Assert.AreEqual(start, permissionsToRetrieve.SharedAccessPolicies[id].SharedAccessStartTime.Value.UtcDateTime);
            //Assert.AreEqual(expiry, permissionsToRetrieve.SharedAccessPolicies[id].SharedAccessExpiryTime.Value.UtcDateTime);
            Assert.AreEqual(permissions.SharedAccessPolicies[id].Permissions, permissionsToRetrieve.SharedAccessPolicies[id].Permissions);

            await queue.DeleteAsync();
        }
 /// <summary>
 /// Delete the queue that was created for this sample
 /// </summary>
 /// <param name="queue">The sample queue to delete</param>
 private static async Task DeleteQueueAsync(CloudQueue queue)
 {
     Console.WriteLine("10. Delete the queue");
     await queue.DeleteAsync();
 }