public void Setup() { SnapshotInitialisation.RestoreFromSnapshot(); using (FullInputContext _context = new FullInputContext("")) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("update threadentries set hidden=null where entryid=" + _postId.ToString()); } } }
/// <summary> /// Remove all the groups from the user given in the parameter /// </summary> /// <param name="testUserReq">the user to be affected</param> private void clearFromDB(DnaTestURLRequest testUserReq) { using (FullInputContext inputcontext = new FullInputContext(true)) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { ISiteList _siteList = SiteList.GetSiteList(); ISite site = _siteList.GetSite(testUtils_CommentsAPI.sitename); string sqlStr = "delete from GroupMembers where UserId=" + testUserReq.CurrentUserID; reader.ExecuteDEBUGONLY(sqlStr); sqlStr = "select * from GroupMembers where UserId=" + testUserReq.CurrentUserID; reader.ExecuteDEBUGONLY(sqlStr); Assert.IsFalse(reader.HasRows, "Error clearing the databse. The user whoulc have no rows in the groupMembers table"); } } }
public void StartUp() { SnapshotInitialisation.RestoreFromSnapshot(); Statistics.InitialiseIfEmpty(null,false); Statistics.ResetCounters(); using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) {//force processpremod out... reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=1 and Name='ProcessPreMod'"); } _siteList = SiteList.GetSiteList(); site = _siteList.GetSite("h2g2"); _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); var bannedEmails = new BannedEmails(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);//no sending signals from here var userGroups = new UserGroups(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);//no sending signals from here var profanityFilter = new ProfanityFilter(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);//no sending signals from here } }
/// <summary> /// going directly not the database, set the flag /// </summary> /// <param name="up">boolean to say which way to set the flag</param> /// <param name="modClassOfSite">needed so that we change the right thing</param> private void makeClassLifo(Boolean flag, int modClassOfSite) { using (FullInputContext inputcontext = new FullInputContext("")) { string sqlStr; using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { ISiteList _siteList = SiteList.GetSiteList(); ISite site = _siteList.GetSite(testUtils_CommentsAPI.sitename); sqlStr = "UPDATE ModerationClass SET ItemRetrievalType=" + (flag ? 1 : 0); sqlStr += " WHERE ModClassID=" + modClassOfSite; reader.ExecuteDEBUGONLY(sqlStr); Assert.AreEqual(reader.RecordsAffected, 1, "SQL change should have afected 1 line. Actually did " + reader.RecordsAffected); SendSignal(); } } }
/// <summary> /// /// </summary> /// <param name="value"></param> private void AddNotAllowURLsonH2G2SiteOption() { //set max char option using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { var sql = String.Format("select * from siteoptions where siteid={0} and name='IsURLFiltered' and Value=1", 1); reader.ExecuteDEBUGONLY(sql); if (reader.HasRows) { return; } else { sql = String.Format("select * from siteoptions where siteid={0} and name='IsURLFiltered' and Value=0", 1); reader.ExecuteDEBUGONLY(sql); if (reader.HasRows) { sql = String.Format("update siteoptions set Value=1 where siteid={0} and name='IsURLFiltered'", 1); reader.ExecuteDEBUGONLY(sql); } else { sql = String.Format("insert into siteoptions values ('General', 1, 'IsURLFiltered', 1, 1, 'Turns on and off allow URL in articles functionality')"); reader.ExecuteDEBUGONLY(sql); } } } } DnaTestURLRequest myRequest = new DnaTestURLRequest(_sitename); myRequest.RequestPageWithFullURL("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/h2g2/?action=recache-site&siteid=1", "", "text/xml"); }
private void AlterSubEditorForArticle(int userId, int h2g2Id) { int entryId = h2g2Id / 10; //set max char option using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { var sql = String.Format("update acceptedrecommendations set SubEditorID={0} where entryID={1}",userId, entryId ); reader.ExecuteDEBUGONLY(sql); } } }
public void CommentForum_ComplaintHideComment() { CommentForum commentForum = new CommentForum { Id = Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; CommentForum result = CreateForum(commentForum); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == commentForum.Id); Assert.IsTrue(result.ParentUri == commentForum.ParentUri); Assert.IsTrue(result.Title == commentForum.Title); Assert.IsTrue(result.commentSummary.Total == 0); //add a comment CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() }; CreateComment(comment, result); //get forum again result = ReadForum(result.Id); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == commentForum.Id); Assert.IsTrue(result.ParentUri == commentForum.ParentUri); Assert.IsTrue(result.Title == commentForum.Title); Assert.IsTrue(result.commentSummary.Total == 1); // Now ste the closing date of the forum to something in the past. using (FullInputContext _context = new FullInputContext(true)) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("hidepost")) { dataReader.AddParameter("postid", result.commentList.comments[0].ID); dataReader.AddParameter("hiddenid", 6); dataReader.Execute(); } } result = ReadForum(result.Id); Assert.IsTrue(result != null); Assert.IsTrue(result.commentList.comments[0].text == "This post has been removed.", "Comment not hidden!"); Assert.IsTrue(result.commentList.comments[0].hidden == CommentStatus.Hidden.Removed_EditorComplaintTakedown); }
/// <summary> /// /// </summary> /// <param name="value"></param> public static void SetSiteOption(string server, string urlname, string section, string name, int type, string value) { //set max char option using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY(string.Format( @" declare @siteid int select @siteid=siteid from sites where urlname = '{0}'; delete siteoptions where siteid=@siteid and section='{1}' and name='{2}'; insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(@siteid,'{1}', '{2}','{3}',{4},'test option') ", urlname, section, name, value, type)); } } DnaTestURLRequest myRequest = new DnaTestURLRequest(urlname); myRequest.RequestPageWithFullURL("http://" + server + "/dna/api/comments/CommentsService.svc/V1/site/h2g2/?action=recache-site", "", "text/xml"); Thread.Sleep(2000); }
/* /// <summary> /// Get the ceiling value for a review forum. /// Crashes if it fails /// </summary> /// <param name="testForumId">forum to be affected</param> /// <param name="forumCeiling">new value to be used by this forum</param> public static string readTable(string tableName) { string row = ""; bool ftt = true; IInputContext context = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader reader = context.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("SELECT * from " + tableName); while (reader.Read()) { if (ftt) { for (int i = 0; i < reader.FieldCount; i++) { row += reader.GetName(i) + "\t"; } row += "\n"; ftt = false; } for (int i = 0; i < reader.FieldCount; i++) { row += reader.GetValue(i) + "\t"; } row += "\n"; } } return row; } */ /// <summary> /// After a review form has been created, this will change the ceiling for the forum. /// Crashes if it fails /// </summary> /// <param name="testForumId">forum to be affected</param> /// <param name="forumCeiling">new value to be used by this forum</param> internal static void setCeiling(string testForumId, string forumCeiling) { using (FullInputContext inputcontext = new FullInputContext("")) { string sqlStr; using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { ISiteList _siteList = SiteList.GetSiteList(); ISite site = _siteList.GetSite(sitename); sqlStr = "delete from siteoptions where siteid=" + site.SiteID.ToString() + " and Name='MaxForumRatingScore' "; sqlStr += "insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values("; sqlStr += site.SiteID.ToString() + ",'CommentForum', 'MaxForumRatingScore'," + forumCeiling + ",0,'test MaxForumRatingScore value')"; reader.ExecuteDEBUGONLY(sqlStr); // having changedd the value in the database, the cache must be updated too // a call to any valid URL with the _ns=1 param should cause a refresh of the site cache DnaTestURLRequest myRequest = new DnaTestURLRequest(sitename); myRequest.RequestPageWithFullURL("http://" + server + "/dna/api/comments/CommentsService.svc/V1/site/h2g2/?action=recache-site", "", "text/xml"); } } }
private void SetMinCharLimit(int minLimit) { //set min and max char option using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() + ",'CommentForum', 'MinCommentCharacterLength','" + minLimit.ToString() + "',0,'test MinCommentCharacterLength value')"); _siteList.ReInitialise(); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } } }
private void DeleteMinMaxLimitSiteOptions() { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { try { reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='MaxCommentCharacterLength'"); } catch { } try { reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='MinCommentCharacterLength'"); } catch { } } _siteList.ReInitialise(); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } }
public void CommentForum_ComplaintHideComment() { CommentForum commentForum = new CommentForum { Id = Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; CommentForum result = _comments.CreateCommentForum(commentForum, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == commentForum.Id); Assert.IsTrue(result.ParentUri == commentForum.ParentUri); Assert.IsTrue(result.Title == commentForum.Title); Assert.IsTrue(result.commentSummary.Total == 0); //add a comment CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() }; //normal user _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _comments.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); _comments.CreateComment(result, comment); //get forum again result = _comments.GetCommentForumByUid(result.Id, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == commentForum.Id); Assert.IsTrue(result.ParentUri == commentForum.ParentUri); Assert.IsTrue(result.Title == commentForum.Title); Assert.IsTrue(result.commentSummary.Total == 1); // Now ste the closing date of the forum to something in the past. using (FullInputContext _context = new FullInputContext("")) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("hidepost")) { dataReader.AddParameter("postid", result.commentList.comments[0].ID); dataReader.AddParameter("hiddenid", 6); dataReader.Execute(); } } result = _comments.GetCommentForumByUid(result.Id, site); Assert.IsTrue(result != null); Assert.IsTrue(result.commentList.comments[0].hidden == CommentStatus.Hidden.Removed_EditorComplaintTakedown); }
public void SiteManager_UpdateSiteModClassInvalidLanguage_ReturnsCorrectError() { var modId = 0; var name = "chinesestandard"; try { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader dataReader = inputcontext.CreateDnaDataReader("createnewmoderationclass")) { dataReader.AddParameter("classname", name); dataReader.AddParameter("description", "chinesestandard"); dataReader.AddParameter("Language", "zh"); dataReader.AddParameter("basedonclass", 1); dataReader.Execute(); } SendSignal(); using (IDnaDataReader dataReader = inputcontext.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("select modclassid from moderationclass where name='" + name + "'"); Assert.IsTrue(dataReader.Read()); modId = dataReader.GetInt32("modclassid"); } } var request = new DnaTestURLRequest(_siteName); request.SetCurrentUserSuperUser(); request.UseEditorAuthentication = true; request.RequestPage("sitemanager?skin=purexml"); var xmlDoc = request.GetLastResponseAsXML(); var listData = GeneratePostData(xmlDoc, _siteId); var originalModClassId = listData.FirstOrDefault(x => x.Key == "modclassid").Value; var pair = listData.Remove(listData.FirstOrDefault(x => x.Key == "modclassid")); listData.Add(new KeyValuePair<string,string>("modclassid", modId.ToString())); request.RequestPage("sitemanager?skin=purexml&update=1", ConvertToQueue(listData)); xmlDoc = request.GetLastResponseAsXML(); ValidateError(xmlDoc, "UPDATE ERROR"); Assert.AreEqual(originalModClassId, xmlDoc.SelectSingleNode("/H2G2/SITEMANAGER/MODERATIONCLASSID").InnerText); } finally { using (FullInputContext inputcontext = new FullInputContext("")) { if (modId != 0) { using (IDnaDataReader dataReader = inputcontext.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("delete from TermsByModClass where modclassid=" + modId.ToString()); dataReader.ExecuteDEBUGONLY("delete from moderationclass where modclassid=" + modId.ToString()); } } } } }
public void SiteManager_UpdateSiteModClassValidLanguage_ReturnsCorrectUpdate() { var modId = 0; var originalModClassId = 0; var request = new DnaTestURLRequest(_siteName); request.SetCurrentUserSuperUser(); request.UseEditorAuthentication = true; request.RequestPage("sitemanager?skin=purexml"); var xmlDoc = request.GetLastResponseAsXML(); ValidateSiteManagerPage(xmlDoc); var listData = GeneratePostData(xmlDoc, _siteId); originalModClassId = Int32.Parse(listData.FirstOrDefault(x => x.Key == "modclassid").Value); try { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader dataReader = inputcontext.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("select modclassid from moderationclass where classlanguage='en' and modclassid <> " + originalModClassId.ToString()); Assert.IsTrue(dataReader.Read()); modId = dataReader.GetInt32("modclassid"); } } var pair = listData.Remove(listData.FirstOrDefault(x => x.Key == "modclassid")); listData.Add(new KeyValuePair<string, string>("modclassid", modId.ToString())); request.RequestPage("sitemanager?skin=purexml&update=1", ConvertToQueue(listData)); xmlDoc = request.GetLastResponseAsXML(); ValidateSiteManagerPage(xmlDoc); Assert.AreEqual(modId.ToString(), xmlDoc.SelectSingleNode("/H2G2/SITEMANAGER/MODERATIONCLASSID").InnerText); listData = GeneratePostData(xmlDoc, _siteId); pair = listData.Remove(listData.FirstOrDefault(x => x.Key == "modclassid")); listData.Add(new KeyValuePair<string, string>("modclassid", originalModClassId.ToString())); request.RequestPage("sitemanager?skin=purexml&update=1", ConvertToQueue(listData)); xmlDoc = request.GetLastResponseAsXML(); ValidateSiteManagerPage(xmlDoc); Assert.AreEqual(originalModClassId.ToString(), xmlDoc.SelectSingleNode("/H2G2/SITEMANAGER/MODERATIONCLASSID").InnerText); } finally { } }
public void CreateComment_IPbutNoBBCUID() { Console.WriteLine("Before CreateComment"); DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); //create the forum CommentForum commentForum = 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); string ipAddr = "123.234.111.222"; // Setup the request url string url = String.Format("https://" + _secureserver + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/?format=JSON&clientIp={2}", _sitename, commentForum.Id, ipAddr); // now get the response request.RequestPageWithFullURL(url, commentForumXml, "text/xml"); Assert.AreEqual("application/json", request.CurrentWebResponse.ContentType); using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader dataReader = inputcontext.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY(@" select top 1 * from threadentries te left join threadentriesipaddress teip on teip.entryid=te.entryid order by te.entryid desc"); Assert.IsTrue(dataReader.Read()); Assert.AreEqual(ipAddr, dataReader.GetString("IPAddress")); Assert.AreEqual(Guid.Empty, dataReader.GetGuid("BBCUID"),"We expect the empty GUID if an IP address is present but the BBCUID cookie is missing"); } } }
private void RemoveCharLimitForSite() { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='MaxCommentCharacterLength'"); _siteList = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null); _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } } }
private void SetCharLimitTo15ForSite() { //set max char option using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() + ",'CommentForum', 'MaxCommentCharacterLength','15',0,'test MaxCommentCharacterLength value')"); _siteList = SiteList.GetSiteList(); _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } } }
public void RatingCreate_RatingWithBiggerSiteOption() { try { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() + ",'CommentForum', 'MaxForumRatingScore','15',0,'test MaxForumRatingScore value')"); } _siteList.ReInitialise(); site = _siteList.GetSite("h2g2"); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 14//standard site option = 5 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); //getr the forum and check value RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text == rating.text); Assert.IsTrue(result.rating == rating.rating); } finally { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='MaxForumRatingScore'"); _siteList = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } } } }
public void TearDown() { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("delete from GroupMembers where UserId=" + TestUserAccounts.GetNormalUserAccount.UserID); reader.ExecuteDEBUGONLY("delete from ModerationClassMembers where UserId=" + TestUserAccounts.GetNormalUserAccount.UserID); } SendSignal(); } }
public void RatingCreate_PreModForum() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID, ModerationStatus.ForumStatus.PreMod); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0);//should be valid post ID Assert.AreEqual("This post is awaiting moderation.", result.text); //check if post in mod queue table using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("select * from ThreadMod where postid=" + result.ID.ToString()); if (!reader.Read() || !reader.HasRows) { Assert.Fail("Post not in ThreadMod table and moderation queue"); } } } }
public void CommentForum_ChangeCanWriteFlag() { CommentForum commentForum = new CommentForum { Id = Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; CommentForum result = CreateForum(commentForum); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == commentForum.Id); Assert.IsTrue(result.ParentUri == commentForum.ParentUri); Assert.IsTrue(result.Title == commentForum.Title); Assert.IsTrue(result.commentSummary.Total == 0); //add a comment CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() }; CreateComment(comment, result); //get forum again result = ReadForum(result.Id); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == commentForum.Id); Assert.IsTrue(result.ParentUri == commentForum.ParentUri); Assert.IsTrue(result.Title == commentForum.Title); Assert.IsTrue(result.commentSummary.Total == 1); Assert.IsFalse(result.isClosed); // Now ste the closing date of the forum to something in the past. using (FullInputContext _context = new FullInputContext(true)) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("updatecommentforumstatus")) { dataReader.AddParameter("uid", result.Id); dataReader.AddParameter("canwrite", 0); dataReader.Execute(); } } result = ReadForum(result.Id); Assert.IsTrue(result != null); Assert.IsTrue(result.isClosed); //try and read it again as json - to check the isclosed forum flag is honoured. result = ReadForumJson(result.Id); Assert.IsTrue(result != null); Assert.IsTrue(result.isClosed); }
public void RatingCreate_PreModSiteWithProcessPreMod() { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("update sites set premoderation=1 where siteid=" + site.SiteID.ToString());//set premod reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() + ",'Moderation', 'ProcessPreMod','1',1,'test premod value')"); } _siteList = SiteList.GetSiteList(); site = _siteList.GetSite("h2g2"); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), inputcontext.SiteList); } try { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID, ModerationStatus.ForumStatus.Unknown);//should override this with the site value //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); try { _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.InvalidProcessPreModState); } } finally { //reset h2g2 site using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("update sites set premoderation=0 where siteid=" + site.SiteID.ToString());//set premod reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='ProcessPreMod'"); } _siteList = SiteList.GetSiteList(); site = _siteList.GetSite("h2g2"); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), inputcontext.SiteList); } } }
/// <summary> /// /// </summary> /// <param name="postid"></param> /// <param name="forumid"></param> /// <param name="status"></param> /// <param name="edittedText"></param> private void ModerateComment(int postid, int forumid, BBC.Dna.Component.ModeratePosts.Status status, string edittedText) { using (FullInputContext _context = new FullInputContext(true)) { int threadId = 0, modId = 0, threadModStatus = 0; using (IDnaDataReader dataReader = _context.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("select modid, threadid, forumid, status from threadmod where postid=" + postid.ToString()); if (dataReader.Read()) { threadId = dataReader.GetInt32NullAsZero("threadid"); modId = dataReader.GetInt32NullAsZero("modid"); threadModStatus = dataReader.GetInt32NullAsZero("status"); forumid = dataReader.GetInt32NullAsZero("forumid"); } } using (IDnaDataReader dataReader = _context.CreateDnaDataReader("moderatepost")) { dataReader.AddParameter("forumid", forumid); dataReader.AddParameter("threadid", threadId); dataReader.AddParameter("postid", postid); dataReader.AddParameter("modid", modId); dataReader.AddParameter("status", (int)status); dataReader.AddParameter("notes", ""); dataReader.AddParameter("referto", 0); dataReader.AddParameter("referredby", 0); dataReader.AddParameter("moderationstatus", threadModStatus); dataReader.Execute(); } if(status == BBC.Dna.Component.ModeratePosts.Status.PassedWithEdit) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("updatepostdetails")) { dataReader.AddParameter("userid", TestUserAccounts.GetNormalUserAccount.UserID); dataReader.AddParameter("postid", postid); dataReader.AddParameter("subject", ""); dataReader.AddParameter("text", edittedText); dataReader.AddParameter("setlastupdated", true); dataReader.AddParameter("forcemoderateandhide", 0); dataReader.AddParameter("ignoremoderation", 1); dataReader.Execute(); } } } }
public void RatingCreate_PostPastClosingDate() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum_good" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //change the closing date for this forum using (FullInputContext _context = new FullInputContext("")) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("updatecommentforumstatus")) { dataReader.AddParameter("uid", ratingForumID); dataReader.AddParameter("forumclosedate", DateTime.Today.AddDays(-20)); dataReader.Execute(); } } ratingForum = _ratings.RatingForumReadByUID(ratingForumID, site); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); try { RatingInfo result = _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.ForumClosed); } }
/// <summary> /// /// </summary> /// <param name="value"></param> private void RemoveNotAllowURLsonH2G2SiteOption() { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("delete from siteoptions where name='IsURLFiltered' and siteid=1"); } } DnaTestURLRequest myRequest = new DnaTestURLRequest(_sitename); myRequest.RequestPageWithFullURL("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/h2g2/?action=recache-site&siteid=1", "", "text/xml"); }
private void SetMinCharLimit(int minLimit) { //set min char option using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(1,'CommentForum', 'MinCommentCharacterLength','" + minLimit.ToString() + "',0,'test MinCommentCharacterLength value')"); } } DnaTestURLRequest myRequest = new DnaTestURLRequest(_sitename); myRequest.RequestPageWithFullURL("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/h2g2/?action=recache-site", "", "text/xml"); }
/// <summary> /// /// </summary> /// <param name="value"></param> private void AddFastFreeTextArticleSearchH2G2SiteOption() { //set max char option using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { var sql = String.Format("select * from siteoptions where siteid={0} and name='FastFreetextSearch' and Value=1", 1); reader.ExecuteDEBUGONLY(sql); if (reader.HasRows) { return; } else { sql = String.Format("select * from siteoptions where siteid={0} and name='FastFreetextSearch' and Value=0", 1); reader.ExecuteDEBUGONLY(sql); if (reader.HasRows) { sql = String.Format("update siteoptions set Value=1 where siteid={0} and name='FastFreetextSearch'", 1); reader.ExecuteDEBUGONLY(sql); } else { sql = String.Format("insert into siteoptions values ('ArticleSearch', 1, 'FastFreetextSearch', 1, 1, 'Use the Fast freetext search. Only articles that have ALL the search terms are returned. It uses the freetext search engine weightings to order the results by relevance.')"); reader.ExecuteDEBUGONLY(sql); } } } } DnaTestURLRequest myRequest = new DnaTestURLRequest(_sitename); myRequest.RequestPageWithFullURL("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/h2g2/?action=recache-site&siteid=1", "", "text/xml"); }
public void CommentCreate_PreModSiteWithProcessPreMod() { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("update sites set premoderation=1 where siteid=" + site.SiteID.ToString());//set premod reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() +",'Moderation', 'ProcessPreMod','1',1,'test premod value')"); } _siteList = SiteList.GetSiteList(); site = _siteList.GetSite("h2g2"); _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), inputcontext.SiteList); } try { //set up test data CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." }; comment.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string commentForumID = "testCommentForum" + Guid.NewGuid().ToString(); CommentForum commentForum = CommentForumCreate(commentForumID, ModerationStatus.ForumStatus.Unknown);//should override this with the site value //normal user _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _comments.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUtils.TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); CommentInfo result = _comments.CreateComment(commentForum, comment); Assert.IsTrue(result != null); Assert.IsTrue(result.ID == 0);//should be have no post ID Assert.IsTrue(result.text == "This post is awaiting moderation."); //check if post in PreModPostings queue table using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("select top 1 * from PreModPostings where dateposted > DATEADD(mi, -1, getdate())");//must be within 2 mins of post date if (!reader.Read() || !reader.HasRows) { Assert.Fail("Post not in ThreadMod PreModPostings and moderation queue"); } } } } finally { //reset h2g2 site using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("update sites set premoderation=0 where siteid=" + site.SiteID.ToString());//set premod reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='ProcessPreMod'"); } _siteList = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null); site = _siteList.GetSite("h2g2"); _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } } }
/// <summary> /// find out the mod class of the site that we are using /// </summary> /// <param name="siteName">short name of site to find out about</param> /// <returns>the mod class of that site</returns> private int getModClass(string siteName) { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { ISiteList _siteList = SiteList.GetSiteList(); ISite site = _siteList.GetSite(testUtils_CommentsAPI.sitename); string sqlStr = "select ModClassId FROM Sites WHERE shortname ='" + siteName + "'"; reader.ExecuteDEBUGONLY(sqlStr); Assert.IsTrue(reader.HasRows); reader.Read(); return reader.GetInt32("ModClassId"); } } }
public void CommentCreate_PostModForum() { //set up test data CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." }; comment.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string commentForumID = "testCommentForum" + Guid.NewGuid().ToString(); CommentForum commentForum = CommentForumCreate(commentForumID, ModerationStatus.ForumStatus.PostMod); //normal user _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _comments.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUtils.TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); CommentInfo result = _comments.CreateComment(commentForum, comment); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text == comment.text); //check if post in mod queue table using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("select * from ThreadMod where postid=" + result.ID.ToString()); if (!reader.Read() || !reader.HasRows) { Assert.Fail("Post not in ThreadMod table and moderation queue"); } } } }