Example #1
0
        public void CloudQueueUnicodeMessages()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();
            queue.EncodeMessage = false;

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

            messages.Add(@"Le débat sur l'identité nationale, l'idée du président Nicolas Sarkozy de déchoir des personnes d'origine étrangère de la nationalité française dans certains cas et les récentes mesures prises contre les Roms ont choqué les experts, qui rendront leurs conclusions le 27 août.");
            messages.Add(@"Ваш логин Yahoo! дает доступ к таким мощным инструментам связи, как электронная почта, отправка мгновенных сообщений, функции безопасности, в частности, антивирусные средства и блокировщик всплывающей рекламы, и избранное, например, фото и музыка в сети — все бесплат");
            messages.Add(@"据新华社8月12日电 8月11日晚,舟曲境内再次出现强降雨天气,使特大山洪泥石流灾情雪上加霜。白龙江水在梨坝子村的交汇地带形成一个新的堰塞湖,水位比平时高出3米。甘肃省国土资源厅副厅长张国华当日22时许在新闻发布会上介绍,截至12日21时50分,舟曲堰塞湖堰塞体已消除,溃坝险情已消除,目前针对堰塞湖的主要工作是疏通河道。");
            messages.Add("ל כולם\", הדהים יעלון, ויישר קו עם העדות שמסר ראש הממשלה, בנימין נתניהו, לוועדת טירקל. לדבריו, אכן השרים דנו רק בהיבטים התקשורתיים של עצירת המשט: \"בשביעייה לא התקיים דיון על האלטרנטיבות. עסקנו בהיבטים ");
            messages.Add(@"Prozent auf 0,5 Prozent. Im Vergleich zum Vorjahresquartal wuchs die deutsche Wirtschaft von Januar bis März um 2,1 Prozent. Auch das ist eine Korrektur nach oben, ursprünglich waren es hier 1,7 Prozent");
            messages.Add("<?xml version=\"1.0\"?>\n<!DOCTYPE PARTS SYSTEM \"parts.dtd\">\n<?xml-stylesheet type=\"text/css\" href=\"xmlpartsstyle.css\"?>\n<PARTS>\n   <TITLE>Computer Parts</TITLE>\n   <PART>\n      <ITEM>Motherboard</ITEM>\n      <MANUFACTURER>ASUS</MANUFACTURER>\n      <MODEL>" +
                         "P3B-F</MODEL>\n      <COST> 123.00</COST>\n   </PART>\n   <PART>\n      <ITEM>Video Card</ITEM>\n      <MANUFACTURER>ATI</MANUFACTURER>\n      <MODEL>All-in-Wonder Pro</MODEL>\n      <COST> 160.00</COST>\n   </PART>\n   <PART>\n      <ITEM>Sound Card</ITEM>\n      <MANUFACTURER>" +
                         "Creative Labs</MANUFACTURER>\n      <MODEL>Sound Blaster Live</MODEL>\n      <COST> 80.00</COST>\n   </PART>\n   <PART>\n      <ITEM> inch Monitor</ITEM>\n      <MANUFACTURER>LG Electronics</MANUFACTURER>\n      <MODEL> 995E</MODEL>\n      <COST> 290.00</COST>\n   </PART>\n</PARTS>");

            foreach (string msg in messages)
            {
                queue.AddMessage(new CloudQueueMessage(msg));

                CloudQueueMessage readBack = queue.GetMessage();
                Assert.AreEqual <string>(msg, readBack.AsString);
                queue.DeleteMessage(readBack);
            }

            queue.Delete();
        }
Example #2
0
        public void CloudQueuePeekMessages()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            int messageCount = 30;

            var emptyMessages = queue.PeekMessages(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);
                queue.AddMessage(message);
                messageContentList.Add(messageContent);
            }

            var receivedMessages = queue.PeekMessages(messageCount).ToList();

            Assert.AreEqual(messageCount, receivedMessages.Count);

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

            queue.Delete();
        }
