Example #1
0
        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);
        }
Example #2
0
        private CommentForum CreateTestCommentForum(bool isReactiveModeration)
        {
            CommentsTests_V1 ct = new CommentsTests_V1();
            CommentForum testCommentForum = null;
            if (isReactiveModeration)
            {
                testCommentForum = ct.CommentForumCreate("Tests Reactive", Guid.NewGuid().ToString(), ModerationStatus.ForumStatus.Reactive);
            }
            else
            {
                testCommentForum = ct.CommentForumCreate("Tests Premod", Guid.NewGuid().ToString(), ModerationStatus.ForumStatus.PreMod);
            }

            return testCommentForum;
        }
Example #3
0
        public void StartUp()
        {
            SnapshotInitialisation.RestoreFromSnapshot();
            _context = new FullInputContext("");

            _siteList = _context.SiteList;

            // Create a comment forums to post tweets to, and the corresponding URLs
            CommentsTests_V1 ct = new CommentsTests_V1();
            _commentForumReactive = ct.CommentForumCreate("Tests Reactive", Guid.NewGuid().ToString(),ModerationStatus.ForumStatus.Reactive);
            _tweetPostUrlReactive= String.Format("http://" + _server + "/dna/api/comments/TwitterService.svc/V1/site/{0}/commentsforums/{1}/",_sitename, _commentForumReactive.Id);

            _commentForumPremod = ct.CommentForumCreate("Tests Premod", Guid.NewGuid().ToString(),ModerationStatus.ForumStatus.PreMod);
            _tweetPostUrlPremod = String.Format("http://" + _server + "/dna/api/comments/TwitterService.svc/V1/site/{0}/commentsforums/{1}/", _sitename, _commentForumPremod.Id);
        }
Example #4
0
        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);

        }
Example #5
0
        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);


        }
Example #6
0
        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);

        }
Example #7
0
        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);
        }
 private static CommentsTests_V1 GetCommentsTests()
 {
     CommentsTests_V1 commentsTests = new CommentsTests_V1();
     return commentsTests;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public CommentsNeroRatings_v1()
 {
     commentsHelper = new CommentsTests_V1();
     SnapshotInitialisation.RestoreFromSnapshot();
 }
Example #10
0
        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);

           
        }
Example #11
0
        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);
        }
Example #12
0
        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);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public CommentsNeroRatings_v1()
 {
     commentsHelper = new CommentsTests_V1();
   
 }