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;
        }
        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);
        }
        public TopicSubscriptionList GetTopicSubscriptionList(string topicName)
        {
            TopicSubscriptionList subList = new TopicSubscriptionList();
            MessagingRequest request = new MessagingRequest("topics/{topicName}/subscriptions");
            request.AddUrlSegment("topicName", topicName);
            request.HttpStatusSuccessCodes.Add(200);

            EntityListResponse<SubscriptionResponse> topicSubscriptionResponse =
                client.Execute<EntityListResponse<SubscriptionResponse>>(request);

            foreach (SubscriptionResponse tmpSubscription in topicSubscriptionResponse.items) {
                if (tmpSubscription.endpoint_type.ToLower() == "http") {
                    HttpTopicSubscription sub = new HttpTopicSubscription();
                    sub.ID = tmpSubscription.id;
                    sub.Body = tmpSubscription.endpoint.body;
                    sub.URL = tmpSubscription.endpoint.url;
                    sub.Headers = tmpSubscription.endpoint.headers;
                    sub.Parameters = tmpSubscription.endpoint.@params;

                    switch (tmpSubscription.endpoint.method.ToUpper()) {
                        case "POST":
                            sub.HttpMethod = HttpTopicSubscriptionMethod.POST;
                            break;
                        case "GET":
                            sub.HttpMethod = HttpTopicSubscriptionMethod.GET;
                            break;
                        case "PUT":
                            sub.HttpMethod = HttpTopicSubscriptionMethod.PUT;
                            break;
                    }

                    subList.Add(sub);
                }
                else if (tmpSubscription.endpoint_type.ToLower() == "queue") {
                    QueueTopicSubscription sub = new QueueTopicSubscription();
                    sub.ID = tmpSubscription.id;
                    sub.QueueName = tmpSubscription.endpoint.queue_name;
                    subList.Add(sub);
                }
            }

            return subList;
        }