Example #3
0
        public void CloudQueueAddGetByteMessage()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            byte[]            testData = new byte[20];
            CloudQueueMessage message  = new CloudQueueMessage(testData);

            queue.AddMessage(message);

            CloudQueueMessage receivedMessage1 = queue.GetMessage();

            Assert.IsTrue(receivedMessage1.AsString == message.AsString);
            TestHelper.AssertStreamsAreEqual(new MemoryStream(receivedMessage1.AsBytes), new MemoryStream(message.AsBytes));

            receivedMessage1.SetMessageContent(Guid.NewGuid().ToString("N"));

            queue.UpdateMessage(receivedMessage1, TimeSpan.FromSeconds(1), MessageUpdateFields.Content | MessageUpdateFields.Visibility);

            queue.DeleteMessage(receivedMessage1);

            queue.Delete();
        }
        public void CloudQueueSetGetMetadata()
        {
            CloudQueue queue = DefaultQueueClient.GetQueueReference(GenerateNewQueueName());

            try
            {
                queue.Create();

                CloudQueue queueToRetrieve = DefaultQueueClient.GetQueueReference(queue.Name);
                queueToRetrieve.FetchAttributes();
                Assert.AreEqual <int>(0, queueToRetrieve.Metadata.Count);

                queue.Metadata.Add("key1", "value1");
                queue.SetMetadata();

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

                queue.Metadata.Clear();
                queue.SetMetadata();

                queueToRetrieve.FetchAttributes();
                Assert.AreEqual <int>(0, queueToRetrieve.Metadata.Count);
            }
            finally
            {
                queue.DeleteIfExists();
            }
        }
        public void CloudQueueCreateAndDelete()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();
            queue.Delete();
        }
        public void CloudQueueDeleteIfExists()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            Assert.IsFalse(queue.DeleteIfExists());
            queue.Create();
            Assert.IsTrue(queue.DeleteIfExists());
            Assert.IsFalse(queue.DeleteIfExists());
        }
        public void CloudQueueCreateUsingDifferenctVersionHeader()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            OperationContext opContext = new OperationContext();

            opContext.SendingRequest += (obj, args) => args.Request.Headers[Constants.HeaderConstants.StorageVersionHeader] = "2011-08-18";

            queue.Create(null, opContext);
            Assert.AreEqual((int)HttpStatusCode.Created, opContext.LastResult.HttpStatusCode);

            queue.DeleteIfExists();
        }
        public void QueueRegionalSASTest()
        {
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

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

            CloudQueue queue = DefaultQueueClient.GetQueueReference(GenerateNewQueueName());

            try
            {
                queue.Create();
                string            messageContent = Guid.NewGuid().ToString();
                CloudQueueMessage message        = new CloudQueueMessage(messageContent);
                queue.AddMessage(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
                });

                queue.SetPermissions(permissions);
                Thread.Sleep(30 * 1000);

                string             sasTokenFromId   = queue.GetSharedAccessSignature(null, id);
                StorageCredentials sasCredsFromId   = new StorageCredentials(sasTokenFromId);
                CloudQueue         sasQueueFromId   = new CloudQueue(queue.Uri, sasCredsFromId);
                CloudQueueMessage  receivedMessage1 = sasQueueFromId.PeekMessage();
                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   = sasQueueFromPolicy.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage2.AsString);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
                queue.DeleteIfExists();
            }
        }
        public void CloudQueueClientCreateQueueSharedKeyLite()
        {
            CloudQueueClient queueClient = GenerateCloudQueueClient();

            queueClient.AuthenticationScheme = AuthenticationScheme.SharedKeyLite;

            string     queueName = Guid.NewGuid().ToString("N");
            CloudQueue queue     = queueClient.GetQueueReference(queueName);

            queue.Create();

            bool exists = queue.Exists();

            Assert.IsTrue(exists);
        }
Example #10
0
        public void CloudQueueMessageOverBoundaryTest()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            CloudQueue queueRefWithoutBase64Encoding = DefaultQueueClient.GetQueueReference(name);

            queueRefWithoutBase64Encoding.EncodeMessage = false;

            // excessive message size
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 8 * 12288);

            queue.Delete();
        }
