Exemple #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);
        }
        public void CreateAs_NormalUser()
        {
            XmlDocument xml;
            DnaXmlValidator myValidator;
            DnaTestURLRequest myRequest = new DnaTestURLRequest(testUtils_ratingsAPI.sitename);

            string forumId = testUtils_ratingsAPI.makeTestForum();
            string ratingId = testUtils_ratingsAPI.makeTestItem(forumId);

            string url = makeCreatePickUrl(ratingId);
            string postData = testUtils_ratingsAPI.makeTimeStamp(); // give it some sort of psot so that it uses POST, also see if it is interested in the POST data

            // create the pick

            myRequest.SetCurrentUserNormal();

            try
            {
                myRequest.RequestPageWithFullURL(url, postData, "text/xml");
            }
            catch { }

            Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.Unauthorized,
                "Should have been unauthorised. Got: " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription
                );

            xml = myRequest.GetLastResponseAsXML();
            myValidator = new DnaXmlValidator(xml.InnerXml, testUtils_ratingsAPI._schemaError);
            myValidator.Validate();
        }
Exemple #3
0
        public void missTrailingSlash()
        {
            Console.WriteLine("Before missingData - missTrailingSlash");

            // working data
            string id = "";
            string title = "";
            string parentUri = "";
            DnaTestURLRequest request = new DnaTestURLRequest(testUtils_CommentsAPI.sitename);

            // fixed input data

            // test variant data
            string postData = testUtils_CommentsAPI.makePostXml(ref id, ref title, ref parentUri);
            string mimeType = "text/xml";
            string url = "http://" + testUtils_CommentsAPI.server + "/dna/api/comments/CommentsService.svc/v1/site/";
            HttpStatusCode expectedHttpResponse = HttpStatusCode.NotFound;

            request.SetCurrentUserEditor();

            try
            {
                request.RequestPageWithFullURL(url, postData, mimeType);
            }
            catch
            {// Check to make sure that the page returned with the correct information
            }

            Assert.IsTrue(request.CurrentWebResponse.StatusCode == expectedHttpResponse,
                "Expected "+expectedHttpResponse+", got " + request.CurrentWebResponse.StatusCode);

            Console.WriteLine("After missingData - missTrailingSlash");
        } // ends missTrailingSlash
Exemple #4
0
        public void NoData()
        {
            Console.WriteLine("Before missingData - NoData");

            // test variant data
            string postData = "";
            string mimeType = "";
            string url = "http://" + testUtils_CommentsAPI.server + "/dna/api/comments/CommentsService.svc/v1/site/";
            //HttpStatusCode expectedHttpResponse = HttpStatusCode.OK;

            // consistent input data

            // working data
            DnaTestURLRequest request = new DnaTestURLRequest(testUtils_CommentsAPI.sitename);
            request.SetCurrentUserEditor();

            // now get the response - no POST data, nor any clue about the type
            try
            {
                request.RequestPageWithFullURL(url, postData, mimeType);
            }
            catch
            {// Check to make sure that the page returned with the correct information
                Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.NotFound);
            }
            Console.WriteLine("After missingData - NoData");
        } // ends NoData
        public static int runningForumCount = 0; // used to see our starting count, before we start adding forums.

        /// <summary>
        /// Simply count the number of commentsForums that have been created so far on this site
        /// </summary>
        /// <param name="SiteName">the name of the sute to query</param>
        /// <returns>teh count</returns>
        public static int countForums(string SiteName)
        {
            string _server = DnaTestURLRequest.CurrentServer;

            DnaTestURLRequest request = new DnaTestURLRequest(SiteName);

            request.SetCurrentUserNormal();

            // Setup the request url
            string url = "http://" + _server + "/dna/api/comments/CommentsService.svc/v1/site/" + SiteName + "/";

            // now get the response - no POST data, nor any clue about the input mime-type
            request.RequestPageWithFullURL(url, "", "");

            Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.OK);

            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForumList);
            validator.Validate();

            BBC.Dna.Api.CommentForumList returnedList = (BBC.Dna.Api.CommentForumList)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.CommentForumList));
            Assert.IsTrue(returnedList != null);

            return returnedList.TotalCount;
        }
        public void CreateAs_NormalUser()
        {
            XmlDocument xml;
            DnaXmlValidator myValidator;
            DnaTestURLRequest myRequest = new DnaTestURLRequest(testUtils_CommentsAPI.sitename);

            string forumId = testUtils_CommentsAPI.makeTestCommentForum();
            string commentID = testUtils_CommentsAPI.makeTestComment(forumId);

            string url = String.Format(
                "http://{0}/dna/api/comments/CommentsService.svc/V1/site/{1}/comments/{2}/editorpicks/",
                testUtils_CommentsAPI.server, testUtils_CommentsAPI.sitename, commentID
                );
            string postData = testUtils_CommentsAPI.makeTimeStamp(); // give it some sort of psot so that it uses POST, also see if it is interested in the POST data

            // create the pick

            myRequest.SetCurrentUserNormal();

            try
            {
                myRequest.RequestPageWithFullURL(url, postData, "text/xml");
            }
            catch { }

            Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.Unauthorized,
                "Should have been unauthorised. Got: " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription
                );

            xml = myRequest.GetLastResponseAsXML();
            myValidator = new DnaXmlValidator(xml.InnerXml, testUtils_CommentsAPI._schemaError);
            myValidator.Validate();
        }
