Exemplo n.º 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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
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);

        }
Exemplo n.º 4
0
        public void TermsFilterAdminPage_CreateTermRefreshSitePostViaApi_CorrectlyBlocksContent()
        {
            const int modClassId = 3;
            var request = new DnaTestURLRequest(SiteName) { UseEditorAuthentication = true };
            request.SetCurrentUserSuperUser();
            request.RequestPage(string.Format("termsfilteradmin?modclassid={0}&skin=purexml&ignorecache=1", modClassId));
            ValidateResponse(request);

            var doc = request.GetLastResponseAsXML();
            var termNode = doc.SelectSingleNode("//H2G2/TERMSFILTERADMIN/TERMSLIST/TERM");
            var termNodeCount = doc.SelectNodes("//H2G2/TERMSFILTERADMIN/TERMSLIST/TERM").Count;
            var termText = "你好";
            TermAction expectedAction = TermAction.ReEdit;

            var postParams = new Queue<KeyValuePair<string, string>>();
            postParams.Enqueue(new KeyValuePair<string, string>("termtext", termText));
            postParams.Enqueue(new KeyValuePair<string, string>("termaction", expectedAction.ToString()));

            //update the first term
            request.RequestPage(string.Format("termsfilteradmin?modclassid={0}&action=UPDATETERM&skin=purexml", modClassId),
                postParams);

            ValidateResponse(request);
            ValidateOkResult(request, "TermsUpdateSuccess", "Terms updated successfully.");
            doc = request.GetLastResponseAsXML();
            termNode = doc.SelectSingleNode("//H2G2/TERMSFILTERADMIN/TERMSLIST/TERM[text()='" + termText + "']");
            Assert.AreEqual(expectedAction.ToString(), termNode.Attributes["ACTION"].Value);
            Assert.AreEqual(termText, termNode.InnerText);
            Assert.AreEqual(termNodeCount + 1, doc.SelectNodes("//H2G2/TERMSFILTERADMIN/TERMSLIST/TERM").Count);

            //check history audit
            var terms = new List<Term>();
            terms.Add(new Term { Id = Int32.Parse(termNode.Attributes["ID"].Value), Action = expectedAction });
            CheckAuditTable(modClassId, terms);

            //Do siterefresh
            request.RequestPage("termsfilteradmin?action=REFRESHCACHE");

            //Post Via Comments Api
            var commentForumObj = new CommentForumTests_V1();
            var commentForum = commentForumObj.CommentForumCreateHelper();
            var commentXml = String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><comment xmlns=\"BBC.Dna.Api\">" +
                "<text>{0}</text>" +
                "</comment>", termText);

            // Setup the request url
            var url = String.Format("https://{0}/dna/api/comments/CommentsService.svc/V1/site/{1}/commentsforums/{2}/", DnaTestURLRequest.SecureServerAddress, commentForum.SiteName, commentForum.Id);
            // now get the response
            request = new DnaTestURLRequest(commentForum.SiteName);
            request.SetCurrentUserNormal();
            var exceptionThrown = false;
            try
            {
                request.RequestPageWithFullURL(url, commentXml, "text/xml");

            }
            catch (Exception)
            {
                exceptionThrown = true;
                Assert.AreEqual(HttpStatusCode.BadRequest, request.CurrentWebResponse.StatusCode);
            }
            Assert.IsTrue(exceptionThrown);
            


        }
Exemplo n.º 5
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);

           
        }
Exemplo n.º 6
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);
        }