Example #11
0
        public void CloudQueueUpdateMessageFullParameter()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            queue.AddMessage(new CloudQueueMessage("message in queue"));
            CloudQueueMessage messageFromQueue = queue.GetMessage(TimeSpan.FromDays(1));
            var nextVisibleTime = messageFromQueue.NextVisibleTime.Value;

            // Modify the message contents client-side
            messageFromQueue.SetMessageContent("new message content!");

            // Increase the message's visibility timeout.
            queue.UpdateMessage(messageFromQueue, TimeSpan.FromDays(2), MessageUpdateFields.Visibility);

            // The extra visibility time we get should be 1 day + small delta server time.
            Assert.IsTrue(messageFromQueue.NextVisibleTime - nextVisibleTime >= TimeSpan.FromDays(1));

            // Decrease the message's visibility timeout.
            queue.UpdateMessage(messageFromQueue, TimeSpan.FromDays(1), MessageUpdateFields.Visibility);

            // Now the extra time equals a small delta server time.
            Assert.IsTrue(messageFromQueue.NextVisibleTime - nextVisibleTime < TimeSpan.FromHours(1));

            // Update the message's visibility and content.
            queue.UpdateMessage(messageFromQueue, TimeSpan.FromSeconds(1), MessageUpdateFields.Visibility | MessageUpdateFields.Content);

            // Wait for message timeout to expire, then retrieve it again.
            Thread.Sleep(TimeSpan.FromSeconds(1.5));
            CloudQueueMessage messageRetrievedAgain = queue.GetMessage();

            // The content should have been modified.
            Assert.AreEqual(messageFromQueue.AsString, messageRetrievedAgain.AsString);

            // Update with zero visibility timeout
            queue.UpdateMessage(messageRetrievedAgain, TimeSpan.Zero, MessageUpdateFields.Visibility);

            // The message is now expired. Retrieve it again.
            messageRetrievedAgain = queue.GetMessage();

            // The content should be the same as before.
            Assert.AreEqual(messageFromQueue.AsString, messageRetrievedAgain.AsString);

            queue.Delete();
        }
        public void CloudQueueClientCreateQueueSharedKeyLite()
        {
            DelegatingHandlerImpl delegatingHandlerImpl = new DelegatingHandlerImpl(new DelegatingHandlerImpl());
            CloudQueueClient      queueClient           = GenerateCloudQueueClient(delegatingHandlerImpl);

            queueClient.AuthenticationScheme = AuthenticationScheme.SharedKeyLite;

            string     queueName = Guid.NewGuid().ToString("N");
            CloudQueue queue     = queueClient.GetQueueReference(queueName);

            queue.Create();

            bool exists = queue.Exists();

            Assert.IsTrue(exists);
            Assert.AreNotEqual(0, delegatingHandlerImpl.CallCount);
        }
Example #13
0
        public void CloudQueueClearMessage()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

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

            queue.AddMessage(message);
            CloudQueueMessage receivedMessage1 = queue.PeekMessage();

            Assert.IsTrue(receivedMessage1.AsString == message.AsString);
            queue.Clear();
            Assert.IsNull(queue.PeekMessage());
            queue.Delete();
        }
        public void QueueEmptyHeaderSigningTest()
        {
            CloudQueue       queue   = DefaultQueueClient.GetQueueReference(Guid.NewGuid().ToString("N"));
            OperationContext context = new OperationContext();

            try
            {
                context.UserHeaders = new Dictionary <string, string>();
                context.UserHeaders.Add("x-ms-foo", String.Empty);
                queue.Create(null, context);
                CloudQueueMessage message = new CloudQueueMessage("Hello Signing");
                queue.AddMessage(message, null, null, null, context);
            }
            finally
            {
                queue.DeleteIfExists();
            }
        }
Example #15
0
        public void CloudQueueMessageSmallBoundaryTest()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            CloudQueue queueRefWithoutBase64Encoding = DefaultQueueClient.GetQueueReference(name);

            queueRefWithoutBase64Encoding.EncodeMessage = false;

            // boundary value 0 and 1
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 0);
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 1);

            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 1024);

            queue.Delete();
        }
Example #16
0
        public void CloudQueueMessageNull()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            queue.AddMessage(new CloudQueueMessage(Encoding.UTF8.GetBytes("")));
            var message = queue.GetMessage();

            Assert.IsNotNull(message);
            Assert.IsNotNull(message.Id);
            Assert.IsTrue(message.ExpirationTime.Value.Subtract(TimeSpan.FromMinutes(2)) > DateTime.UtcNow);
            Assert.IsNotNull(message.AsString);
            Assert.IsNotNull(message.InsertionTime.Value < DateTime.UtcNow);
            Assert.IsNotNull(message.PopReceipt);
            Assert.IsTrue(message.NextVisibleTime.Value.Add(TimeSpan.FromMinutes(2)) > DateTime.UtcNow);

            queue.Delete();
        }