Exemple #7
0
        public void GetForumSource_V1Xml_ReadOnly_Returns404()
        {
            Console.WriteLine("Before GetForumSource_V1Xml_ReadOnly_Returns404");

            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserNormal();
            request.AssertWebRequestFailure = false;

            string url = String.Format("http://" + _server + "/dna/api/forums/ForumsService.svc/V1/site/{0}/forums/{1}/threads/{2}/forumsource?format=xml", _sitename, 666, 666);

            try
            {
                request.RequestPageWithFullURL(url, null, "text/xml", String.Empty, null);
            }
            catch (WebException)
            {

            }
            Assert.AreEqual(HttpStatusCode.NotFound, request.CurrentWebResponse.StatusCode);
            ErrorData errorData = (ErrorData)StringUtils.DeserializeObject(request.GetLastResponseAsXML().OuterXml, typeof(ErrorData));
            Assert.AreEqual(ErrorType.ForumOrThreadNotFound.ToString(), errorData.Code);

            Console.WriteLine("After GetForumSource_V1Xml_ReadOnly_Returns404");

        }
Exemple #8
0
        /// <summary>
        /// Helper Function for Tests that require an editors pick.
        /// </summary>
        /// <param name="commentId"></param>
        public void CreateEditorsPickHelper( String siteName, int commentId )
        {
            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/{1}/editorpicks/", _sitename, commentId);

            DnaTestURLRequest request = new DnaTestURLRequest(siteName);
            request.SetCurrentUserEditor();
            request.RequestPageWithFullURL(url, "No data to send", "text/xml");
        }
        public void inXMLoutXML()
        {
            Console.WriteLine("Before formatParamTests - inXMLoutXML");

           // test variant data
            string mimeType = "text/xml";
            string formatParam = "XML";

            HttpStatusCode expectedResponseCode = HttpStatusCode.OK;

            // working data
            string id = "";
            string title = "";
            string parentUri = "";

            // make the post as XML data
            string postData = testUtils_ratingsAPI.makeCreatePostXml_minimal(ref id, ref title, ref parentUri);
            
            string url = testUtils_ratingsAPI.makeCreateForumUrl() + "?format=" + formatParam;

            DnaTestURLRequest request = new DnaTestURLRequest(testUtils_ratingsAPI.sitename);

            request.SetCurrentUserEditor();

            try
            {
                request.RequestPageWithFullURL(url, postData, mimeType);
            }
            catch
            {
                string resp = request.GetLastResponseAsString(); // usefull when debugging
                if (expectedResponseCode == HttpStatusCode.OK)
                    Assert.Fail("Fell over: " + resp); 
            }

            Assert.IsTrue(
                request.CurrentWebResponse.StatusCode == expectedResponseCode, 
                "HTTP repsonse. Expected:" + expectedResponseCode + " actually got " + request.CurrentWebResponse.StatusCode
                );

            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, testUtils_ratingsAPI._schemaRatingForum);
            validator.Validate();

            BBC.Dna.Api.RatingForum returnedForum = 
                (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)
                );

            Assert.IsTrue(returnedForum.Id == id);
            Assert.IsTrue(returnedForum.Title == title);
            Assert.IsTrue(returnedForum.ParentUri == parentUri);
            Assert.IsTrue(returnedForum.ratingsList.TotalCount == 0);

            Console.WriteLine("After formatParamTests - inXMLoutXML");
        } // ends inXMLoutXML
