public void CloudQueueClientListQueuesSegmentedTask()
        {
            CloudQueueClient client = GenerateCloudQueueClient();

            string        prefix     = "dotnetqueuetest" + Guid.NewGuid().ToString("N");
            List <string> queueNames = new List <string>();
            int           count      = 3;

            for (int i = 0; i < count; i++)
            {
                string queueName = prefix + i;
                queueNames.Add(queueName);
                client.GetQueueReference(queueName).CreateAsync().Wait();
            }

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

            do
            {
                QueueResultSegment segment = client.ListQueuesSegmentedAsync(token).Result;
                token = segment.ContinuationToken;
                results.AddRange(segment.Results);
            }while (token != null);

            foreach (CloudQueue queue in results)
            {
                if (queueNames.Remove(queue.Name))
                {
                    client.GetQueueReference(queue.Name).DeleteAsync().Wait();
                }
            }

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

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

            using (AutoResetEvent waitHandle = new AutoResetEvent(false))
            {
                QueueContinuationToken token   = null;
                List <CloudQueue>      results = new List <CloudQueue>();
                do
                {
                    IAsyncResult result = client.BeginListQueuesSegmented(prefix, token, ar => waitHandle.Set(), null);
                    waitHandle.WaitOne();
                    QueueResultSegment segment = client.EndListQueuesSegmented(result);
                    results.AddRange(segment.Results);
                    token = segment.ContinuationToken;
                }while (token != null);

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

                foreach (string name in queueNames)
                {
                    client.GetQueueReference(name).Create();
                }

                do
                {
                    IAsyncResult result = client.BeginListQueuesSegmented(prefix, token, ar => waitHandle.Set(), null);
                    waitHandle.WaitOne();
                    QueueResultSegment segment = client.EndListQueuesSegmented(result);
                    results.AddRange(segment.Results);
                    token = segment.ContinuationToken;
                }while (token != null);

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

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

                Assert.AreEqual <int>(0, queueNames.Count);
            }
        }
        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 CloudQueueClientListQueuesSegmentedAsync()
        {
            CloudQueueClient client     = GenerateCloudQueueClient();
            string           prefix     = "rtqueuetest" + Guid.NewGuid().ToString("N");
            List <string>    queueNames = new List <string>();
            int count = 3;

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

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

            do
            {
                QueueResultSegment segment = await client.ListQueuesSegmentedAsync(prefix, QueueListingDetails.None, null, token, null, null);

                token = segment.ContinuationToken;
                results.AddRange(segment.Results);
            }while (token != null);

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

            foreach (string name in queueNames)
            {
                await client.GetQueueReference(name).CreateAsync();
            }

            do
            {
                QueueResultSegment segment = await client.ListQueuesSegmentedAsync(prefix, QueueListingDetails.None, 10, token, null, null);

                token = segment.ContinuationToken;
                results.AddRange(segment.Results);
            }while (token != null);

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

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

            Assert.AreEqual <int>(0, queueNames.Count);
        }
        public void CloudQueueClientListQueuesSegmentedWithPrefixOverload()
        {
            string        prefix     = "dotnetqueuetest" + Guid.NewGuid().ToString("N");
            List <string> queueNames = new List <string>();
            int           count      = 3;

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

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

            CloudQueueClient client = GenerateCloudQueueClient();

            do
            {
                QueueResultSegment segment = client.ListQueuesSegmented(prefix, token);
                token = segment.ContinuationToken;
                results.AddRange(segment.Results);
            }while (token != null);

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

            foreach (string name in queueNames)
            {
                client.GetQueueReference(name).Create();
            }

            do
            {
                QueueResultSegment segment = client.ListQueuesSegmented(prefix, token);
                token = segment.ContinuationToken;
                results.AddRange(segment.Results);
            }while (token != null);

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

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

            Assert.AreEqual <int>(0, queueNames.Count);
        }
        public void CloudQueueClientListQueuesWithContinuationTokenNullTarget()
        {
            CloudQueueClient client     = GenerateCloudQueueClient();
            string           prefix     = "dotnetqueuetest" + Guid.NewGuid().ToString("N");
            List <string>    queueNames = new List <string>();
            int segmentCount            = 8;

            for (int i = 0; i < segmentCount; i++)
            {
                queueNames.Add(prefix + i);
            }

            QueueContinuationToken continuationToken = null;
            List <CloudQueue>      results           = new List <CloudQueue>();
            int tokenCount = 0;

            foreach (string name in queueNames)
            {
                client.GetQueueReference(name).CreateAsync().Wait();
            }

            do
            {
                QueueResultSegment segment = client.ListQueuesSegmentedAsync(prefix, QueueListingDetails.None, 1, continuationToken, null, null).Result;
                tokenCount++;
                continuationToken = segment.ContinuationToken;
                if (tokenCount < segmentCount)
                {
                    Assert.IsNotNull(segment.ContinuationToken);
                    continuationToken.TargetLocation = null;
                }

                results.AddRange(segment.Results);
            }while (continuationToken != null);

            Assert.AreEqual <int>(results.Count, queueNames.Count);
            Assert.AreEqual <int>(results.Count, tokenCount);

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

            Assert.AreEqual <int>(0, queueNames.Count);
        }
        public void ListQueuesSegmentedTest()
        {
            String prefix = "pagingqueuetest" + Guid.NewGuid();

            ///Create 20 queues
            for (int i = 1; i <= 20; i++)
            {
                CloudQueue myqueue = DefaultQueueClient.GetQueueReference(prefix + i);
                myqueue.CreateIfNotExists();
            }

            ///Segmented listing of queues.
            ///Return a page of 10 queues beginning with the specified prefix.
            ///Check with options and context as NULL
            QueueResultSegment resultSegment = DefaultQueueClient.ListQueuesSegmented(prefix, QueueListingDetails.None, 10, null, null, null);

            IEnumerable <CloudQueue> list = resultSegment.Results;
            int count = 0;

            foreach (CloudQueue item in list)
            {
                count++;
                item.Delete();
            }
            Assert.AreEqual(10, count);
            Assert.IsNotNull(resultSegment.ContinuationToken);

            OperationContext    context = new OperationContext();
            QueueRequestOptions options = new QueueRequestOptions();

            ///Check with options and context having some value

            QueueResultSegment       resultSegment2 = DefaultQueueClient.ListQueuesSegmented(prefix, QueueListingDetails.None, 10, resultSegment.ContinuationToken, options, context);
            IEnumerable <CloudQueue> list2          = resultSegment2.Results;

            foreach (CloudQueue item in list2)
            {
                item.Delete();
            }
            Assert.IsNull(resultSegment2.ContinuationToken);
        }
        public async Task CloudQueueClientListQueuesBasicAsync()
        {
            DelegatingHandlerImpl delegatingHandlerImpl = new DelegatingHandlerImpl(new DelegatingHandlerImpl());
            CloudQueueClient      client = GenerateCloudQueueClient(delegatingHandlerImpl);
            string        prefix         = GenerateNewQueueName();
            List <string> queueNames     = new List <string>();
            int           count          = 30;

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

            QueueResultSegment emptyResults = await client.ListQueuesSegmentedAsync(prefix, QueueListingDetails.All, null, null, null, null);

            Assert.AreEqual <int>(0, emptyResults.Results.Count());

            foreach (string name in queueNames)
            {
                await client.GetQueueReference(name).CreateAsync();
            }

            QueueResultSegment results = await client.ListQueuesSegmentedAsync(prefix, QueueListingDetails.All, null, null, null, null);

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

            Assert.AreEqual <int>(count, results.Results.Count());
            Assert.AreNotEqual(0, delegatingHandlerImpl.CallCount);
        }
Beispiel #9
0
        public async Task CloudQueueClientListQueuesBasicAsync()
        {
            string        prefix     = TestHelper.GenerateNewQueueName();
            List <string> queueNames = new List <string>();
            int           count      = 2;

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

            QueueResultSegment emptyResults = await DefaultQueueClient.ListQueuesSegmentedAsync(prefix, QueueListingDetails.All, null, null, null);

            Assert.AreEqual <int>(0, emptyResults.Results.Count());

            foreach (string name in queueNames)
            {
                await DefaultQueueClient.GetQueueReference(name).CreateAsync();
            }

            QueueResultSegment results = await DefaultQueueClient.ListQueuesSegmentedAsync(prefix, QueueListingDetails.All, null, null, null);

            foreach (var queue in results.Results)
            {
                if (queueNames.Remove(queue.Name))
                {
                    await queue.DeleteAsync();
                }
                else
                {
                    Assert.Fail();
                }
            }

            Assert.AreEqual <int>(count, results.Results.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);
        }