Example #17
0
        public void CloudQueueMessageGetMessageFullParameter()
        {
            string            data = "Visibility Test Message";
            CloudQueueMessage message;

            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            queue.AddMessage(new CloudQueueMessage(data));

            // Expect failure from zero visibility timeout
            TestHelper.ExpectedException <StorageException>(
                () => queue.GetMessage(TimeSpan.Zero),
                "Expect failure from zero visibility timeout");

            // Expect failure from over 7 days visibility timeout
            TestHelper.ExpectedException <StorageException>(
                () => queue.GetMessage(TimeSpan.FromDays(7) + TimeSpan.FromSeconds(1)),
                "Expect failure from over 7 days visibility timeout");

            // Test 1 second timeout (minimum)
            message = queue.GetMessage(TimeSpan.FromSeconds(1));
            Assert.IsNotNull(message);
            Assert.AreEqual(message.AsString, data);

            // Wait for the timeout to expire
            Thread.Sleep(TimeSpan.FromSeconds(1));

            // Test 7 day timeout (maximum)
            message = queue.GetMessage(TimeSpan.FromDays(7));
            Assert.IsNotNull(message);
            Assert.AreEqual(message.AsString, data);

            // Delete the message
            queue.DeleteMessage(message);

            queue.Delete();
        }
Example #18
0
        public void CloudQueueAddMessageFullParameter()
        {
            CloudQueueMessage futureMessage  = new CloudQueueMessage("This message is for the future.");
            CloudQueueMessage presentMessage = new CloudQueueMessage("This message is for the present.");

            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            queue.AddMessage(futureMessage, null, TimeSpan.FromDays(2));

            // We should not be able to see the future message yet.
            CloudQueueMessage retrievedMessage = queue.GetMessage();

            Assert.IsNull(retrievedMessage);

            queue.AddMessage(presentMessage, null, TimeSpan.Zero);

            // We should be able to see the present message.
            retrievedMessage = queue.GetMessage();
            Assert.IsNotNull(retrievedMessage);
            Assert.AreEqual <string>(presentMessage.AsString, retrievedMessage.AsString);

            TestHelper.ExpectedException <ArgumentException>(
                () => queue.AddMessage(futureMessage, TimeSpan.FromDays(1), TimeSpan.FromDays(2)),
                "Using a visibility timeout longer than the time to live should fail");

            TestHelper.ExpectedException <ArgumentException>(
                () => queue.AddMessage(futureMessage, null, TimeSpan.FromDays(8)),
                "Using a visibility longer than the maximum time to live should fail");

            TestHelper.ExpectedException <ArgumentException>(
                () => queue.AddMessage(futureMessage, null, TimeSpan.FromMinutes(-1)),
                "Using a negative visibility should fail");

            queue.Delete();
        }
        public void CloudQueueGetSetPermissions()
        {
            CloudQueue queue = DefaultQueueClient.GetQueueReference(GenerateNewQueueName());

            try
            {
                queue.Create();
                QueuePermissions emptyPermission = queue.GetPermissions();
                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
                });

                queue.SetPermissions(permissions);
                Thread.Sleep(30 * 1000);

                CloudQueue       queueToRetrieve       = DefaultQueueClient.GetQueueReference(queue.Name);
                QueuePermissions permissionsToRetrieve = queueToRetrieve.GetPermissions();

                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);
            }
            finally
            {
                queue.DeleteIfExists();
            }
        }
Example #20
0
        public void CloudQueueMessageNormalBoundaryTest()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            CloudQueue queueRefWithoutBase64Encoding = DefaultQueueClient.GetQueueReference(name);

            queueRefWithoutBase64Encoding.EncodeMessage = false;

            // a string with ascii chars of length 8*6144 will have Base64-encoded length 8*8192 (64kB)
            // the following three test strings with length 8*6144-1, 8*6144, and 8*6144+1
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 8 * 6144 - 1);
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 8 * 6144);
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 8 * 6144 + 1);

            // boundary value 8*8192-1, 8*8192, 8*8192+1
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 8 * 8192 - 1);
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 8 * 8192);
            CloudQueueMessageBase64EncodingBoundaryTest(queue, queueRefWithoutBase64Encoding, 8 * 8192 + 1);

            queue.Delete();
        }