Exemple #10
0
        public void GetCallingUserInfo_AsEditor_ReturnsEditorItemInGroup()
        {
            Console.WriteLine("Before GetCallingUserInfo_AsEditor_ReturnsEditorItemInGroup");
            
            DnaTestURLRequest request = new DnaTestURLRequest("h2g2");
            request.SetCurrentUserEditor();
            request.RequestPageWithFullURL(callinguser_url);

            BBC.Dna.Users.User user = (BBC.Dna.Users.User)StringUtils.DeserializeObject(request.GetLastResponseAsXML().OuterXml, typeof(BBC.Dna.Users.User));

            Assert.IsNotNull(user.UsersListOfGroups.Find(x => x.Name.ToLower()  == "editor"));

            Console.WriteLine("After GetCallingUserInfo_AsEditor_ReturnsEditorItemInGroup");
        }
Exemple #11
0
        public void GetCallingUserInfo_AsBannedUser_ReturnsBannedStatus()
        {
            Console.WriteLine("Before GetCallingUserInfo_AsBannedUser_ReturnsBannedStatus");

            DnaTestURLRequest request = new DnaTestURLRequest("h2g2");
            request.SetCurrentUserBanned();
            request.RequestPageWithFullURL(callinguserfull_secure_url);

            BBC.Dna.Users.User user = (BBC.Dna.Users.User)StringUtils.DeserializeObject(request.GetLastResponseAsXML().OuterXml, typeof(BBC.Dna.Users.User));

            Assert.AreEqual("Banned", user.StatusAsString);

            Console.WriteLine("After GetCallingUserInfo_AsBannedUser_ReturnsBannedStatus");
        }
Exemple #12
0
        public void InitialiseServer()
        {
            SnapshotInitialisation.ForceRestore();
            using (var iis = IIsInitialise.GetIIsInitialise())
            {
                iis.RestartTestSite();
            }

            var request = new DnaTestURLRequest("h2g2");
            //request.RequestPage("status");
            request.RequestPage("status-n");
            request.RequestPageWithFullURL(string.Format("http://{0}/dna/api/comments/status.aspx", DnaTestURLRequest.CurrentServer));

        }
Exemple #13
0
        public void InitialiseServer()
        {
            if(_server == "local.bbc.co.uk:8081")
            {
                SnapshotInitialisation.ForceRestore();
                IIsInitialise.GetIIsInitialise().RestartTestSite();
            }


            var request = new DnaTestURLRequest("h2g2");
            //request.RequestPage("status");
            request.RequestPage("status-n");
            request.RequestPageWithFullURL(string.Format("http://{0}/dna/api/comments/status.aspx", DnaTestURLRequest.CurrentServer));

        }
Exemple #14
0
        public void Commentboxusingapi_Readwrite()
        {

            var testHandler = new StressTestHandler("commentboxusingapi_readwrite", _server, _serverName, _tolerance);
            var uid = "commentboxusingapi_readwrite_loadtest";
            var replace = new Dictionary<string, string> { { "UID", uid } };

            testHandler.InitialiseServer();
            testHandler.MakeReplacements(replace);
            var request = new DnaTestURLRequest("h2g2");
            request.RequestPageWithFullURL(string.Format("http://{0}/dna/h2g2/comments/acsapi?dnauid={1}&dnainitialtitle=TestingCommentBox&dnahostpageurl=http://local.bbc.co.uk/dna/haveyoursay/acs&dnaforumduration=0&skin=purexml", _server, uid));
            testHandler.RunTest();

            Assert.IsFalse(testHandler.DoesRunContainHttpErrors());
            testHandler.CompareResults();
        }
