コード例 #1
0
        public void GetTopic()
        {
            Topic topic = new Topic(TestDataFactory.RandomTopicName());
            Assert.NotNull(validClient.CreateTopic(topic));

            Topic remoteTopic = validClient.GetTopic(topic.Name);
            Assert.NotNull(remoteTopic);
            Assert.AreEqual(remoteTopic.Name, topic.Name);
        }
コード例 #2
0
        public void DeleteTopic()
        {
            Topic topic = new Topic(TestDataFactory.RandomTopicName());
            T("Topic " + topic.Name);
            Assert.NotNull(validClient.CreateTopic(topic));

            bool result = false;
            Assert.DoesNotThrow(
                delegate { result = validClient.DeleteTopic(topic.Name); });
            Assert.IsTrue(result);
        }
コード例 #3
0
        public void CreateTopic()
        {
            string topicName = TestDataFactory.RandomTopicName();

            T("Topic " + topicName);

            Topic topic = new Topic(topicName);
            topic.Tags.AddRange(new string[] {"test", "csharp"});

            Topic topicRemote = validClient.CreateTopic(topic);
            Assert.NotNull(topicRemote);
            Assert.AreEqual(topicRemote.Name, topicName);
        }
コード例 #4
0
        public void UpdateTopic()
        {
            string topicName = TestDataFactory.RandomTopicName();

            T("Topic " + topicName);
            Topic topic = new Topic(topicName);
            topic.Tags.AddRange(new string[] { "test", "csharp" });

            Topic topicRemote = validClient.CreateTopic(topic);
            Assert.NotNull(topicRemote);
            Assert.AreEqual(topicRemote.Name, topicName);

            string randomString = TestDataFactory.RandomHexString(32);
            T("Tagging with " + randomString);
            topicRemote.Tags.Add(randomString);

            Topic updatedTopic = validClient.UpdateTopic(topicRemote);
            Assert.NotNull(updatedTopic);
            Assert.AreEqual(updatedTopic.Name, topic.Name);
            Assert.IsTrue(updatedTopic.Tags.Contains(randomString));
        }
コード例 #5
0
 public MessageList PublishToTopic(Topic topic, MessageList messages)
 {
     return PublishToTopic(topic.Name, messages);
 }
コード例 #6
0
        public void PushSingleToTopic()
        {
            string topicName = TestDataFactory.RandomTopicName();

            T("Topic " + topicName);
            Topic newTopic = new Topic(topicName);
            Topic topic = validClient.CreateTopic(newTopic);

            Assert.NotNull(topic);
            Assert.AreEqual(topicName, topic.Name);

            string randomBody = TestDataFactory.RandomHexString();
            Message msg = new Message();
            msg.Fields["test Key"] = TestDataFactory.RandomHexString(10);
            msg.Body = randomBody;

            Assert.AreEqual(randomBody, msg.Body);

            Message returnMsg = validClient.PublishToTopic(topic, msg);
            Assert.IsNotEmpty(returnMsg.ID);
            Assert.AreEqual(returnMsg.Body, msg.Body);
            Assert.AreEqual(returnMsg.Fields["test Key"], msg.Fields["test Key"]);

            T("Msg ID:    " + returnMsg.ID);
            T("Msg Body:  " + returnMsg.Body);
            T("Msg Field: testKey=" + returnMsg.Fields["test Key"]);
        }
コード例 #7
0
        public Topic GetTopic(string name, bool getSubscriptions = false)
        {
            MessagingRequest request = new MessagingRequest("topics/{topicName}", Method.GET);
            request.AddUrlSegment("topicName", name);
            request.HttpStatusSuccessCodes.Add(200);
            request.HttpStatusExceptionMap.Add(404, typeof(TopicNotFoundException));

            TopicResponse response = client.Execute<TopicResponse>(request);

            Topic tmpTopic = new Topic();
            tmpTopic.Name = response.name;
            tmpTopic.Tags = new TagList(response.tags);

            if (getSubscriptions) {
                tmpTopic.Subscriptions = GetTopicSubscriptionList(tmpTopic.Name);
            }

            return tmpTopic;
        }