Example #21
0
        public void CloudQueueUpdateMessageBoundaryAndNegativeCheck()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            queue.AddMessage(new CloudQueueMessage("message in queue"));
            CloudQueueMessage messageFromQueue = queue.GetMessage(TimeSpan.FromDays(1));

            messageFromQueue.SetMessageContent("newer message content");

            // If Visibility is not flagged for modification, an exception should be raised.
            TestHelper.ExpectedException <ArgumentException>(
                () => queue.UpdateMessage(messageFromQueue, TimeSpan.FromDays(1), MessageUpdateFields.Content),
                "Visibility is not flagged for modification");

            // If visibility timeout is greater than the maximum time to live, an exception should be raised.
            TestHelper.ExpectedException <ArgumentException>(
                () => queue.UpdateMessage(messageFromQueue, TimeSpan.FromDays(7) + TimeSpan.FromSeconds(1), MessageUpdateFields.Visibility),
                "visibility timeout is greater than the maximum time to live");

            // If visibility timeout is negative, an exception should be raised.
            TestHelper.ExpectedException <ArgumentException>(
                () => queue.UpdateMessage(messageFromQueue, TimeSpan.FromSeconds(-1), MessageUpdateFields.Visibility),
                "visibility timeout is negative");

            // If the message has no ID and pop receipt, an exception should be raised.
            CloudQueueMessage messageNotReceived = new CloudQueueMessage("This message has never been in a queue before.");

            TestHelper.ExpectedException <ArgumentException>(
                () => queue.UpdateMessage(messageNotReceived, TimeSpan.FromDays(1), MessageUpdateFields.Visibility),
                "the message has no ID and pop receipt");

            queue.Delete();
        }
Example #22
0
        public void CloudQueueAddGetMessage()
        {
            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

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

            queue.AddMessage(message);

            CloudQueueMessage receivedMessage1 = queue.GetMessage();

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

            receivedMessage1.SetMessageContent(Guid.NewGuid().ToString("N"));

            queue.UpdateMessage(receivedMessage1, TimeSpan.FromSeconds(1), MessageUpdateFields.Content | MessageUpdateFields.Visibility);

            queue.DeleteMessage(receivedMessage1);

            queue.Delete();
        }
Example #23
0
        public void CloudQueueMessageQueueAddLargeMessage()
        {
            long maxStringLength    = CloudQueueMessage.MaxMessageSize;
            long maxByteArrayLength = CloudQueueMessage.MaxMessageSize * 3 / 4;

            string     name  = GenerateNewQueueName();
            CloudQueue queue = DefaultQueueClient.GetQueueReference(name);

            queue.Create();

            {
                char[] longMessageChars = new char[maxStringLength];
                for (long i = 0; i < longMessageChars.LongLength; i++)
                {
                    longMessageChars[i] = (char)('A' + (i % 26));
                }

                CloudQueueMessage longMessageFromString = new CloudQueueMessage(new string(longMessageChars));

                // Do not encode the message. This allows a maximally-sized string to be used.
                queue.EncodeMessage = false;

                // The following call should succeed.
                queue.AddMessage(longMessageFromString);

                CloudQueueMessage retrievedMessage = queue.GetMessage();
                Assert.AreEqual(longMessageFromString.AsString, retrievedMessage.AsString);
            }

            {
                byte[] longMessageBytes = new byte[maxByteArrayLength];
                for (long i = 0; i < longMessageBytes.LongLength; i++)
                {
                    longMessageBytes[i] = (byte)i;
                }

                CloudQueueMessage longMessageFromByteArray = new CloudQueueMessage(longMessageBytes);

                // The following call should throw an exception because byte array messages must be base 64 encoded.
                queue.EncodeMessage = false;

                TestHelper.ExpectedException <ArgumentException>(
                    () => queue.AddMessage(longMessageFromByteArray),
                    "AddMessage should throw an exception because byte array messages must be base 64 encoded");

                // Encode the message in base 64. This is the only way to use byte arrays in a message.
                queue.EncodeMessage = true;

                // The following call should succeed.
                queue.AddMessage(longMessageFromByteArray);

                CloudQueueMessage retrievedMessage = queue.GetMessage();
                byte[]            expectedBytes    = longMessageFromByteArray.AsBytes;
                byte[]            foundBytes       = retrievedMessage.AsBytes;

                Assert.AreEqual(expectedBytes.Length, foundBytes.Length);

                for (int i = 0; i < expectedBytes.Length; i++)
                {
                    Assert.AreEqual(expectedBytes[i], foundBytes[i]);
                }
            }

            queue.Delete();
        }