Exemple #15
0
        public void GetForumThreadsXml_ReadOnly_ReturnsValidXml()
        {
            Console.WriteLine("Before GetForumXml_ReadOnly_ReturnsValidXml");

            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserNormal();
            string url = String.Format("http://" + _server + "/dna/api/forums/ForumsService.svc/V1/site/{0}/forums/{1}/threads/{2}?format=xml", _sitename, 150, 33);
            // now get the response
            request.RequestPageWithFullURL(url, null, "text/xml");
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml.Replace("xmlns=\"http://schemas.datacontract.org/2004/07/BBC.Dna.Objects\"","") , _schemaForumThreads);
            validator.Validate();

            Console.WriteLine("After GetForumXml_ReadOnly_ReturnsValidXml");
        }
        /// <summary>
        /// Try making a rating (review)
        /// </summary>
        /// <param name="forumId">The forum on which to try hanging the review</param>
        /// <param name="theRequest">The Request object (giving the user ID etc)</param>
        /// <returns>The request object (containing the response from the server)</returns>
        private DnaTestURLRequest tryIt(string forumId, DnaTestURLRequest theRequest)
        {
            string mimeType = "text/xml";
            string ratingString = "";
            string ratingScore = "";
            string postData = testUtils_ratingsAPI.makeEntryPostXml_minimal(ref ratingString, ref ratingScore);
            string url = testUtils_ratingsAPI.makeCreatePostUrl(forumId);

            try
            {
                theRequest.RequestPageWithFullURL(url, postData, mimeType);
            }
            catch
            {
            }
            return theRequest;
        } 
Exemple #17
0
        public CommentForum CommentForumCreateHelper()
        {
            string nameSpace = "Tests";
            string id = Guid.NewGuid().ToString();
            ModerationStatus.ForumStatus moderationStatus = ModerationStatus.ForumStatus.Reactive;
            DateTime closingDate = DateTime.MinValue;

            Console.WriteLine("Before CreateCommentForum");

            var request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserEditor();

            string title = "Functiontest Title";
            string parentUri = "http://www.bbc.co.uk/dna/h2g2/";
            string commentForumXml = String.Format("<commentForum xmlns=\"BBC.Dna.Api\">" +
                                                   "<id>{0}</id>" +
                                                   "<namespace>{3}</namespace>" +
                                                   "<title>{1}</title>" +
                                                   "<parentUri>{2}</parentUri>" +
                                                   "<closeDate>{4}</closeDate>" +
                                                   "<moderationServiceGroup>{5}</moderationServiceGroup>" +
                                                   "</commentForum>", id, title, parentUri, nameSpace,
                                                   closingDate.ToString("yyyy-MM-dd"), moderationStatus);

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/",
                                       _sitename);
            // now get the response
            request.RequestPageWithFullURL(url, commentForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            // 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.IsTrue(returnedForum.Id == id);

            Assert.IsTrue(returnedForum.ParentUri == parentUri);
            Assert.IsTrue(returnedForum.Title == title);
            Assert.IsTrue(returnedForum.ModerationServiceGroup == moderationStatus);
            return returnedForum;
        }
Exemple #18
0
        public void GetReviewForumXML()
        {
            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserNormal();
            string url = String.Empty;
            BBC.Dna.Api.RatingForum ratingForum = CreateRatingForum();

            // Setup the request url
            url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{1}/", _sitename, ratingForum.Id);
           

            // 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();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaRatingForum);
            validator.Validate();

            BBC.Dna.Api.RatingForum returnedForum = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum));
            
        }
