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
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 Test02RequestHierarchyPageWithSiteID() { Console.WriteLine("Test02RequestHierarchyPageWithSiteID"); XmlDocument xmldoc = new XmlDocument(); DnaTestURLRequest request = new DnaTestURLRequest("haveyoursay"); try { request.RequestAspxPage("HierarchyPage.aspx", "siteid=16&skin=purexml"); xmldoc.LoadXml(request.GetLastResponseAsString()); } catch (Exception e) { System.Console.Write(e.Message + request.GetLastResponseAsString()); //Assert.Fail(e.Message + _asphost.ResponseString); } Assert.IsNotNull(xmldoc.SelectSingleNode("//HIERARCHYNODES"), "Expected a HIERARCHYNODES XML Tag!!!"); Assert.AreEqual("16", xmldoc.SelectSingleNode("//HIERARCHYNODES").Attributes["SITEID"].Value, "Incorrect site id in XML"); }
public void TestXSLTCaching() { Console.WriteLine("Before TestXSLTCaching"); // First log the user into the system. DnaTestURLRequest request = new DnaTestURLRequest("h2g2"); request.SetCurrentUserEditor(); // Now create the test skin to use StreamWriter test1file = new StreamWriter(_testXSLTFilename); test1file.Write(CreateXSLTFile("XSLT caching test 1")); test1file.Close(); // Now call the acs page with the clear templates flag and // check to make sure that it returns the text we supplied in the new xslt file. request.RequestPage("acs?d_skinfile=" + _testXSLTFilename + "&clear_templates=1"); Assert.IsTrue(request.GetLastResponseAsString().Contains("XSLT caching test 1")); // Now update the file so that it says something different. StreamWriter test2file = new StreamWriter(_testXSLTFilename); test2file.Flush(); test2file.Write(CreateXSLTFile("XSLT caching test 2")); test2file.Close(); // Now call the same page. We should still have the old transform in cache, so the text should still reflect what was in the old file! request.RequestPage("acs?d_skinfile=" + _testXSLTFilename); Assert.IsTrue(request.GetLastResponseAsString().Contains("XSLT caching test 1")); // Now call the acs page and flush the cache. We should now see that it is using the new file and not the old! request.RequestPage("acs?d_skinfile=" + _testXSLTFilename + "&clear_templates=1"); Assert.IsFalse(request.GetLastResponseAsString().Contains("XSLT caching test 1")); Assert.IsTrue(request.GetLastResponseAsString().Contains("XSLT caching test 2")); // Now delete the file totally! Check to make sure we still have the cached version! File.Delete(_testXSLTFilename); request.RequestPage("acs?d_skinfile=" + _testXSLTFilename); Assert.IsFalse(request.GetLastResponseAsString().Contains("XSLT caching test 1")); Assert.IsTrue(request.GetLastResponseAsString().Contains("XSLT caching test 2")); Console.WriteLine("After TestXSLTCaching"); }
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; }
public void onlyOnce() { Console.WriteLine("Before duplicationTests - onlyOnce"); DnaTestURLRequest myRequest = new DnaTestURLRequest(testUtils_CommentsAPI.sitename); // Make the forum into which to put ratings string testForumId = testUtils_ratingsAPI.makeTestForum(); myRequest.SetCurrentUserNormal(); // make a rating for the first time myRequest = tryIt(testForumId, myRequest); Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.OK, "Failed to make the test rating. Expecting " + HttpStatusCode.OK + " as response, got " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription ); // try and make a second one as the same person myRequest = tryIt(testForumId, myRequest); Assert.IsTrue(myRequest.CurrentWebResponse.StatusCode == HttpStatusCode.BadRequest, "Error making second attempt. Expecting " + HttpStatusCode.BadRequest + " as response, got " + myRequest.CurrentWebResponse.StatusCode + "\n" + myRequest.CurrentWebResponse.StatusDescription ); XmlDocument xml = myRequest.GetLastResponseAsXML(); DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, testUtils_ratingsAPI._schemaError); validator.Validate(); string resStr = myRequest.GetLastResponseAsString(); Assert.IsTrue(Regex.Match(resStr, "code\\>MultipleRatingByUser<").Success == true); Assert.IsTrue(Regex.Match(resStr, "already").Success == true); Console.WriteLine("After duplicationTests - onlyOnce"); }
public void FrontPageRedirector_CustomSkin_RedirectsToCPlusHomeWithSkinInTact() { try { SetSiteOptions(""); var request = new DnaTestURLRequest("h2g2"); request.SetCurrentUserNormal(); request.RequestPage("classic/", null); var lastRequest = request.GetLastResponseAsString(); Assert.IsTrue(lastRequest.IndexOf("%2fdna%2fh2g2%2fclassic%2fhome") > 0); } finally { UnSetSiteOptions(); } }
public void FrontPageRedirector_NoSiteOption_RedirectsToCPlusHome() { try { SetSiteOptions(""); var request = new DnaTestURLRequest(_siteName); request.SetCurrentUserNormal(); request.RequestPage("/", null); var lastRequest = request.GetLastResponseAsString(); Assert.IsTrue(lastRequest.IndexOf("%2fdna%2fmbiplayer%2fhome") > 0); } finally { UnSetSiteOptions(); } }
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)); }
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)); }
public void GetCommentForumsBySitenameAndPrefixXML_WithSorting_ByCreated() { Console.WriteLine("Before GetCommentForumsBySitenameXML"); //create 3 forums with a prefix and one without var request = new DnaTestURLRequest(_sitename); request.SetCurrentUserEditor(); string prefix = "prefixfunctionaltest-"; //have to randomize the string to post string title = "Functiontest Title"; string parentUri = "http://www.bbc.co.uk/dna/h2g2/"; string id = string.Empty; string url = string.Empty; string commentForumXml = string.Empty; XmlDocument xml = null; DnaXmlValidator validator = null; CommentForum returnedForum = null; for (int i = 0; i < 3; i++) { id = prefix + Guid.NewGuid(); 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 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 xml = request.GetLastResponseAsXML(); validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForum); validator.Validate(); returnedForum = (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum)); Assert.IsTrue(returnedForum.Id == id); } //create a non-prefixed one id = Guid.NewGuid().ToString(); 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 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 xml = request.GetLastResponseAsXML(); validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForum); validator.Validate(); returnedForum = (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum)); Assert.IsTrue(returnedForum.Id == id); // Setup the request url url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/?prefix={1}", _sitename, prefix); // now get the response request.RequestPageWithFullURL(url, "", "text/xml"); // Check to make sure that the page returned with the correct information xml = request.GetLastResponseAsXML(); validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForumList); validator.Validate(); var returnedList = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList != null); Console.WriteLine("After GetCommentForumsBySitenameXML"); 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"); returnedList = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.SortBy.ToString() == sortBy); DateTime prevCreate = DateTime.MinValue; DateTime currentDate = DateTime.MinValue; for (int i = 0; i < returnedList.CommentForums.Count; i++) { currentDate = DateTime.Parse(returnedList.CommentForums[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 = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.SortBy.ToString() == sortBy); prevCreate = DateTime.MaxValue; for (int i = 0; i < returnedList.CommentForums.Count; i++) { currentDate = DateTime.Parse(returnedList.CommentForums[i].Created.At); Assert.IsTrue(currentDate <= prevCreate); prevCreate = currentDate; } //test descending created case insensitive sortBy = SortBy.Created.ToString(); sortDirection = SortDirection.Ascending.ToString().ToLower(); request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml"); returnedList = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() != sortDirection); // should fail and return the default Assert.IsTrue(returnedList.SortDirection.ToString() == SortDirection.Ascending.ToString()); // should fail and return the default Assert.IsTrue(returnedList.SortBy.ToString() == sortBy); prevCreate = DateTime.MinValue; for (int i = 0; i < returnedList.CommentForums.Count; i++) { currentDate = DateTime.Parse(returnedList.CommentForums[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 = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.SortBy.ToString() != sortBy); // should fail and return the default which is Created Assert.IsTrue(returnedList.SortBy.ToString() == SortBy.Created.ToString()); // should fail and return the default which is Created prevCreate = DateTime.MaxValue; for (int i = 0; i < returnedList.CommentForums.Count; i++) { currentDate = DateTime.Parse(returnedList.CommentForums[i].Created.At); Assert.IsTrue(currentDate <= prevCreate); prevCreate = currentDate; } }
public void GetCommentForumsBySitenameXML_WithSorting_ByPostCount() { 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(); string sortBy = SortBy.PostCount.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 = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.SortBy.ToString() == sortBy); int prevTotal = 0; int currentTotal; for (int i = 0; i < returnedList.CommentForums.Count; i++) { currentTotal = returnedList.CommentForums[i].commentSummary.Total; Assert.IsTrue(currentTotal >= prevTotal); prevTotal = currentTotal; } //test descending created sortBy = SortBy.PostCount.ToString(); sortDirection = SortDirection.Descending.ToString(); request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml"); returnedList = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.SortBy.ToString() == sortBy); prevTotal = int.MaxValue; for (int i = 0; i < returnedList.CommentForums.Count; i++) { currentTotal = returnedList.CommentForums[i].commentSummary.Total; Assert.IsTrue(currentTotal <= prevTotal); prevTotal = currentTotal; } //test descending created case insensitive sortBy = SortBy.PostCount.ToString(); sortDirection = SortDirection.Ascending.ToString().ToLower(); request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml"); returnedList = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() != sortDirection); // should fail and return the default Assert.IsTrue(returnedList.SortDirection.ToString() == SortDirection.Ascending.ToString()); // should fail and return the default Assert.IsTrue(returnedList.SortBy.ToString() == sortBy); prevTotal = 0; for (int i = 0; i < returnedList.CommentForums.Count; i++) { currentTotal = returnedList.CommentForums[i].commentSummary.Total; Assert.IsTrue(currentTotal >= prevTotal); prevTotal = currentTotal; } //test sort by created case insensitive sortBy = SortBy.PostCount.ToString().ToLower(); sortDirection = SortDirection.Descending.ToString(); request.RequestPageWithFullURL(String.Format(sortUrl, sortBy, sortDirection), "", "text/xml"); returnedList = (CommentForumList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForumList)); Assert.IsTrue(returnedList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.SortBy.ToString() != sortBy); // should fail and return the default which is Created Assert.AreEqual(SortBy.Created, returnedList.SortBy); // should fail and return the default which is Created }
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); }
// ============================================================================================= /// <summary> /// Does all the work /// </summary> private DnaTestURLRequest makeRequest(string formatParam, String file, String postData, String mimeType) { DnaTestURLRequest request = new DnaTestURLRequest(testUtils_CommentsAPI.sitename); request.SetCurrentUserEditor(); String url = "http://" + testUtils_CommentsAPI.server + "/dna/api/comments/CommentsService.svc/v1/site/" + testUtils_CommentsAPI.sitename + "/" + file + "?format=" + formatParam; // now get the response - minimal POST data, no clue about the input mime-type , user is not allowed, however try { request.RequestPageWithFullURL(url, postData, mimeType); } catch { string respStr = request.GetLastResponseAsString(); } return request; } // ends makeRequest
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"); }
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; } }
public void CreateReviewForum_InReactive() { Console.WriteLine("Before CreateReviewForum"); 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/"; ModerationStatus.ForumStatus moderationStatus = ModerationStatus.ForumStatus.Reactive; string ratingForumXml = String.Format("<ratingForum xmlns=\"BBC.Dna.Api\">" + "<id>{0}</id>" + "<title>{1}</title>" + "<parentUri>{2}</parentUri>" + "<moderationServiceGroup>{3}</moderationServiceGroup>" + "</ratingForum>", id, title, parentUri, moderationStatus); // Setup the request url string url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/", _sitename); // now get the response request.RequestPageWithFullURL(url, ratingForumXml, "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(); 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)); Assert.IsTrue(returnedForum.ModerationServiceGroup == moderationStatus); Console.WriteLine("After GetReviewForumXML"); }
public void GetUserContributionsForEmbeddedCommentsTypeXML_UserWithContributions_ReturnsValidXML() { Console.WriteLine("Before GetUserContributionsForEmbeddedCommentsTypeXML_UserWithContributions_ReturnsValidXML"); string contributions_for_type_xml_url = test_contributionsUrl.Replace("{user}", test_identityuserid) + "/type/EmbeddedComments?format=xml"; DnaTestURLRequest request = new DnaTestURLRequest("h2g2"); request.SetCurrentUserNormal(); request.RequestPageWithFullURL(contributions_for_type_xml_url); Contributions contributions = (Contributions)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(Contributions)); foreach (Contribution contribution in contributions.ContributionItems) { Assert.AreEqual(SiteType.EmbeddedComments, contribution.SiteType); } Console.WriteLine("After GetUserContributionsForEmbeddedCommentsTypeXML_UserWithContributions_ReturnsValidXML"); }
public void GetReviewForumJSON() { 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, "", "application/json"); BBC.Dna.Api.RatingForum returnedForum = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeJSONObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); }
/// <summary> /// Creates a review forum and returns it /// </summary> /// <returns>The create review forum</returns> private BBC.Dna.Api.RatingForum CreateRatingForum() { DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserEditor(); string id = "FunctiontestReviewForum-" + Guid.NewGuid().ToString();//have to randomize the string to post string title = "Functiontest Title"; string parentUri = "http://www.bbc.co.uk/dna/h2g2/"; string ratingForumXml = String.Format("<ratingForum xmlns=\"BBC.Dna.Api\">" + "<id>{0}</id>" + "<title>{1}</title>" + "<parentUri>{2}</parentUri>" + "</ratingForum>", id, title, parentUri); // Setup the request url string url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/", _sitename); // now get the response request.RequestPageWithFullURL(url, ratingForumXml, "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(); DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaRatingForum); validator.Validate(); return (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); }
/// <summary> /// tests successful RatingForumIdentityUserCreate /// </summary> private RatingForum RatingForumIdentityUserCreate(string nameSpace, string id, ModerationStatus.ForumStatus moderationStatus, DateTime closingDate) { Console.WriteLine("Before RatingForumIdentityUserCreate"); string identitySitename = "identity606"; DnaTestURLRequest request = new DnaTestURLRequest(identitySitename); string userName = "******" + DateTime.Now.Ticks.ToString(); string userEmail = userName + "@bbc.co.uk"; Assert.IsTrue(request.SetCurrentUserAsNewIdentityUser(userName, "password", "RatingForum User", userEmail, "1989-12-31", TestUserCreator.IdentityPolicies.Adult, 1, TestUserCreator.UserType.SuperUser), "Failed to create a test identity user"); //Assert.IsTrue(request.SetCurrentUserAsNewIdentityUser(userName, "password", "RatingForum User", userEmail, "1989-12-31", TestUserCreator.IdentityPolicies.Adult, true, true), "Failed to create a test identity user"); //using (IDnaDataReader reader = DnaMockery.CreateDatabaseInputContext().CreateDnaDataReader("")) //{ // string sql = "EXEC dbo.createnewuserfromidentityid " + request.CurrentIdentityUserID + ",0,'" + userName + "','" + userEmail + "',74"; // reader.ExecuteDEBUGONLY(sql); // if (reader.Read()) // { // int dnauserid = reader.GetInt32NullAsZero("userid"); // sql = "UPDATE dbo.Users SET Status = 2 WHERE UserID = " + dnauserid.ToString(); // reader.ExecuteDEBUGONLY(sql); // } //} string title = "FunctionalTest Title"; string parentUri = "http://www.bbc.co.uk/dna/h2g2/"; string ratingForumXml = String.Format("<ratingForum xmlns=\"BBC.Dna.Api\">" + "<id>{0}</id>" + "<namespace>{3}</namespace>" + "<title>{1}</title>" + "<parentUri>{2}</parentUri>" + "<closeDate>{4}</closeDate>" + "<moderationServiceGroup>{5}</moderationServiceGroup>" + "</ratingForum>", id, title, parentUri, nameSpace, closingDate.ToString("yyyy-MM-dd"), moderationStatus); // Setup the request url string url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/", identitySitename); // now get the response request.RequestPageWithFullURL(url, ratingForumXml, "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(); 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)); Assert.IsTrue(returnedForum.Id == id); Assert.IsTrue(returnedForum.ParentUri == parentUri); Assert.IsTrue(returnedForum.Title == title); Assert.IsTrue(returnedForum.ModerationServiceGroup == moderationStatus); Console.WriteLine("After RatingForumIdentityUserCreate"); return returnedForum; }
[Ignore]//ignored because method is no longer supported public void GetReviewForumXML_WithUserList() { BBC.Dna.Api.RatingForum returnedForum = RatingForumIdentityUserCreate("tests", Guid.NewGuid().ToString() ,ModerationStatus.ForumStatus.Reactive, DateTime.MinValue); string url = String.Empty; string identitySiteName = "identity606"; DnaTestURLRequest request = new DnaTestURLRequest(identitySiteName); PostToRatingForumAsIdentityUser(returnedForum, request, identitySiteName); string newIdentityUserID1 = request.CurrentIdentityUserID; PostToRatingForumAsIdentityUser(returnedForum, request, identitySiteName); string newIdentityUserID2 = request.CurrentIdentityUserID; PostToRatingForumAsIdentityUser(returnedForum, request, identitySiteName); string newIdentityUserID3 = request.CurrentIdentityUserID; ////////////////////////////// //Call ReviewForums with filter by UserList ////////////////////////////// url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{1}/", identitySiteName, returnedForum.Id); string filterBy = FilterBy.UserList.ToString(); string userList = newIdentityUserID1 + "," + newIdentityUserID2; string filterUrl = url + "?filterBy={0}&userList={1}"; request.RequestPageWithFullURL(String.Format(filterUrl, filterBy, userList), "", "text/xml"); BBC.Dna.Api.RatingForum returnedList = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); Assert.IsTrue(returnedList.ratingsList.FilterBy.ToString() == filterBy); Assert.IsTrue(returnedList.ratingsList.TotalCount == 2); Assert.IsTrue(returnedList.ratingsSummary.Total == 2); Assert.IsTrue(returnedList.ratingsSummary.Average == (returnedList.ratingsList.ratings[0].rating + returnedList.ratingsList.ratings[1].rating)/2); //test when no user list passed userList = string.Empty; try { request.RequestPageWithFullURL(String.Format(filterUrl, filterBy, userList), "", "text/xml"); } catch {// Check to make sure that the page returned with the correct information Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.BadRequest); } //test when a bad user list passed userList = TestUserAccounts.GetNormalUserAccount.UserID + "," + TestUserAccounts.GetEditorUserAccount.UserID + ",a"; try { request.RequestPageWithFullURL(String.Format(filterUrl, filterBy, userList), "", "text/xml"); } catch {// Check to make sure that the page returned with the correct information Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.BadRequest); } }
public void GetReviewForumXML_WithSorting_ByCreated() { BBC.Dna.Api.RatingForum returnedForum = CreateRatingForum(); DnaTestURLRequest request = new DnaTestURLRequest(_sitename); string url = String.Empty; request.SetCurrentUserEditor(); //create 10 comments for (int i = 0; i < 3; i++) { string text = "Functiontest Title" + Guid.NewGuid().ToString(); string commentXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" + "<text>{0}</text>" + "<rating>{1}</rating>" + "</comment>", text, 5); // Setup the request url url = String.Format("https://" + _secureserver + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{1}/", _sitename, returnedForum.Id); //change the user for a review... switch(i) { case 1: request.SetCurrentUserModerator(); break; case 2: request.SetCurrentUserNormal(); break; } // now get the response request.RequestPageWithFullURL(url, commentXml, "text/xml"); } ////////////////////////////// //set up sorting tests ////////////////////////////// url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{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"); BBC.Dna.Api.RatingForum returnedList = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); Assert.IsTrue(returnedList.ratingsList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.ratingsList.SortBy.ToString() == sortBy); DateTime prevCreate = DateTime.MinValue; DateTime currentDate = DateTime.MinValue; for (int i = 0; i < returnedList.ratingsList.ratings.Count; i++) { currentDate = DateTime.Parse(returnedList.ratingsList.ratings[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 = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); Assert.IsTrue(returnedList.ratingsList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.ratingsList.SortBy.ToString() == sortBy); prevCreate = DateTime.MaxValue; for (int i = 0; i < returnedList.ratingsList.ratings.Count; i++) { currentDate = DateTime.Parse(returnedList.ratingsList.ratings[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 = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); Assert.IsTrue(returnedList.ratingsList.SortDirection.ToString() != sortDirection);// should fail and return the default Assert.IsTrue(returnedList.ratingsList.SortDirection.ToString() == SortDirection.Ascending.ToString());// should fail and return the default Assert.IsTrue(returnedList.ratingsList.SortBy.ToString() == sortBy); prevCreate = DateTime.MinValue; for (int i = 0; i < returnedList.ratingsList.ratings.Count; i++) { currentDate = DateTime.Parse(returnedList.ratingsList.ratings[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 = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); Assert.IsTrue(returnedList.ratingsList.SortDirection.ToString() == sortDirection); Assert.IsTrue(returnedList.ratingsList.SortBy.ToString() != sortBy);// should fail and return the default which is Created Assert.IsTrue(returnedList.ratingsList.SortBy.ToString() == SortBy.Created.ToString());// should fail and return the default which is Created prevCreate = DateTime.MaxValue; for (int i = 0; i < returnedList.ratingsList.ratings.Count; i++) { currentDate = DateTime.Parse(returnedList.ratingsList.ratings[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 = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum)); Assert.IsTrue(returnedList.ratingsList.SortDirection.ToString() != sortDirection); Assert.IsTrue(returnedList.ratingsList.SortDirection.ToString() == SortDirection.Ascending.ToString()); Assert.IsTrue(returnedList.ratingsList.SortBy.ToString() != sortBy);// should fail and return the default which is Created Assert.IsTrue(returnedList.ratingsList.SortBy.ToString() == SortBy.Created.ToString());// should fail and return the default which is Created prevCreate = DateTime.MinValue; for (int i = 0; i < returnedList.ratingsList.ratings.Count; i++) { currentDate = DateTime.Parse(returnedList.ratingsList.ratings[i].Created.At); Assert.IsTrue(currentDate >= prevCreate); prevCreate = currentDate; } }
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"); }
public void GetCommentForum_NotFoundJSON() { 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}/", _sitename, Guid.NewGuid()); try { request.RequestPageWithFullURL(url, "", "text/javascript"); } catch { // Check to make sure that the page returned with the correct information Assert.IsTrue(request.CurrentWebResponse.StatusCode == HttpStatusCode.NotFound); } var error = (ErrorData) StringUtils.DeserializeJSONObject(request.GetLastResponseAsString(), typeof (ErrorData)); }
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)); }
public void CreateCommentForum_WithClosedDate() { Console.WriteLine("Before CreateCommentForum"); 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/"; DateTime closeDate = DateTime.Now.AddDays(1); string commentForumXml = String.Format("<commentForum xmlns=\"BBC.Dna.Api\">" + "<id>{0}</id>" + "<title>{1}</title>" + "<parentUri>{2}</parentUri>" + "<closeDate>{3}</closeDate>" + "</commentForum>", id, title, parentUri, closeDate.ToString("yyyy-MM-dd")); // 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)); DateTime anticipatedClosedDate = DateTime.Parse(closeDate.AddDays(1).ToString("yyyy-MM-dd")); Assert.IsTrue(returnedForum.CloseDate == anticipatedClosedDate); Console.WriteLine("After GetCommentForumXML"); }
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"); }
public void GetCommentListBySitenameAndPrefixXML() { Console.WriteLine("Before GetCommentForumsBySitenameXML"); //create 3 forums with a prefix and one without var request = new DnaTestURLRequest(_sitename); request.SetCurrentUserEditor(); string prefix = "prefixfunctionaltest-"; //have to randomize the string to post string title = "Functiontest Title"; string parentUri = "http://www.bbc.co.uk/dna/h2g2/"; string id = string.Empty; string url = string.Empty; string commentForumXml = string.Empty; XmlDocument xml = null; DnaXmlValidator validator = null; CommentForum returnedForum = null; for (int i = 0; i < 3; i++) { id = prefix + Guid.NewGuid(); 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 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 xml = request.GetLastResponseAsXML(); validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForum); validator.Validate(); returnedForum = (CommentForum) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentForum)); Assert.IsTrue(returnedForum.Id == id); //post comments to list for (int j = 0; j < 3; j++) { 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"); // Check to make sure that the page returned with the correct information xml = request.GetLastResponseAsXML(); validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForum); validator.Validate(); var returnedComment = (CommentInfo) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (CommentInfo)); Assert.IsTrue(returnedComment.text == text); Assert.IsNotNull(returnedComment.User); Assert.IsTrue(returnedComment.User.UserId == request.CurrentUserID); } } //create a non-prefixed one id = Guid.NewGuid().ToString(); 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 url = String.Format( "http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/?prefix={1}", _sitename, prefix); // now get the response request.RequestPageWithFullURL(url, "", "text/xml"); // Check to make sure that the page returned with the correct information xml = request.GetLastResponseAsXML(); validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentsList); validator.Validate(); var returnedList = (BBC.Dna.Api.CommentsList) StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof (BBC.Dna.Api.CommentsList)); Assert.IsTrue(returnedList != null); //Assert.IsTrue(returnedList.TotalCount == 9); // 3 forums with 3 comments per forum = 9 Console.WriteLine("After GetCommentForumsBySitenameXML"); }