コード例 #8
0
        public void DeleteSubscribedTopicFailure()
        {
            Topic topic = new Topic(TestDataFactory.RandomTopicName());
            T("Topic " + topic.Name);
            Assert.NotNull(validClient.CreateTopic(topic));

            HttpTopicSubscription sub = new HttpTopicSubscription();
            sub.HttpMethod = HttpTopicSubscriptionMethod.GET;
            sub.URL = "http://into.oblivion/";

            Assert.NotNull(validClient.CreateTopicSubscription(topic, sub));

            bool result = false;
            Assert.Throws<TopicHasSubscriptionsException>(
                delegate { result = validClient.DeleteTopic(topic.Name); });
            Assert.IsFalse(result);
        }
コード例 #9
0
        public void ListTopicsWithNew()
        {
            Topic topic = new Topic(TestDataFactory.RandomTopicName());
            Topic newTopic = validClient.CreateTopic(topic);
            Assert.IsNotNull(newTopic);

            T("Created topic " + newTopic.Name);

            List<Topic> topicList = null;
            Assert.DoesNotThrow(
                delegate { topicList = validClient.GetTopicList(); });
            Assert.IsNotNull(topicList);
            Assert.IsTrue(topicList.Count > 0);

            Topic remoteTopic = topicList.Find(
                delegate(Topic tmpTopic)
                {
                    return (tmpTopic.Name == newTopic.Name);
                });

            Assert.IsNotNull(remoteTopic);
        }
コード例 #10
0
 public bool DeleteTopicSubscription(Topic topic, ITopicSubscription subscription)
 {
     return DeleteTopicSubscription(topic.Name, subscription.GetID());
 }
コード例 #11
0
 public bool DeleteTopicSubscription(Topic topic, string subscriptionId)
 {
     return DeleteTopicSubscription(topic.Name, subscriptionId);
 }
コード例 #12
0
 public TopicSubscriptionList GetTopicSubscriptionList(Topic topic)
 {
     return GetTopicSubscriptionList(topic.Name);
 }
コード例 #13
0
 public bool DeleteTopic(Topic topic, bool forceDeletion = false)
 {
     return DeleteTopic(topic.Name, forceDeletion);
 }
コード例 #14
0
        public QueueTopicSubscription CreateTopicSubscription(Topic topic, QueueTopicSubscription subscription)
        {
            MessagingRequest request = new MessagingRequest("topics/{topicName}/subscriptions", Method.POST);
            request.AddUrlSegment("topicName", topic.Name);
            request.HttpStatusSuccessCodes.Add(200);
            request.HttpStatusExceptionMap.Add(400, typeof(BadRequestException));
            request.HttpStatusSuccessCodes.Add(201);

            object postObj = new {
                endpoint_type = "queue",
                endpoint = new {
                    queue_name = subscription.QueueName
                }
            };

            if (DebugRequests) {
                Console.WriteLine("-> " + request.JsonSerializer.Serialize(postObj));
            }

            request.AddBody(postObj);

            SubscriptionResponse response = client.Execute<SubscriptionResponse>(request);
            subscription.ID = response.id;
            subscription.QueueName = response.endpoint.queue_name;

            return subscription;
        }
コード例 #15
0
        public Topic CreateTopic(string topicName)
        {
            Topic topic = new Topic(topicName);

            return CreateOrUpdateTopic(topic, true);
        }