Exemple #19
0
        public void GetArticle_ReadOnly_ReturnsValidXml()
        {
            Console.WriteLine("Before GetArticle_ReadOnly_ReturnsValidXml");

            int[] ids = { 559, 586, 630, 649, 667, 883, 937, 964, 1251, 1422, 79526,87130,87310,
                            88274,88319,88373,89804,91298,92369,92440,92495,99119,99452,99524,101755,101782};
            
            foreach (var id in ids)
            {
                DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
   
                Console.WriteLine("Validing ID:" + id);
                string url = String.Format("http://" + _server + "/dna/api/articles/ArticleService.svc/V1/site/{0}/articles/{1}?format=xml", _sitename, id);
                // now get the response
                request.RequestPageWithFullURL(url, null, "text/xml");
                // Check to make sure that the page returned with the correct information
                XmlDocument xml = request.GetLastResponseAsXML();
                DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml.Replace("xmlns=\"http://schemas.datacontract.org/2004/07/BBC.Dna.Objects\"", ""), _schemaArticle);
                validator.Validate();            
            }
            Console.WriteLine("After GetArticle_ReadOnly_ReturnsValidXml");
        }
        public void CreateTestForumAndComment(ref CommentForum commentForum, ref CommentInfo returnedComment)
        {
            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserNormal();
            //create the forum
            if (string.IsNullOrEmpty(commentForum.Id))
            {
                commentForum = commentsHelper.CommentForumCreate("tests", Guid.NewGuid().ToString());
            }

            string text = "Functiontest Title" + Guid.NewGuid().ToString();
            string commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" +
                "<text>{0}</text>" +
                "</comment>", text);

            // Setup the request url
            string url = String.Format(_secureserver + "dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/", _sitename, commentForum.Id);
            // now get the response
            request.RequestPageWithFullURL(url, commentForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForum);
            validator.Validate();

            //check the TextAsHtml element
            //string textAsHtml = xml.DocumentElement.ChildNodes[2].InnerXml;
            //Assert.IsTrue(textAsHtml == "<div class=\"dna-comment text\" xmlns=\"\">" + text + "</div>");

            returnedComment = (CommentInfo)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentInfo));
            Assert.IsTrue(returnedComment.text == text);
            Assert.IsNotNull(returnedComment.User);
            Assert.IsTrue(returnedComment.User.UserId == request.CurrentUserID);

            DateTime created = DateTime.Parse(returnedComment.Created.At);
            DateTime createdTest = BBC.Dna.Utils.TimeZoneInfo.GetTimeZoneInfo().ConvertUtcToTimeZone(DateTime.Now.AddMinutes(5));
            Assert.IsTrue(created < createdTest);//should be less than 5mins
            Assert.IsTrue(!String.IsNullOrEmpty(returnedComment.Created.Ago));
        }
Exemple #21
0
        protected static string CallAPIRequest(DnaTestURLRequest request, string requestURL, string postData, DnaTestURLRequest.usertype userType, string requestMethod)
        {
            if (userType == DnaTestURLRequest.usertype.SUPERUSER)
            {
                request.SetCurrentUserSuperUser();
            } 
            else if (userType == DnaTestURLRequest.usertype.EDITOR)
            {
                request.SetCurrentUserEditor();
            }
            else if (userType == DnaTestURLRequest.usertype.NORMALUSER)
            {
                request.SetCurrentUserNormal();
            }
            else
            {
                request.SetCurrentUserNotLoggedInUser();
            }

            request.AssertWebRequestFailure = false;
            request.RequestPageWithFullURL(requestURL, postData, "application/json", requestMethod);
            return requestURL;
        }
        public void CreateCommentForum_AsFormPost()
        {
            Console.WriteLine("Before CreateCommentForum");

            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserEditor();

            string id = "FunctiontestCommentForum-" + Guid.NewGuid().ToString();//have to randomize the string to post
            string title = "Functiontest Title";
            string parentUri = "http://www.bbc.co.uk/dna/h2g2/";

            string commentForumXml = String.Format("id={0}&" +
                "title={1}&" +
                "parentUri={2}", HttpUtility.HtmlEncode(id), HttpUtility.HtmlEncode(title), HttpUtility.HtmlEncode(parentUri));

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/create.htm", _sitename);
            // now get the response
            request.RequestPageWithFullURL(url, commentForumXml, "application/x-www-form-urlencoded", null, headers);
            Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.MovedPermanently, "Not Moved - Status Code = " + request.CurrentWebResponse.StatusCode.ToString());
            Assert.IsTrue(request.CurrentWebResponse.Headers["Location"] == headers["referer"] + "?resultCode=" + ErrorType.Ok.ToString());

        }
