Esempio n. 1
0
        public void Create101Cues()
        {
            if (!TestConfig.Run_Create101Cues)
            {
                Assert.Inconclusive("Test Skipped.");
                return;
            }

            AuthToken at = new AuthToken(Properties.Settings.Default.ManageKey, Properties.Settings.Default.ServiceNamespace);
            Queues q = new Queues(at);

            DateTime startDt = DateTime.Now;
            Console.WriteLine(String.Format("Create101Cues started @ {0} {1}", startDt.ToLongDateString(), startDt.ToLongTimeString()));
            List<string> qNames = GenerateQNames;
            try
            {
                foreach (string qName in qNames)
                {
                    q.Create(qName);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine(String.Format("Time Elapsed: {0} seconds", (DateTime.Now - startDt).TotalSeconds));

            startDt = DateTime.Now;
            Console.WriteLine(String.Format("Create101Cues fetching queue list @ {0} {1}", startDt.ToLongDateString(), startDt.ToLongTimeString()));
            AtomPubFeed apfxml = q.AtomPubList();
            List<string> queues = q.NameList(apfxml);
            string tp = testPrefix;
            Console.WriteLine(String.Format("Queues Found: {0}", String.Join(",", queues.Select(x => x.Replace(tp, "")).ToArray())));
            Console.WriteLine(String.Format("Time Elapsed: {0} seconds", (DateTime.Now - startDt).TotalSeconds));

            startDt = DateTime.Now;
            Console.WriteLine(String.Format("Create101Cues validating queue list @ {0} {1}", startDt.ToLongDateString(), startDt.ToLongTimeString()));
            foreach (string s in qNames)
            {
                if (!queues.Contains(s))
                {
                    Assert.Fail(String.Format("Missing queue name: {0}", s));
                }
            }
            Console.WriteLine(String.Format("Time Elapsed: {0} seconds", (DateTime.Now - startDt).TotalSeconds));
        }
        public void CreateQueue_FromDefinition()
        {
            if (!TestConfig.Run_CreateQueueFromDefinition)
            {
                Assert.Inconclusive("Test skipped.");
                return;
            }

            AuthToken at = new AuthToken(Properties.Settings.Default.ManageKey, Properties.Settings.Default.ServiceNamespace);
            Queues q = new Queues(at);
            #region "Pre-test clean-up"
            try
            {
                q.Delete("qWithDefaults");
                q.Delete("qWithDefaults2");
            }
            catch
            {
                // Do nothing.
            }
            #endregion

            q.Create("qWithDefaults");

            QueueDescription qd = null;
            int tries = 0;

            #region "Wait up to 10 seconds for the queue to publish."
            while (qd == null && tries < 10)
            {
                Thread.Sleep(1000);
                try
                {
                    var tmp = q.AtomPubList().Entries.Where(x => x.Title == "qwithdefaults");
                    if (tmp != null)
                    {
                        if (tmp.Count() == 1)
                        {
                            AtomPubFeedEntry ape = tmp.First();
                            if (ape.Content != null)
                            {
                                if (ape.Content.Value != null)
                                {
                                    qd = QueueDescription.DeserializeFrom(ape.Content.Value);
                                }
                            }
                        }
                    }
                }
                catch
                {
                    // Do nothing.
                }
                finally
                {
                    tries += 1;
                }
            }
            #endregion
            #region "Tried 10 x fail"
            if (tries == 10 && qd == null)
            {
                try
                {
                    q.Delete("qWithDefaults");
                }
                catch
                {
                    Console.WriteLine("Failure to create and/or delete could constitute a problem with Azure and/or Service Bus and/or Internet connection.");
                    Console.WriteLine("Could not clean-up: 'qWithDefaults' -- Suggest using Service Bus Explorer to remove this queue if it exists.");
                    // Do nothing.
                }
                finally
                {
                    Assert.Fail("Failed to retreive and/or delete newly created queue: 'qWithDefaults'");
                }
            }
            #endregion

            q.Create("qWithDefaults2", new QueueDefinition("qWithDefaults2", qd));

            QueueDescription qd2 = null;
            tries = 0;
            #region "Wait up to 10 seconds for the queue to publish."
            while (qd2 == null && tries < 10)
            {
                Thread.Sleep(1000);
                try
                {
                    var tmp = q.AtomPubList().Entries.Where(x => x.Title == "qwithdefaults2");
                    if (tmp != null)
                    {
                        if (tmp.Count() == 1)
                        {
                            AtomPubFeedEntry ape = tmp.First();
                            if (ape.Content != null)
                            {
                                if (ape.Content.Value != null)
                                {
                                    qd2 = QueueDescription.DeserializeFrom(ape.Content.Value);
                                }
                            }
                        }
                    }
                }
                catch // (Exception ex)
                {
                    // Do nothing.
                }
                finally
                {
                    tries += 1;
                }
            }
            #endregion
            #region "Tried 10 x fail"
            if (tries == 10 && qd2 == null)
            {
                try
                {
                    q.Delete("qWithDefaults");
                    q.Delete("qWithDefaults2");
                }
                catch
                {
                    Console.WriteLine("Failure to create and/or delete could constitute a problem with Azure and/or Service Bus and/or Internet connection.");
                    Console.WriteLine("Could not clean-up: 'qWithDefaults' and/or 'qWithDefaults2' -- Suggest using Service Bus Explorer to remove this queue if it exists.");
                    // Do nothing.
                }
                finally
                {
                    Assert.Fail("Failed to retreive and/or delete newly created queues: 'qWithDefaults', 'qWithDefaults2'");
                }
            }
            #endregion

            try
            {
                QueueDefinition qdc1 = new QueueDefinition("qWithDefaults", qd);
                QueueDefinition qdc2 = new QueueDefinition("qWithDefaults2", qd2);
                Assert.AreEqual<QueueDefinition>(qdc1, qdc2);
            }
            finally
            {
                #region "Cleanup"
                q.Delete("qWithDefaults");
                q.Delete("qWithDefaults2");
                #endregion
            }
        }