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 GetCommentForumWithCommentId_CreateAndAscending_ReturnsCorrectPost() { var sortBy = SortBy.Created; var sortDirection = SortDirection.Ascending; var expectedStartIndex = 2; var itemsPerPage = 1; //create the forum CommentForum commentForum = CommentForumCreateHelper(); //Create 2 Comments in the same forum. var comments = new CommentsTests_V1(); CommentInfo commentInfo = comments.CreateCommentHelper(commentForum.Id); CommentInfo commentInfo2 = comments.CreateCommentHelper(commentForum.Id); CommentInfo commentInfo3 = comments.CreateCommentHelper(commentForum.Id); 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}/commentsforums/{1}/?includepostid={2}&sortBy={3}&sortDirection={4}&itemsPerPage={5}", _sitename, commentForum.Id, commentInfo3.ID, sortBy, sortDirection, itemsPerPage); // now get the response request.RequestPageWithFullURL(url, "", "text/xml"); // Check to make sure that the page returned with the correct information XmlDocument xml = request.GetLastResponseAsXML(); var validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForum); validator.Validate(); var returnedForum = (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentForum)); Assert.AreEqual(expectedStartIndex, returnedForum.commentList.StartIndex); Assert.AreEqual(itemsPerPage, returnedForum.commentList.ItemsPerPage); Assert.AreEqual(commentInfo3.ID, returnedForum.commentList.comments[0].ID); }
public void GetCommentForumsBySitenameXML_WithTimeFrameFilter() { SnapshotInitialisation.ForceRestore();//must be clean here... var request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); // Filter forum on editors picks filter var url = String.Format( "http://{0}/dna/api/comments/CommentsService.svc/V1/site/{1}/?filterBy={2}", _server, _sitename, FilterBy.PostsWithinTimePeriod); //create the forum var commentForum = CommentForumCreateHelper(); //Create 1 Comments in the same forum. var comments = new CommentsTests_V1(); var commentInfo = comments.CreateCommentHelper(commentForum.Id); //get the latest list request.RequestPageWithFullURL(url, "", "text/xml"); var returnedObj = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentForumList)); Assert.IsNotNull(returnedObj); Assert.AreEqual(FilterBy.PostsWithinTimePeriod, returnedObj.FilterBy); Assert.AreEqual(SortBy.PostCount, returnedObj.SortBy); Assert.AreEqual(1, returnedObj.TotalCount); url += "&timeperiod=0"; request.RequestPageWithFullURL(url, "", "text/xml"); returnedObj = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentForumList)); Assert.IsNotNull(returnedObj); Assert.AreEqual(FilterBy.PostsWithinTimePeriod, returnedObj.FilterBy); Assert.AreEqual(SortBy.PostCount, returnedObj.SortBy); Assert.AreEqual(0, returnedObj.TotalCount); }
public void GetCommentForumsBySitenameXML_WithEditorsPickFilter() { var request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); //create the forum CommentForum commentForum = CommentForumCreateHelper(); //Create 2 Comments in the same forum. var comments = new CommentsTests_V1(); CommentInfo commentInfo = comments.CreateCommentHelper(commentForum.Id); CommentInfo commentInfo2 = comments.CreateCommentHelper(commentForum.Id); //Create Editors Pick on first comment var editorsPicks = new EditorsPicks_V1(); editorsPicks.CreateEditorsPickHelper(_sitename, commentInfo.ID); // Filter forum on editors picks filter string url = String.Format( "http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/h2g2/commentsforums/{0}/?filterBy=EditorPicks", commentForum.Id); //Check that picked comment is in results. request.RequestPageWithFullURL(url, "", "text/xml"); XmlDocument xml = request.GetLastResponseAsXML(); //Check XML. var validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForumList); validator.Validate(); var nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("api", "BBC.Dna.Api"); // Check comment is included in picks. String xPath = String.Format("api:commentForum/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:commentForum/api:commentsList/api:comments/api:comment[api:id='{0}']", commentInfo2.ID); pick = xml.SelectSingleNode(xPath, nsmgr); Assert.IsNull(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); }
private static CommentsTests_V1 GetCommentsTests() { CommentsTests_V1 commentsTests = new CommentsTests_V1(); return commentsTests; }
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 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); }