Exemple #23
0
        public void AddComplaintItemToModQueue()
        {

            DnaTestURLRequest request = new DnaTestURLRequest(_siteName);
            request.SetCurrentUserEditor();

            string uri = "http://www.bbc.co.uk/dna/h2g2/";
            string callback = "http://www.bbc.co.uk/dna/h2g2";
            string complaintText = "This is a test complaint";

            string moderationItemXml = String.Format("<item xmlns=\"BBC.Dna.Moderation\">" +
                "<uri>{0}</uri>" +
                "<callbackuri>{1}</callbackuri>" +
                "<complainttext>{2}</complainttext>" +
                "</item>", uri, callback, complaintText);

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/moderation/ModerationService.svc/V1/site/{0}/items/", _siteName);

            // Make a POST Request with the data
            request.RequestPageWithFullURL(url, moderationItemXml, "text/xml");
            Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.OK);
        }
Exemple #24
0
        // mising the trailing / cause an exception 
        // "Web request ( http://dnadev.national.core.bbc.co.uk:8082/comments/commentsService.svc/v1/site/h2g2/commentsforums/FunctiontestCommentForum-e0d90d33-b3fe-4286-bfcb-5da2feafe9fa ) failed with error : The underlying connection was closed: An unexpected error occurred on a receive."
        // this happens before the request.CurrentWebResponse is given contents (so it stays null)
        public void missTrailingSlash()
        {
            Console.WriteLine("Before missingData - missTrailingSlash");

            // working data
            string testForumId = testUtils_CommentsAPI.makeTestCommentForum();
            DnaTestURLRequest request = new DnaTestURLRequest(testUtils_CommentsAPI.sitename);

            // fixed input data
            string mimeType = "text/xml";
            string postData = testUtils_CommentsAPI.makeCommentPostXML();

            // test variant data
            string url = String.Format("http://{0}{1}site/{2}/commentsforums/{3}",
                testUtils_CommentsAPI.server,
                testUtils_CommentsAPI._resourceLocation,
                testUtils_CommentsAPI.sitename,
                testForumId
                );

            request.SetCurrentUserEditor();

            // Now try and create the comment
            bool assertThrown = false;
            try
            {
                request.RequestPageWithFullURL(url, postData, mimeType);
            }
            catch
            {
                assertThrown = true;
            }

            Assert.IsTrue(assertThrown);

            Console.WriteLine("After missingData - missTrailingSlash");
        } 
Exemple #25
0
        public void GetCommentForumHTML_XsltCacheTest()
        {
            Console.WriteLine("Before GetCommentForumHTML_XsltCacheTest");

            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}/",
                                       _sitename);
            // now get the response
            request.RequestPageWithFullURL(url);
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            var validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForumList);
            validator.Validate();
            var returnedList =
                (CommentForumList)
                StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList));
            //get the first for test
            CommentForum commentForum = returnedList.CommentForums[0];

            // Setup the request url
            url =
                String.Format(
                    "http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/",
                    _sitename, commentForum.Id);

            // now get the response
            request.RequestPageWithFullURL(url, "", "text/html");
            Assert.IsTrue(request.GetLastResponseAsString().IndexOf("<div") >= 0);

            commentForum = returnedList.CommentForums[1];
            // Setup the request url
            url =
                String.Format(
                    "http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/",
                    _sitename, commentForum.Id);

            // now get the response
            request.RequestPageWithFullURL(url, "", "text/html");
            Assert.IsTrue(request.GetLastResponseAsString().IndexOf("<div") >= 0);


            Console.WriteLine("After GetCommentForumHTML_XsltCacheTest");
        }
