private RequestBodyBuilder PopulateRequestParameters(KnowledgebaseArticleRequest knowledgebaseArticleRequest, RequestTypes requestType) { knowledgebaseArticleRequest.EnsureValidData(requestType); RequestBodyBuilder parameters = new RequestBodyBuilder(); parameters.AppendRequestDataNonEmptyString("subject", knowledgebaseArticleRequest.Subject); parameters.AppendRequestDataNonEmptyString("contents", knowledgebaseArticleRequest.Contents); if (requestType == RequestTypes.Create && knowledgebaseArticleRequest.CreatorId.HasValue) { parameters.AppendRequestDataNonNegativeInt("creatorid", knowledgebaseArticleRequest.CreatorId.Value); } if (knowledgebaseArticleRequest.ArticleStatus.HasValue) { parameters.AppendRequestData("articlestatus", EnumUtility.ToApiString(knowledgebaseArticleRequest.ArticleStatus.Value)); } parameters.AppendRequestDataBool("isfeatured", knowledgebaseArticleRequest.IsFeatured); parameters.AppendRequestDataBool("allowcomments", knowledgebaseArticleRequest.AllowComments); parameters.AppendRequestDataArrayCommaSeparated("categoryid", knowledgebaseArticleRequest.CategoryIds); if (requestType == RequestTypes.Update && knowledgebaseArticleRequest.EditedStaffId.HasValue) { parameters.AppendRequestDataNonNegativeInt("editedstaffid", knowledgebaseArticleRequest.EditedStaffId.Value); } return(parameters); }
public KnowledgebaseArticle CreateKnowledgebaseArticle(KnowledgebaseArticleRequest knowledgebaseArticleRequest) { RequestBodyBuilder parameters = PopulateRequestParameters(knowledgebaseArticleRequest, RequestTypes.Create); KnowledgebaseArticleCollection knowledgebaseArticles = Connector.ExecutePost <KnowledgebaseArticleCollection>(KnowledgebaseArticleBaseUrl, parameters.ToString()); if (knowledgebaseArticles != null && knowledgebaseArticles.Count > 0) { return(knowledgebaseArticles[0]); } return(null); }
public KnowledgebaseArticle UpdateKnowledgebaseArticle(KnowledgebaseArticleRequest knowledgebaseArticleRequest) { string apiMethod = String.Format("{0}/{1}", KnowledgebaseArticleBaseUrl, knowledgebaseArticleRequest.Id); RequestBodyBuilder parameters = PopulateRequestParameters(knowledgebaseArticleRequest, RequestTypes.Update); KnowledgebaseArticleCollection knowledgebaseArticles = Connector.ExecutePut <KnowledgebaseArticleCollection>(apiMethod, parameters.ToString()); if (knowledgebaseArticles != null && knowledgebaseArticles.Count > 0) { return(knowledgebaseArticles[0]); } return(null); }
public void CreateUpdateDeleteKnowledgebaseArticle() { var knowledgebaseArticleRequest = new KnowledgebaseArticleRequest { Subject = "subject", Contents = "Contents", CreatorId = 1, ArticleStatus = KnowledgebaseArticleStatus.Published, IsFeatured = true, AllowComments = true, CategoryIds = new[] { 1 } }; var knowledgebaseArticle = TestSetup.KayakoApiService.Knowledgebase.CreateKnowledgebaseArticle(knowledgebaseArticleRequest); Assert.IsNotNull(knowledgebaseArticle); Assert.That(knowledgebaseArticle.Subject, Is.EqualTo(knowledgebaseArticleRequest.Subject)); Assert.That(knowledgebaseArticle.Contents, Is.EqualTo(knowledgebaseArticleRequest.Contents)); Assert.That(knowledgebaseArticle.CreatorId, Is.EqualTo(knowledgebaseArticleRequest.CreatorId)); Assert.That(knowledgebaseArticle.ArticleStatus, Is.EqualTo(knowledgebaseArticleRequest.ArticleStatus)); Assert.That(knowledgebaseArticle.IsFeatured, Is.EqualTo(knowledgebaseArticleRequest.IsFeatured)); Assert.That(knowledgebaseArticle.AllowComments, Is.EqualTo(knowledgebaseArticleRequest.AllowComments)); Assert.That(knowledgebaseArticle.Categories, Is.EqualTo(knowledgebaseArticleRequest.CategoryIds)); knowledgebaseArticleRequest.Id = knowledgebaseArticle.Id; knowledgebaseArticleRequest.EditedStaffId = 1; knowledgebaseArticleRequest.Subject += "_Subject"; knowledgebaseArticleRequest.AllowComments = false; knowledgebaseArticle = TestSetup.KayakoApiService.Knowledgebase.UpdateKnowledgebaseArticle(knowledgebaseArticleRequest); Assert.IsNotNull(knowledgebaseArticle); Assert.That(knowledgebaseArticle.Subject, Is.EqualTo(knowledgebaseArticleRequest.Subject)); Assert.That(knowledgebaseArticle.AllowComments, Is.EqualTo(knowledgebaseArticleRequest.AllowComments)); var deleteResult = TestSetup.KayakoApiService.Knowledgebase.DeleteKnowledgebaseArticle(knowledgebaseArticleRequest.Id); Assert.IsTrue(deleteResult); }
public void CreateKnowledgebaseArticle() { var knowledgebaseArticleRequest = new KnowledgebaseArticleRequest { CreatorId = 3, Subject = "Subject", Contents = "Contents", ArticleStatus = KnowledgebaseArticleStatus.Published, IsFeatured = false, AllowComments = true, CategoryIds = new [] { 1 } }; const string apiMethod = "/Knowledgebase/Article"; const string parameters = "subject=Subject&contents=Contents&creatorid=3&articlestatus=1&isfeatured=0&allowcomments=1&categoryid=1"; _kayakoApiRequest.Setup(x => x.ExecutePost <KnowledgebaseArticleCollection>(apiMethod, parameters)).Returns(_responseKnowledgebaseArticleCollection); var knowledgebaseArticle = _knowledgebaseController.CreateKnowledgebaseArticle(knowledgebaseArticleRequest); _kayakoApiRequest.Verify(x => x.ExecutePost <KnowledgebaseArticleCollection>(apiMethod, parameters), Times.Once()); Assert.That(knowledgebaseArticle, Is.EqualTo(_responseKnowledgebaseArticleCollection.FirstOrDefault())); }
public void UpdateKnowledgebaseArticle() { var knowledgebaseArticleRequest = new KnowledgebaseArticleRequest { Id = 1, EditedStaffId = 3, Subject = "Subject", Contents = "Contents", ArticleStatus = KnowledgebaseArticleStatus.Published, IsFeatured = false, AllowComments = true, CategoryIds = new [] { 1, 2, 3 } }; string apiMethod = string.Format("/Knowledgebase/Article/{0}", knowledgebaseArticleRequest.Id); const string parameters = "subject=Subject&contents=Contents&articlestatus=1&isfeatured=0&allowcomments=1&categoryid=1,2,3&editedstaffid=3"; _kayakoApiRequest.Setup(x => x.ExecutePut <KnowledgebaseArticleCollection>(apiMethod, parameters)).Returns(_responseKnowledgebaseArticleCollection); var knowledgebaseArticle = _knowledgebaseController.UpdateKnowledgebaseArticle(knowledgebaseArticleRequest); _kayakoApiRequest.Verify(x => x.ExecutePut <KnowledgebaseArticleCollection>(apiMethod, parameters), Times.Once()); Assert.That(knowledgebaseArticle, Is.EqualTo(_responseKnowledgebaseArticleCollection.FirstOrDefault())); }