public void QueueContinuationTokenVerifyXmlFunctions()
        {
            CloudQueueClient client     = GenerateCloudQueueClient();
            string           prefix     = "dotnetqueuetest" + Guid.NewGuid().ToString("N");
            List <string>    queueNames = new List <string>();
            int count = 30;

            for (int i = 0; i < count; i++)
            {
                queueNames.Add(prefix + i);
                client.GetQueueReference(prefix + i).Create();
            }

            QueueContinuationToken token   = null;
            List <CloudQueue>      results = new List <CloudQueue>();

            do
            {
                QueueResultSegment segment = client.ListQueuesSegmented(prefix, QueueListingDetails.None, 5, token, null, null);
                token = segment.ContinuationToken;
                results.AddRange(segment.Results);
                if (token != null)
                {
                    Assert.AreEqual(null, token.GetSchema());

                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    StringBuilder sb = new StringBuilder();
                    using (XmlWriter writer = XmlWriter.Create(sb, settings))
                    {
                        token.WriteXml(writer);
                    }

                    using (XmlReader reader = XmlReader.Create(new StringReader(sb.ToString())))
                    {
                        token = new QueueContinuationToken();
                        token.ReadXml(reader);
                    }
                }
            }while (token != null);

            foreach (CloudQueue queue in results)
            {
                if (queueNames.Remove(queue.Name))
                {
                    queue.Delete();
                }
                else
                {
                    Assert.Fail();
                }
            }

            Assert.AreEqual <int>(0, queueNames.Count);
        }
        public async Task QueueContinuationTokenVerifyXmlWithinXml()
        {
            CloudQueueClient client     = GenerateCloudQueueClient();
            string           prefix     = "dotnetqueuetest" + Guid.NewGuid().ToString("N");
            List <string>    queueNames = new List <string>();
            int count = 30;

            for (int i = 0; i < count; i++)
            {
                queueNames.Add(prefix + i);
                client.GetQueueReference(prefix + i).Create();
            }

            QueueContinuationToken token   = null;
            List <CloudQueue>      results = new List <CloudQueue>();

            do
            {
                QueueResultSegment segment = client.ListQueuesSegmented(prefix, QueueListingDetails.None, 5, token, null, null);
                token = segment.ContinuationToken;
                results.AddRange(segment.Results);
                if (token != null)
                {
                    Assert.AreEqual(null, token.GetSchema());

                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    StringBuilder sb = new StringBuilder();
                    using (XmlWriter writer = XmlWriter.Create(sb, settings))
                    {
                        writer.WriteStartElement("test1");
                        writer.WriteStartElement("test2");
                        token.WriteXml(writer);
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }

                    using (XmlReader reader = XMLReaderExtensions.CreateAsAsync(new MemoryStream(Encoding.Unicode.GetBytes(sb.ToString()))))
                    {
                        token = new QueueContinuationToken();
                        await reader.ReadStartElementAsync();

                        await reader.ReadStartElementAsync();

                        await token.ReadXmlAsync(reader);

                        await reader.ReadEndElementAsync();

                        await reader.ReadEndElementAsync();
                    }
                }
            }while (token != null);

            foreach (CloudQueue queue in results)
            {
                if (queueNames.Remove(queue.Name))
                {
                    queue.Delete();
                }
                else
                {
                    Assert.Fail();
                }
            }

            Assert.AreEqual <int>(0, queueNames.Count);
        }