public void CreateEditorsPick() { //First get a comment. CommentsTests_V1 comments = new CommentsTests_V1(); CommentForumTests_V1 commentForums = new CommentForumTests_V1(); _commentInfo = comments.CreateCommentHelper(commentForums.CommentForumCreateHelper().Id); Assert.IsNotNull(_commentInfo, "Unable to Create Comment"); DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserEditor(); // Setup the request url string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/{1}/editorpicks/", _sitename,_commentInfo.ID); request.RequestPageWithFullURL(url, "No data to send", "text/xml"); //Check for Editors Pick presence. url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/?filterBy=EditorPicks", _sitename); request.RequestPageWithFullURL(url); XmlDocument xml = request.GetLastResponseAsXML(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("api", "BBC.Dna.Api"); String xPath = String.Format("api:commentsList/api:comments/api:comment[api:id='{0}']", _commentInfo.ID); XmlNode pick = xml.SelectSingleNode(xPath, nsmgr); Assert.IsNotNull(pick); }
public void GetReviewForumWithEditorsPickFilter() { //Create 2 Comments CommentsTests_V1 comments = new CommentsTests_V1(); CommentForumTests_V1 commentForums = new CommentForumTests_V1(); CommentInfo commentInfo = comments.CreateCommentHelper(commentForums.CommentForumCreateHelper().Id); CommentInfo commentInfo2 = comments.CreateCommentHelper(commentForums.CommentForumCreateHelper().Id); //Create Editors Pick on 1st comment only. EditorsPicks_V1 editorsPicks = new EditorsPicks_V1(); editorsPicks.CreateEditorsPickHelper(_sitename, commentInfo.ID); //Request Comments Filtered by Editors Picks. DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); // Setup the request url string url = commentInfo.ForumUri + "?filterBy=EditorsPick"; //Check that picked comment is in results. request.RequestPageWithFullURL(url, "", "text/xml"); XmlDocument xml = request.GetLastResponseAsXML(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("api", "BBC.Dna.Api"); String xPath = String.Format("api:ratingForum/api:commentsList/api:comments/api:comment[api:id='{0}']", commentInfo.ID); XmlNode pick = xml.SelectSingleNode(xPath, nsmgr); Assert.IsNotNull(pick); //Check Comment that has not been picked is not present. xPath = String.Format("api:ratingForum/api:commentsList/api:comments/api:comment[api:id='{0}']", commentInfo2.ID); pick = xml.SelectSingleNode(xPath, nsmgr); Assert.IsNull(pick); }
public void GetCommentListBySitenameXML_WithEditorsPickFilter() { //Create Comment. var comment = new CommentsTests_V1(); var commentForumTest = new CommentForumTests_V1(); //create the forum CommentForum commentForum = commentForumTest.CommentForumCreateHelper(); CommentInfo commentInfo = comment.CreateCommentHelper(commentForum.Id); CommentInfo commentInfo2 = comment.CreateCommentHelper(commentForum.Id); //Create Editors Pick on first comment only. var editorsPicks = new EditorsPicks_V1(); editorsPicks.CreateEditorsPickHelper(_sitename, commentInfo.ID); //Request Comments Filtered by Editors Picks. var request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); // Setup the request url string url = String.Format( "http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/?filterBy=EditorPicks", _sitename); //Check that picked comment is in results. request.RequestPageWithFullURL(url, "", "text/xml"); XmlDocument xml = request.GetLastResponseAsXML(); //Check Schema var validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForumList); validator.Validate(); var nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("api", "BBC.Dna.Api"); String xPath = String.Format("api:commentsList/api:comments/api:comment[api:id='{0}']", commentInfo.ID); XmlNode pick = xml.SelectSingleNode(xPath, nsmgr); Assert.IsNotNull(pick); //Check Comment that has not been picked is not present. xPath = String.Format("api:commentsList/api:comments/api:comment[api:id='{0}']", commentInfo2.ID); pick = xml.SelectSingleNode(xPath, nsmgr); Assert.IsNull(pick); }
public void CreateEditorsPickNonEditor() { //First get a comment. CommentsTests_V1 comments = new CommentsTests_V1(); CommentForumTests_V1 commentForums = new CommentForumTests_V1(); _commentInfo = comments.CreateCommentHelper(commentForums.CommentForumCreateHelper().Id); Assert.IsNotNull(_commentInfo, "Unable to Create Comment"); DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); // Setup the request url try { string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/{1}/editorpicks/", _sitename, _commentInfo.ID); request.RequestPageWithFullURL(url, "No data to send", "text/xml"); } catch (Exception e) { Console.WriteLine(e.Message); } //Should return 401 unauthorised Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.Unauthorized); }
public void CreateEditorsPick_CheckStandardCalls_ReturnsCommentandEditorPickCount() { //First get a comment. CommentsTests_V1 comments = new CommentsTests_V1(); CommentForumTests_V1 commentForums = new CommentForumTests_V1(); var uid = commentForums.CommentForumCreateHelper().Id; _commentInfo = comments.CreateCommentHelper(uid); Assert.IsNotNull(_commentInfo, "Unable to Create Comment"); DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserEditor(); // Setup the request url string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/{1}/editorpicks/", _sitename, _commentInfo.ID); request.RequestPageWithFullURL(url, String.Empty, "text/xml", "POST"); //Check for Editors Pick presence. url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/?filterBy=EditorPicks", _sitename); request.RequestPageWithFullURL(url); XmlDocument xml = request.GetLastResponseAsXML(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("api", "BBC.Dna.Api"); String xPath = String.Format("api:commentsList/api:comments/api:comment[api:id='{0}']", _commentInfo.ID); XmlNode pick = xml.SelectSingleNode(xPath, nsmgr); Assert.IsNotNull(pick); //get normal list of comments url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/", _sitename, uid); request.RequestPageWithFullURL(url); var returnedForum = (CommentForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentForum)); Assert.AreEqual(1, returnedForum.commentSummary.EditorPicksTotal); Assert.IsTrue(returnedForum.commentList.comments[0].IsEditorPick); }
public void RemoveEditorsPickViaPost() { //First get a comment. CommentsTests_V1 comments = new CommentsTests_V1(); CommentForumTests_V1 commentForums = new CommentForumTests_V1(); _commentInfo = comments.CreateCommentHelper(commentForums.CommentForumCreateHelper().Id); // Now make a pick String url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/{1}/editorpicks/", _sitename, _commentInfo.ID); DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserEditor(); request.RequestPageWithFullURL(url, String.Empty, "text/xml", "POST"); //Check that pick has been made. url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/?filterBy=EditorPicks", _sitename); request.RequestPageWithFullURL(url); XmlDocument xml = request.GetLastResponseAsXML(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("api", "BBC.Dna.Api"); XmlNode response = xml.SelectSingleNode(String.Format("api:commentsList/api:comments/api:comment[api:id={0}]", _commentInfo.ID), nsmgr); Assert.IsNotNull(response); // Delete the pick. url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/{1}/editorpicks/delete", _sitename, _commentInfo.ID); request.RequestPageWithFullURL(url, String.Empty, String.Empty, "POST"); Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.OK); //Check the pick is no longer there url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/?filterBy=EditorPicks", _sitename); request.RequestPageWithFullURL(url); xml = request.GetLastResponseAsXML(); nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("api", "BBC.Dna.Api"); response = xml.SelectSingleNode(String.Format("api:commentsList/api:comments/api:comment[api:id={0}]", _commentInfo.ID), nsmgr); Assert.IsNull(response); }