public void GetNewsItemsByCategoryId(int categoryId)
        {
            NewsItemCollection newsItems = TestSetup.KayakoApiService.News.GetNewsItems(categoryId);

            Assert.IsNotNull(newsItems, "No news items were returned");
            Assert.IsNotEmpty(newsItems, "No news items were returned");
        }
        public void GetAllNewsItems()
        {
            NewsItemCollection newsItems = TestSetup.KayakoApiService.News.GetNewsItems();

            Assert.IsNotNull(newsItems, "No news items were returned");
            Assert.IsNotEmpty(newsItems, "No news items were returned");
        }
        public void NewsItemCollectionDeserialization()
        {
            var newsItemCollection = new NewsItemCollection
                {
                    new NewsItem
                        {
                            Id = 41,
                            StaffId = 1,
                            NewsItemType = NewsItemType.Global,
                            NewsItemStatus = NewsItemStatus.Published,
                            Author = "Author full name",
                            Email = "*****@*****.**",
                            Subject = "News subject",
                            EmailSubject = "",
                            DateLine = new UnixDateTime(1338237929),
                            Expiry = new UnixDateTime(0),
                            IsSynced = false,
                            TotalComments = 0,
                            UserVisibilityCustom = true,
                            UserGroupIdList = new[] { 1,2,3},
                            StaffVisibilityCustom = true,
                            StaffGroupIdList = new[] { 1,2},
                            AllowComments = true,
                            Contents = "Test",
                            Categories = new [] { 1,2}
                        }
                };

            var expectedNewsItemCollection = XmlDataUtility.ReadFromFile<NewsItemCollection>("TestData/NewsItemCollection.xml");

            AssertUtility.ObjectsEqual(expectedNewsItemCollection, newsItemCollection);
        }
        public void NewsItemCollectionDeserialization()
        {
            var newsItemCollection = new NewsItemCollection
            {
                new NewsItem
                {
                    Id                    = 41,
                    StaffId               = 1,
                    NewsItemType          = NewsItemType.Global,
                    NewsItemStatus        = NewsItemStatus.Published,
                    Author                = "Author full name",
                    Email                 = "*****@*****.**",
                    Subject               = "News subject",
                    EmailSubject          = "",
                    DateLine              = new UnixDateTime(1338237929),
                    Expiry                = new UnixDateTime(0),
                    IsSynced              = false,
                    TotalComments         = 0,
                    UserVisibilityCustom  = true,
                    UserGroupIdList       = new[] { 1, 2, 3 },
                    StaffVisibilityCustom = true,
                    StaffGroupIdList      = new[] { 1, 2 },
                    AllowComments         = true,
                    Contents              = "Test",
                    Categories            = new [] { 1, 2 }
                }
            };

            var expectedNewsItemCollection = XmlDataUtility.ReadFromFile <NewsItemCollection>("TestData/NewsItemCollection.xml");

            AssertUtility.ObjectsEqual(expectedNewsItemCollection, newsItemCollection);
        }