Exemple #26
0
        public void GetCommentForumsBySitenameXML()
        {
            Console.WriteLine("Before GetCommentForumsBySitenameXML");

            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}/",
                                       _sitename);

            // 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, _schemaCommentForumList);
            validator.Validate();

            var returnedList =
                (CommentForumList)
                StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList));
            Console.WriteLine("After GetCommentForumsBySitenameXML");
        }
Exemple #27
0
        public void GetCommentForumJSON()
        {
            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}/",
                                       _sitename);
            // now get the response
            request.RequestPageWithFullURL(url);
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            var validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForumList);
            validator.Validate();
            var returnedList =
                (CommentForumList)
                StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList));
            //get the first for test
            CommentForum commentForum = returnedList.CommentForums.First();

            // Setup the request url
            url =
                String.Format(
                    "http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/",
                    _sitename, commentForum.Id);

            // now get the response
            request.RequestPageWithFullURL(url, "", "application/json");

            var returnedForum =
                (CommentForum)
                StringUtils.DeserializeJSONObject(request.GetLastResponseAsString(), typeof (CommentForum));
        }
Exemple #28
0
        public void GetCommentForumXML_WithSorting_ByCreated()
        {
            var request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserEditor();

            string id = "FunctiontestCommentForum-" + Guid.NewGuid(); //have to randomize the string to post
            string title = "Functiontest Title";
            string parentUri = "http://www.bbc.co.uk/dna/h2g2/";
            string commentForumXml = String.Format("<commentForum xmlns=\"BBC.Dna.Api\">" +
                                                   "<id>{0}</id>" +
                                                   "<title>{1}</title>" +
                                                   "<parentUri>{2}</parentUri>" +
                                                   "</commentForum>", id, title, parentUri);

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/",
                                       _sitename);
            // now get the response
            request.RequestPageWithFullURL(url, commentForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            // 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.IsTrue(returnedForum.Id == id);
            //create 10 comments
            for (int i = 0; i < 3; i++)
            {
                string text = "Functiontest Title" + Guid.NewGuid();
                string commentXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" +
                                                  "<text>{0}</text>" +
                                                  "</comment>", text);

                // Setup the request url
                url =
                    String.Format(
                        "https://" + _secureServer + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/",
                        _sitename, returnedForum.Id);
                // now get the response
                request.RequestPageWithFullURL(url, commentXml, "text/xml");
            }
            //////////////////////////////
            //set up sorting tests
            //////////////////////////////
            url =
                String.Format(
                    "http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/",
                    _sitename, returnedForum.Id);
            string sortBy = SortBy.Created.ToString();
            string sortDirection = SortDirection.Ascending.ToString();
            string sortUrl = url + "?sortBy={0}&sortDirection={1}";

            //test ascending created
            request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml");
            var returnedList =
                (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum));
            Assert.IsTrue(returnedList.commentList.SortDirection.ToString() == sortDirection);
            Assert.IsTrue(returnedList.commentList.SortBy.ToString() == sortBy);

            DateTime prevCreate = DateTime.MinValue;
            DateTime currentDate = DateTime.MinValue;
            for (int i = 0; i < returnedList.commentList.comments.Count; i++)
            {
                currentDate = DateTime.Parse(returnedList.commentList.comments[i].Created.At);
                Assert.IsTrue(currentDate >= prevCreate);
                prevCreate = currentDate;
            }

            //test descending created
            sortBy = SortBy.Created.ToString();
            sortDirection = SortDirection.Descending.ToString();
            request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml");
            returnedList =
                (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum));
            Assert.IsTrue(returnedList.commentList.SortDirection.ToString() == sortDirection);
            Assert.IsTrue(returnedList.commentList.SortBy.ToString() == sortBy);

            prevCreate = DateTime.MaxValue;
            for (int i = 0; i < returnedList.commentList.comments.Count; i++)
            {
                currentDate = DateTime.Parse(returnedList.commentList.comments[i].Created.At);
                Assert.IsTrue(currentDate <= prevCreate);
                prevCreate = currentDate;
            }

            //test descending created case insensitive
            sortBy = SortBy.Created.ToString();
            sortDirection = SortDirection.Descending.ToString().ToLower();
            request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml");
            returnedList =
                (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum));
            Assert.IsTrue(returnedList.commentList.SortDirection.ToString() != sortDirection);
            // should fail and return the default
            Assert.IsTrue(returnedList.commentList.SortDirection.ToString() == SortDirection.Ascending.ToString());
            // should fail and return the default
            Assert.IsTrue(returnedList.commentList.SortBy.ToString() == sortBy);

            prevCreate = DateTime.MinValue;
            for (int i = 0; i < returnedList.commentList.comments.Count; i++)
            {
                currentDate = DateTime.Parse(returnedList.commentList.comments[i].Created.At);
                Assert.IsTrue(currentDate >= prevCreate);
                prevCreate = currentDate;
            }

            //test sort by created case insensitive
            sortBy = SortBy.Created.ToString().ToLower();
            sortDirection = SortDirection.Descending.ToString();
            request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml");
            returnedList =
                (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum));
            Assert.IsTrue(returnedList.commentList.SortDirection.ToString() == sortDirection);
            Assert.IsTrue(returnedList.commentList.SortBy.ToString() != sortBy);
            // should fail and return the default which is Created
            Assert.IsTrue(returnedList.commentList.SortBy.ToString() == SortBy.Created.ToString());
            // should fail and return the default which is Created

            prevCreate = DateTime.MaxValue;
            for (int i = 0; i < returnedList.commentList.comments.Count; i++)
            {
                currentDate = DateTime.Parse(returnedList.commentList.comments[i].Created.At);
                Assert.IsTrue(currentDate <= prevCreate);
                prevCreate = currentDate;
            }


            //test sort by created case with defaults (created and ascending
            sortBy = "";
            sortDirection = "";
            request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml");
            returnedList =
                (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum));
            Assert.IsTrue(returnedList.commentList.SortDirection.ToString() != sortDirection);
            Assert.IsTrue(returnedList.commentList.SortDirection.ToString() == SortDirection.Ascending.ToString());
            Assert.IsTrue(returnedList.commentList.SortBy.ToString() != sortBy);
            // should fail and return the default which is Created
            Assert.IsTrue(returnedList.commentList.SortBy.ToString() == SortBy.Created.ToString());
            // should fail and return the default which is Created

            prevCreate = DateTime.MinValue;
            for (int i = 0; i < returnedList.commentList.comments.Count; i++)
            {
                currentDate = DateTime.Parse(returnedList.commentList.comments[i].Created.At);
                Assert.IsTrue(currentDate >= prevCreate);
                prevCreate = currentDate;
            }
        }
Exemple #29
0
        public void GetCommentForumsBySitenameXML_InvalidSiteName()
        {
            Console.WriteLine("Before GetCommentForumsBySitenameXML");

            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}/",
                                       "NOTAVALIDSITE");

            try
            {
                // now get the response
                request.RequestPageWithFullURL(url, "", "text/xml");
            }
            catch { }
            Assert.AreEqual(request.CurrentWebResponse.StatusCode, HttpStatusCode.NotFound);
        }
Exemple #30
0
        public void GetCommentForumsBySitenameJSON()
        {
            Console.WriteLine("Before GetCommentForumsBySitenameJSON");

            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}/",
                                       _sitename);

            // now get the response
            request.RequestPageWithFullURL(url, "", "application/json");
            var returnedList =
                (CommentForumList)
                StringUtils.DeserializeJSONObject(request.GetLastResponseAsString(), typeof (CommentForumList));
            Console.WriteLine("After GetCommentForumsBySitenameJSON");
        }