コード例 #16
0
        public HttpTopicSubscription CreateTopicSubscription(Topic topic, HttpTopicSubscription subscription)
        {
            MessagingRequest request = new MessagingRequest("topics/{topicName}/subscriptions", Method.POST);
            request.AddUrlSegment("topicName", topic.Name);
            request.HttpStatusSuccessCodes.Add(200);
            request.HttpStatusExceptionMap.Add(400, typeof(BadRequestException));
            request.HttpStatusSuccessCodes.Add(201);

            object postObj = new {
                endpoint_type = "http",
                endpoint = new {
                    method = subscription.HttpMethod.ToString(),
                    url = subscription.URL,
                    // Escaping the params member with an @ is required, as "params" is a reserved word in C#.
                    @params = subscription.Parameters,
                    headers = subscription.Headers,
                    body = subscription.Body
                }
            };

            if (DebugRequests) {
                Console.WriteLine("-> " + request.JsonSerializer.Serialize(postObj));
            }

            request.AddBody(postObj);

            SubscriptionResponse response = client.Execute<SubscriptionResponse>(request);
            subscription.ID = response.id;
            subscription.URL = response.endpoint.url;
            subscription.Headers = response.endpoint.headers;
            subscription.Parameters = response.endpoint.@params;
            subscription.Body = response.endpoint.body;

            switch (response.endpoint.method) {
                case "GET":
                    subscription.HttpMethod = HttpTopicSubscriptionMethod.GET;
                    break;
                case "POST":
                    subscription.HttpMethod = HttpTopicSubscriptionMethod.POST;
                    break;
                case "PUT":
                    subscription.HttpMethod = HttpTopicSubscriptionMethod.PUT;
                    break;
            }

            return subscription;
        }
コード例 #17
0
        private Topic CreateOrUpdateTopic(Topic topic, bool create = true)
        {
            MessagingRequest request = new MessagingRequest("topics/{topicName}", Method.PUT);
            request.AddUrlSegment("topicName", topic.Name);
            request.HttpStatusSuccessCodes.Add(200);
            request.HttpStatusExceptionMap.Add(400, typeof(BadRequestException));

            if (create) {
                request.HttpStatusSuccessCodes.Add(201);
            }
            else {
                request.HttpStatusSuccessCodes.Add(200);
            }

            object postObj = new {
                tags = topic.Tags
            };

            if (DebugRequests) {
                Console.WriteLine("-> " + request.JsonSerializer.Serialize(postObj));
            }

            request.AddBody(postObj);

            TopicResponse response = client.Execute<TopicResponse>(request);

            topic.Name = response.name;
            topic.Tags = new TagList(response.tags);

            return topic;
        }
コード例 #18
0
 public Topic UpdateTopic(Topic topic)
 {
     return CreateOrUpdateTopic(topic, false);
 }
コード例 #19
0
 public Topic CreateTopic(Topic topic)
 {
     return CreateOrUpdateTopic(topic, true);
 }
コード例 #20
0
        public Topic CreateTopic(string topicName, TagList tags)
        {
            Topic topic = new Topic(topicName);
            topic.Tags = tags;

            return CreateOrUpdateTopic(topic, true);
        }
コード例 #21
0
 public Message PublishToTopic(Topic topic, Message message)
 {
     return PublishToTopic(topic.Name, message);
 }
コード例 #22
0
        public TopicList GetTopicList(IEnumerable<string> tagList, bool populateSubscriptions = false)
        {
            TopicList topicList = new TopicList();
            MessagingRequest request = new MessagingRequest("topics");
            request.HttpStatusSuccessCodes.Add(200);

            if (tagList != null) {
                request.AddParameter("tags", new TagList(tagList).ToString(","));
            }

            EntityListResponse<TopicResponse> topicListResponse =
                client.Execute<EntityListResponse<TopicResponse>>(request);

            foreach (TopicResponse tmpTopic in topicListResponse.items) {
                Topic topic = new Topic(tmpTopic.name);

                if (tmpTopic.tags != null) {
                    topic.Tags = new TagList(tmpTopic.tags);
                }

                if (populateSubscriptions) {
                    topic.Subscriptions = GetTopicSubscriptionList(topic);
                }

                topicList.Add(topic);
            }

            return topicList;
        }