Beispiel #5
0
        public void Setup()
        {
            _kayakoApiRequest = new Mock <IKayakoApiRequest>();
            _newsController   = new NewsController(_kayakoApiRequest.Object);

            _responseNewsCategoryCollection = new NewsCategoryCollection
            {
                new NewsCategory(),
                new NewsCategory()
            };

            _responseNewsItemCollection = new NewsItemCollection
            {
                new NewsItem(),
                new NewsItem()
            };

            _responseNewsSubscriberCollection = new NewsSubscriberCollection
            {
                new NewsSubscriber(),
                new NewsSubscriber(),
                new NewsSubscriber()
            };

            _responseNewsItemCommentCollection = new NewsItemCommentCollection
            {
                new NewsItemComment(),
                new NewsItemComment()
            };
        }
        public NewsItem CreateNewsItem(NewsItemRequest newsItemRequest)
        {
            RequestBodyBuilder parameters = PopulateRequestParameters(newsItemRequest, RequestTypes.Create);

            NewsItemCollection newsItems = Connector.ExecutePost <NewsItemCollection>(NewsItemBaseUrl, parameters.ToString());

            if (newsItems != null && newsItems.Count > 0)
            {
                return(newsItems[0]);
            }

            return(null);
        }
        public NewsItem UpdateNewsItem(NewsItemRequest newsItemRequest)
        {
            string apiMethod = string.Format("{0}/{1}", NewsItemBaseUrl, newsItemRequest.Id);

            RequestBodyBuilder parameters = PopulateRequestParameters(newsItemRequest, RequestTypes.Update);

            NewsItemCollection newsItems = Connector.ExecutePut <NewsItemCollection>(apiMethod, parameters.ToString());

            if (newsItems != null && newsItems.Count > 0)
            {
                return(newsItems[0]);
            }

            return(null);
        }
        public void GetNewsItemById()
        {
            NewsItemCollection newsItems = TestSetup.KayakoApiService.News.GetNewsItems();

            Assert.IsNotNull(newsItems, "No news items were returned");
            Assert.IsNotEmpty(newsItems, "No news items were returned");

            NewsItem newsItemToGet = newsItems[new Random().Next(newsItems.Count)];

            Trace.WriteLine("GetNewsItem using news item id: " + newsItemToGet.Id);

            NewsItem newsItem = TestSetup.KayakoApiService.News.GetNewsItem(newsItemToGet.Id);

            AssertObjectXmlEqual(newsItem, newsItemToGet);
        }
Beispiel #9
0
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <IList <NewsItem> > > GetNewsWithOperationResponseAsync(CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            // Tracing
            bool   shouldTrace  = ServiceClientTracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                ServiceClientTracing.Enter(invocationId, this, "GetNewsAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/api/NewsArticle";
            string baseUrl = this.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpRequest.Method     = HttpMethod.Get;
            httpRequest.RequestUri = new Uri(url);

            // Set Credentials
            if (this.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await this.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
            }

            // Send Request
            if (shouldTrace)
            {
                ServiceClientTracing.SendRequest(invocationId, httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            if (shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(invocationId, httpResponse);
            }
            HttpStatusCode statusCode = httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (statusCode != HttpStatusCode.OK)
            {
                HttpOperationException <object> ex = new HttpOperationException <object>();
                ex.Request  = httpRequest;
                ex.Response = httpResponse;
                ex.Body     = null;
                if (shouldTrace)
                {
                    ServiceClientTracing.Error(invocationId, ex);
                }
                throw ex;
            }

            // Create Result
            HttpOperationResponse <IList <NewsItem> > result = new HttpOperationResponse <IList <NewsItem> >();

            result.Request  = httpRequest;
            result.Response = httpResponse;

            // Deserialize Response
            if (statusCode == HttpStatusCode.OK)
            {
                IList <NewsItem> resultModel = new List <NewsItem>();
                JToken           responseDoc = null;
                if (string.IsNullOrEmpty(responseContent) == false)
                {
                    responseDoc = JToken.Parse(responseContent);
                }
                if (responseDoc != null)
                {
                    resultModel = NewsItemCollection.DeserializeJson(responseDoc);
                }
                result.Body = resultModel;
            }

            if (shouldTrace)
            {
                ServiceClientTracing.Exit(invocationId, result);
            }
            return(result);
        }
        public void Setup()
        {
            _kayakoApiRequest = new Mock<IKayakoApiRequest>();
            _newsController = new NewsController(_kayakoApiRequest.Object);

            _responseNewsCategoryCollection = new NewsCategoryCollection
                {
                    new NewsCategory(),
                    new NewsCategory()
                };

            _responseNewsItemCollection = new NewsItemCollection
                {
                    new NewsItem(),
                    new NewsItem()
                };

            _responseNewsSubscriberCollection = new NewsSubscriberCollection
                {
                    new NewsSubscriber(),
                    new NewsSubscriber(),
                    new NewsSubscriber()
                };

            _responseNewsItemCommentCollection = new NewsItemCommentCollection
                {
                    new NewsItemComment(),
                    new NewsItemComment()
                };
        }