public override void PopulateFacet(Facet facet) { TermsList.Clear(); TermsFacet termsFacet = facet as TermsFacet; if (termsFacet != null) { foreach (TermCount termCount in termsFacet.Terms) { TermsList.Add(new MultiSelectTermCount() { Count = termCount.Count, Term = termCount.Term, Selected = SelectedTerms.Contains(termCount.Term) }); } } }
/// <summary> /// Constructor for Terms By Forum /// </summary> /// <param name="forumId"></param> /// <param name="isForForum"></param> public TermsFilterAdmin(int forumId, bool isForForum) { TermsList = new TermsList(forumId, false, isForForum); }
public void FilterByTermId_WithValidTerms_ReturnsCorrectList() { TermsList target = new TermsList(); target.Terms.Add(new TermDetails(){Id=1}); target.Terms.Add(new TermDetails() { Id = 2 }); int termId = 1; target.FilterByTermId(termId); Assert.AreEqual(1, target.Terms.Count); }
public void TermsListSchemaValidation() { var expected = "<TERMSLIST xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" FORUMID=\"0\" MODCLASSID=\"0\"><TERMDETAILS ID=\"0\" ACTION=\"ReEdit\" TERM=\"term\" MODCLASSID=\"0\" ForumID=\"0\" USERID=\"0\" FromModClass=\"false\" /></TERMSLIST>"; var target = new TermsList{ModClassId = 0}; target.Terms.Add(TermTest.CreateTerm()); XmlDocument xml = Serializer.SerializeToXml(target); Assert.AreEqual(expected, xml.SelectSingleNode("TERMSLIST").OuterXml); }
public void IsUpToDate_AlwaysReturnsTrue() { var target = new TermsList(); Assert.IsFalse(target.IsUpToDate(null)); }
/// <summary> /// /// </summary> /// <returns></returns> public static TermsList GetTermDetailsList() { var expected = new TermsList(1, true); expected.Terms.Add(TermDetailsTest.CreateTermDetails()); return expected; }
/// <summary> /// /// </summary> /// <returns></returns> public static TermsList GetTermsList() { var expected = new TermsList(1); expected.Terms.Add(TermTest.CreateTerm()); return expected; }
/// <summary> /// Checks the parameters and updates the term passed in /// </summary> /// <returns></returns> private BaseResult UpdateTerm() { var modClassId = InputContext.GetParamIntOrZero("modclassid", "Moderation Class ID"); if (modClassId == 0) { return new Error { Type = "UPDATETERM", ErrorMessage = "Moderation Class ID cannot be 0." }; } var termText = InputContext.GetParamStringOrEmpty("termtext", "the text of the term"); if (termText == String.Empty) { return new Error { Type = "UPDATETERM", ErrorMessage = "Terms text cannot be empty." }; } TermAction termAction; try { termAction = (TermAction)Enum.Parse(typeof(TermAction), InputContext.GetParamStringOrEmpty("termaction", "the action of the term"), true); } catch (Exception) { return new Error { Type = "UPDATETERM", ErrorMessage = "Terms action invalid." }; } var termList = new TermsList { ModClassId = modClassId }; termList.Terms.Add(new TermDetails { Value = termText, Action = termAction }); Error error = termList.UpdateTermsInDatabase(AppContext.ReaderCreator, _cache, "Update through moderation tools", InputContext.ViewingUser.UserID, true); if (error == null) { return new Result("TermsUpdateSuccess", "Terms updated successfully."); } return error; }
public void TermsFilterImportPage_AddSingleTermWithoutReason_ReturnsCorrectError() { //set up data var reason = "";//empty for test var termsLists = new TermsLists(); var termsList = new TermsList(1); termsList.Terms.Add(new TermDetails { Action = TermAction.ReEdit, Value = "bollocks" }); termsLists.Termslist.Add(termsList); termsList = new TermsList(2); termsList.Terms.Add(new TermDetails { Action = TermAction.Refer, Value = "bollocks" }); termsLists.Termslist.Add(termsList); string postText = termsLists.Termslist.Aggregate("", (current1, tmpTermsList) => tmpTermsList.Terms.Aggregate(current1, (current, term) => current + (term.Value + "\n"))); var postParams = new Queue<KeyValuePair<string, string>>(); postParams.Enqueue(new KeyValuePair<string, string>("reason", reason)); postParams.Enqueue(new KeyValuePair<string, string>("termtext", postText)); foreach (var tempTermsList in termsLists.Termslist) { postParams.Enqueue(new KeyValuePair<string, string>("action_modclassid_" + tempTermsList.ModClassId, (tempTermsList.Terms[0].Action).ToString())); } var request = new DnaTestURLRequest(SiteName) { UseEditorAuthentication = true }; request.SetCurrentUserSuperUser(); request.RequestPage("termsfilterimport?action=UPDATETERMS&skin=purexml", postParams); ValidateError(request, "UPDATETERMMISSINGDESCRIPTION", "The import description cannot be empty."); }
public void TermsFilterImportPage_AddSingleReferTermToAll_PassesValidation() { //refresh mod classes SendSignal(); //set up data var reason = "this has a reason"; var term = "potato"; var action = TermAction.Refer; var moderationClasses = new ModerationClassListCache(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null); var moderationClassList = moderationClasses.GetObjectFromCache(); var termsLists = new TermsLists(); foreach (var modClass in moderationClassList.ModClassList) { var termsList = new TermsList { ModClassId = modClass.ClassId }; termsList.Terms.Add(new TermDetails { Value = term, Action = action }); termsLists.Termslist.Add(termsList); } Assert.AreNotEqual(0, termsLists.Termslist.Count); var postParams = new Queue<KeyValuePair<string, string>>(); postParams.Enqueue(new KeyValuePair<string, string>("reason", reason)); postParams.Enqueue(new KeyValuePair<string, string>("termtext", term)); postParams.Enqueue(new KeyValuePair<string, string>("action_modclassid_all", action.ToString())); var request = new DnaTestURLRequest(SiteName) { UseEditorAuthentication = true }; request.SetCurrentUserSuperUser(); request.RequestPage("termsfilterimport?action=UPDATETERMS&skin=purexml", postParams); ValidateResponse(request); //check correct error message returned ValidateOkResult(request, "TermsUpdateSuccess", "Term updated successfully."); //check history table termsLists = ValidateHistory(request, reason, termsLists); //Check that all terms are actually associated ValidateTermAssociations(request, termsLists); }
public void PostToForum_BlockedForumTermsInPost_CorrectModeratedPost() { var forumTerm = "bum1234"; var processPreMod = false; var siteStatus = ModerationStatus.SiteStatus.UnMod; var forumStatus = ModerationStatus.ForumStatus.Reactive; var threadStatus = ModerationStatus.ForumStatus.Reactive; var userStatus = ModerationStatus.UserStatus.Standard; //var expectedPostStatus = ModerationStatus.ForumStatus.PostMod; SetPermissions(siteStatus, forumStatus, threadStatus, userStatus, processPreMod); DnaTestURLRequest request = new DnaTestURLRequest(_siteName); //request.SetCurrentUserNormal(); //Add the terms to the terms update history ICacheManager _cache = CacheFactory.GetCacheManager(); IDnaDataReaderCreator creator = DnaMockery.CreateDatabaseReaderCreator(); var termsLists = new TermsLists(); var termList = new TermsList(_forumId, false, true); termList.Terms.Add(new TermDetails { Value = forumTerm, Action = TermAction.ReEdit }); termsLists.Termslist.Add(termList); Error error = termsLists.UpdateTermsInDatabase(creator, _cache, "Testing bum1234", 6, false); SendTermsSignal(); request = PostToForumWithException(request, "Testing terms with refferred item " + forumTerm + " post", DnaTestURLRequest.usertype.NORMALUSER); var xml = request.GetLastResponseAsXML(); IInputContext context = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader dataReader = context.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("select * from ForumModTermMapping where ThreadModID = (select max(modid) from threadmod where notes like '%" + forumTerm + "%')"); Assert.IsFalse(dataReader.Read()); } }
public void PostToForum_ReferredForumReferredModClassTermsInPost_CorrectModeratedPost() { var forumTerm = "potato"; var processPreMod = false; var siteStatus = ModerationStatus.SiteStatus.UnMod; var forumStatus = ModerationStatus.ForumStatus.Reactive; var threadStatus = ModerationStatus.ForumStatus.Reactive; var userStatus = ModerationStatus.UserStatus.Standard; var expectedPostStatus = ModerationStatus.ForumStatus.PostMod; SetPermissions(siteStatus, forumStatus, threadStatus, userStatus, processPreMod); DnaTestURLRequest request = new DnaTestURLRequest(_siteName); //request.SetCurrentUserNormal(); new TermsFilterImportPageTests().TermsFilterImportPage_AddSingleReferTermToAll_PassesValidation(); SendTermsSignal(); //Add the terms to the terms update history ICacheManager _cache = CacheFactory.GetCacheManager(); IDnaDataReaderCreator creator = DnaMockery.CreateDatabaseReaderCreator(); var termsLists = new TermsLists(); var termList = new TermsList(_forumId, false, true); termList.Terms.Add(new TermDetails { Value = forumTerm, Action = TermAction.Refer }); termsLists.Termslist.Add(termList); Error error = termsLists.UpdateTermsInDatabase(creator, _cache, "Testing potato", 6, false); SendTermsSignal(); request = PostToForumWithException(request, "Testing terms with refferred item " + forumTerm + " post", DnaTestURLRequest.usertype.NORMALUSER); var xml = request.GetLastResponseAsXML(); CheckPostInModQueue(xml, expectedPostStatus, processPreMod); CheckPostInThread(xml, expectedPostStatus, processPreMod); var termId = 0; var threadModId = 0; IInputContext context = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader dataReader = context.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("select ID from TermsLookUp where term = '" + forumTerm + "'"); Assert.IsTrue(dataReader.Read()); termId = dataReader.GetInt32("ID"); dataReader.ExecuteDEBUGONLY("select * from ForumModTermMapping where ThreadModID = (select max(modid) from threadmod)"); Assert.IsTrue(dataReader.Read()); Assert.AreEqual(termId, dataReader.GetInt32("TermID")); threadModId = dataReader.GetInt32("ThreadModID"); } var terms = TermsList.GetTermsListByThreadModIdFromThreadModDB(creator, threadModId, true); Assert.AreEqual(forumTerm, terms.Terms[0].Value); Assert.AreEqual("this has a reason", terms.Terms[0].Reason); }
public void PostToForum_ReferredForumTermsInPost_CorrectModeratedPost() { var forumTerm = "humbug123"; var processPreMod = false; var siteStatus = ModerationStatus.SiteStatus.UnMod; var forumStatus = ModerationStatus.ForumStatus.Reactive; var threadStatus = ModerationStatus.ForumStatus.Reactive; var userStatus = ModerationStatus.UserStatus.Standard; var expectedPostStatus = ModerationStatus.ForumStatus.PostMod; SetPermissions(siteStatus, forumStatus, threadStatus, userStatus, processPreMod); DnaTestURLRequest request = new DnaTestURLRequest(_siteName); //request.SetCurrentUserNormal(); //Add the terms to the terms update history ICacheManager _cache = CacheFactory.GetCacheManager(); IDnaDataReaderCreator creator = DnaMockery.CreateDatabaseReaderCreator(); var termsLists = new TermsLists(); var termList = new TermsList(_forumId, false, true); termList.Terms.Add(new TermDetails { Value = forumTerm, Action = TermAction.Refer }); termsLists.Termslist.Add(termList); Error error = termsLists.UpdateTermsInDatabase(creator, _cache, "Testing humbug123", 6, false); SendTermsSignal(); request = PostToForumWithException(request, "Testing terms with refferred item " + forumTerm + " post", DnaTestURLRequest.usertype.NORMALUSER); var xml = request.GetLastResponseAsXML(); CheckPostInModQueue(xml, expectedPostStatus, processPreMod); CheckPostInThread(xml, expectedPostStatus, processPreMod); CheckModerationTerms(forumTerm, creator); }
/// <summary> /// Checks the parameters and updates the term passed in /// </summary> /// <returns></returns> private BaseResult UpdateTerms() { string reason = InputContext.GetParamStringOrEmpty("reason", "The reason for the change"); if (reason == string.Empty) { return new Error {Type = "UPDATETERMMISSINGDESCRIPTION", ErrorMessage = "The import description cannot be empty."}; } string termText = InputContext.GetParamStringOrEmpty("termtext", "the text of the term"); string[] terms = termText.Split('\n'); terms = terms.Where(x => x != String.Empty).Distinct().ToArray(); if (terms.Length == 0) { return new Error {Type = "UPDATETERMMISSINGTERM", ErrorMessage = "Terms text must contain newline delimited terms."}; } var moderationClassList = ModerationClassListCache.GetObject(); var termsLists = new TermsLists(); foreach (var modClass in moderationClassList.ModClassList) { //get all action or just the one for the specific mod class string actionParam = string.Format("action_modclassid_all"); if(!InputContext.DoesParamExist(actionParam, "Modclass action value")) { actionParam = string.Format("action_modclassid_{0}", modClass.ClassId); if (!InputContext.DoesParamExist(actionParam, "Modclass action value")) continue; } //parse term id TermAction termAction; if (Enum.IsDefined(typeof(TermAction), InputContext.GetParamStringOrEmpty(actionParam, "Modclass action value"))) { termAction = (TermAction) Enum.Parse(typeof(TermAction), InputContext.GetParamStringOrEmpty(actionParam, "Modclass action value")); } else { return new Error {Type = "UPDATETERMINVALIDACTION", ErrorMessage = "Terms action invalid."}; } var termsList = new TermsList(modClass.ClassId); foreach (var term in terms) { termsList.Terms.Add(new TermDetails { Value = term, Action = termAction }); } termsLists.Termslist.Add(termsList); } BaseResult error = termsLists.UpdateTermsInDatabase(AppContext.ReaderCreator, _cache, reason, InputContext.ViewingUser.UserID, true); if (error == null) { return new Result("TermsUpdateSuccess", String.Format("{0} updated successfully.", terms.Length==1?"Term":"Terms")); } return error; }
public void GetAllTermsListsTest() { var expected = new TermsList(); expected.Terms.Add(TermTest.CreateTerm()); string key = expected.GetCacheKey(0); var reader = Mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Read()).Return(true).Repeat.Twice(); var readerCreator = Mocks.DynamicMock<IDnaDataReaderCreator>(); readerCreator.Stub(x => x.CreateDnaDataReader("gettermsbymodclassid")).Return(reader); var cacheManager = Mocks.DynamicMock<ICacheManager>(); cacheManager.Stub(x => x.GetData(key)).Return(null); Mocks.ReplayAll(); int[] modClassIds = {1,2}; TermsLists actual = TermsLists.GetAllTermsLists(readerCreator, cacheManager, modClassIds, false); Assert.AreEqual(2, actual.Termslist.Count); }
public void FilterListByTermIdTest() { var term = new TermDetails(){Id=1}; var termsList = new TermsList(1); termsList.Terms.Add(term); var target = new TermsLists(); target.Termslist.Add(TermsListTest.GetTermsList()); target.Termslist.Add(termsList); target.FilterListByTermId(1); Assert.AreEqual(1, target.Termslist.Count); }
public void TermsFilterImportPage_AddSingleTermWithoutTerms_ReturnsCorrectError() { //set up data var reason = "Not Empty";//empty for test var termsLists = new TermsLists(); var termsList = new TermsList(1); termsList.Terms.Add(new TermDetails { Action = TermAction.ReEdit, Value = "bollocks" }); termsLists.Termslist.Add(termsList); termsList = new TermsList(2); termsList.Terms.Add(new TermDetails { Action = TermAction.Refer, Value = "bollocks" }); termsLists.Termslist.Add(termsList); string postText = "";//breaks test var postParams = new Queue<KeyValuePair<string, string>>(); postParams.Enqueue(new KeyValuePair<string, string>("reason", reason)); postParams.Enqueue(new KeyValuePair<string, string>("termtext", postText)); foreach (var tempTermsList in termsLists.Termslist) { postParams.Enqueue(new KeyValuePair<string, string>("action_modclassid_" + tempTermsList.ModClassId, (tempTermsList.Terms[0].Action).ToString())); } var request = new DnaTestURLRequest(SiteName) { UseEditorAuthentication = true }; request.SetCurrentUserSuperUser(); request.RequestPage("termsfilterimport?action=UPDATETERMS&skin=purexml", postParams); ValidateError(request, "UPDATETERMMISSINGTERM", "Terms text must contain newline delimited terms."); }
/// <summary> /// Checks the parameters and updates the term passed in /// </summary> /// <returns></returns> private BaseResult UpdateTerm() { var forumId = InputContext.GetParamIntOrZero("forumid", "Forum ID"); if (forumId == 0) { return new Error { Type = "UPDATETERM", ErrorMessage = "Forum ID cannot be 0." }; } var termText = InputContext.GetParamStringOrEmpty("termtext", "the text of the term"); string[] terms = termText.Split('\n'); terms = terms.Where(x => x != String.Empty).Distinct().ToArray(); if (terms.Length == 0) { return new Error { Type = "UPDATETERMMISSINGTERM", ErrorMessage = "Terms text must contain newline delimited terms." }; } var termReason = InputContext.GetParamStringOrEmpty("reason", "Reason for the term added.").Trim(); if (string.IsNullOrEmpty(termReason)) { return new Error { Type = "UPDATETERMMISSINGDESCRIPTION", ErrorMessage = "Term reason cannot be empty." }; } string actionParam = string.Format("action_forumid_all"); TermAction termAction; if (Enum.IsDefined(typeof(TermAction), InputContext.GetParamStringOrEmpty(actionParam, "Forum action value"))) { termAction = (TermAction)Enum.Parse(typeof(TermAction), InputContext.GetParamStringOrEmpty(actionParam, "Forum action value")); } else { return new Error { Type = "UPDATETERMINVALIDACTION", ErrorMessage = "Terms action invalid." }; } var termsLists = new TermsLists(); var termList = new TermsList(forumId, false, true); foreach (var term in terms) { termList.Terms.Add(new TermDetails { Value = term, Action = termAction }); } termsLists.Termslist.Add(termList); BaseResult error = termsLists.UpdateTermsInDatabase(InputContext.CreateDnaDataReaderCreator(), _cache, termReason.Trim(), InputContext.ViewingUser.UserID, false); if (error == null) { //Send email to the distribution list SendTermUpdateEmail(terms, forumId, termReason.Trim(), termAction, InputContext.ViewingUser.UserID); return new Result("TermsUpdateSuccess", String.Format("{0} updated successfully.", terms.Length == 1 ? "Term" : "Terms")); } return error; }
public void TermsFilterImportPage_AddMultipleTerms_PassesValidation() { var term1 = Guid.NewGuid().ToString(); var term2 = Guid.NewGuid().ToString(); //set up data var reason = "this has a reason"; var termsLists = new TermsLists(); var termsList = new TermsList(1); termsList.Terms.Add(new TermDetails { Action = TermAction.Refer, Value = term1 }); termsList.Terms.Add(new TermDetails { Action = TermAction.Refer, Value = term2 }); termsLists.Termslist.Add(termsList); termsList = new TermsList(2); termsList.Terms.Add(new TermDetails { Action = TermAction.ReEdit, Value = term1 }); termsList.Terms.Add(new TermDetails { Action = TermAction.ReEdit, Value = term2 }); termsLists.Termslist.Add(termsList); string postText = termsLists.Termslist.Aggregate("", (current1, tmpTermsList) => tmpTermsList.Terms.Aggregate(current1, (current, term) => current + (term.Value + "\n"))); var postParams = new Queue<KeyValuePair<string, string>>(); postParams.Enqueue(new KeyValuePair<string, string>("reason", reason)); postParams.Enqueue(new KeyValuePair<string, string>("termtext", postText)); foreach (var tempTermsList in termsLists.Termslist) { postParams.Enqueue(new KeyValuePair<string, string>("action_modclassid_" + tempTermsList.ModClassId, (tempTermsList.Terms[0].Action).ToString())); } var request = new DnaTestURLRequest(SiteName) { UseEditorAuthentication = true }; request.SetCurrentUserSuperUser(); request.RequestPage("termsfilterimport?action=UPDATETERMS&skin=purexml&ignorecache=1", postParams); ValidateResponse(request); //check correct error message returned ValidateOkResult(request, "TermsUpdateSuccess", "Terms updated successfully."); //check history table termsLists = ValidateHistory(request, reason, termsLists); //Check that all terms are actually associated ValidateTermAssociations(request, termsLists); }
/// <summary> /// /// </summary> /// <returns></returns> public static TermsList GetTermsListForAForum() { var expected = new TermsList(1, false, true); expected.Terms.Add(TermTest.CreateTerm()); return expected; }
public void TermsFilterImportPage_AddMultipleTermsWithErrors_ReturnsErrors() { var term1 = Guid.NewGuid().ToString(); var term2 = Guid.NewGuid().ToString(); //set up data var reason = "this has a reason"; var termsLists = new TermsLists(); var termsList = new TermsList(1); termsList.Terms.Add(new TermDetails { Action = TermAction.Refer, Value = term1 }); termsList.Terms.Add(new TermDetails { Action = TermAction.Refer, Value = term2 }); termsLists.Termslist.Add(termsList); termsList = new TermsList(2); termsList.Terms.Add(new TermDetails { Action = TermAction.ReEdit, Value = term1 }); termsList.Terms.Add(new TermDetails { Action = TermAction.ReEdit, Value = term2 }); termsLists.Termslist.Add(termsList); string postText = termsLists.Termslist.Aggregate("", (current1, tmpTermsList) => tmpTermsList.Terms.Aggregate(current1, (current, term) => current + (term.Value + "\n"))); var postParams = new Queue<KeyValuePair<string, string>>(); postParams.Enqueue(new KeyValuePair<string, string>("reason", reason)); postParams.Enqueue(new KeyValuePair<string, string>("termtext", postText)); foreach (var tempTermsList in termsLists.Termslist) { postParams.Enqueue(new KeyValuePair<string, string>("action_modclassid_" + tempTermsList.ModClassId, (tempTermsList.Terms[0].Action).ToString())); } postParams.Enqueue(new KeyValuePair<string, string>("action_modclassid_" + 3, "100"));//invalid action var request = new DnaTestURLRequest(SiteName) { UseEditorAuthentication = true }; request.SetCurrentUserSuperUser(); request.RequestPage("termsfilterimport?action=UPDATETERMS&skin=purexml&ignorecache=1", postParams); //check correct error message returned ValidateError(request, "UPDATETERMINVALIDACTION", "Terms action invalid."); }
public void GetTermsListByForumId_NonCachedVersion_ReturnsCachedVersion() { var expected = new TermsList(); expected.Terms.Add(TermTest.CreateTerm()); string key = expected.GetCacheKey(0); var reader = Mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); var readerCreator = Mocks.DynamicMock<IDnaDataReaderCreator>(); readerCreator.Stub(x => x.CreateDnaDataReader("gettermsbyforumid")).Return(reader); var cacheManager = Mocks.DynamicMock<ICacheManager>(); cacheManager.Stub(x => x.GetData(key)).Return(null); Mocks.ReplayAll(); TermsList actual = TermsList.GetTermsListByForumId(readerCreator, cacheManager, 0, false); Assert.AreEqual(expected.Terms.Count, actual.Terms.Count); }
public void CreateComment_AsPlainText_ForumTermsFilterTest() { Console.WriteLine("Before CreateComment"); var forumTerm = "hum123"; var forumReason = "Reason related to forum"; DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); //create the forum CommentForum commentForum = CommentForumCreate("tests", Guid.NewGuid().ToString()); string text = "Functiontest Title : Hello hum123 hello"; PostStyle.Style postStyle = PostStyle.Style.plaintext; string commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" + "<text>{0}</text>" + "<poststyle>{1}</poststyle>" + "</comment>", text, postStyle); ICacheManager _cache = CacheFactory.GetCacheManager(); IDnaDataReaderCreator creator = DnaMockery.CreateDatabaseReaderCreator(); var termList = new TermsList(commentForum.ForumID, false, true); termList.Terms.Add(new TermDetails { Value = forumTerm, Action = TermAction.Refer }); Error error = termList.UpdateTermsInDatabase(creator, _cache, forumReason, 6, false); SendTermsSignal(); // Setup the request url string url = String.Format("https://" + _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(); CommentInfo returnedComment = (CommentInfo)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentInfo)); Assert.IsTrue(returnedComment.text == text); Assert.IsTrue(returnedComment.PostStyle == postStyle); Assert.IsNotNull(returnedComment.User); Assert.IsTrue(returnedComment.User.UserId == request.CurrentUserID); Console.WriteLine("After CreateComment"); //CheckTermsInDB(forumTerm); var termId = 0; var threadModId = 0; using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("select * from threadmod where modid = (select max(modid) from threadmod)"); Assert.IsTrue(reader.Read()); Assert.AreEqual("Filtered terms: " + forumTerm, reader.GetStringNullAsEmpty("notes")); reader.ExecuteDEBUGONLY("select ID from TermsLookUp where term='" + forumTerm + "'"); Assert.IsTrue(reader.Read()); termId = reader.GetInt32("ID"); reader.ExecuteDEBUGONLY("select * from ForumModTermMapping where threadmodid = (select max(modid) from threadmod)"); Assert.IsTrue(reader.Read()); Assert.AreEqual(termId, reader.GetInt32("TermID")); threadModId = reader.GetInt32("ThreadModID"); } } var terms = TermsList.GetTermsListByThreadModIdFromThreadModDB(creator, threadModId, true); Assert.AreEqual(forumTerm, terms.Terms[0].Value); Assert.AreEqual(forumReason, terms.Terms[0].Reason); }
public void GetTermsListByThreadModIdFromThreadModDB_ReturnsNonEmptyList() { var expected = new TermsList(7, true); expected.Terms.Add(TermDetailsTest.CreateTermDetails()); string key = expected.GetCacheKey(0); var reader = Mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); reader.Stub(x => x.HasRows).Return(true).Repeat.Once(); var readerCreator = Mocks.DynamicMock<IDnaDataReaderCreator>(); readerCreator.Stub(x => x.CreateDnaDataReader("gettermsbymodidfromthreadmod")).Return(reader); Mocks.ReplayAll(); TermsList actual = TermsList.GetTermsListByThreadModIdFromThreadModDB(readerCreator, 0, false); Assert.AreEqual(expected.Terms.Count, actual.Terms.Count); }
public void CreateComment_AsPlainText_ReferForumTermsReferModClassFilterTest() { Console.WriteLine("Before CreateComment"); var forumTerm = "arse"; var forumReason = "Reason related to forum"; DnaTestURLRequest request = new DnaTestURLRequest(_sitename); request.SetCurrentUserNormal(); //create the forum CommentForum commentForum = CommentForumCreate("tests", Guid.NewGuid().ToString()); string text = "Functiontest Title : Hello arse hello"; PostStyle.Style postStyle = PostStyle.Style.plaintext; string commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" + "<text>{0}</text>" + "<poststyle>{1}</poststyle>" + "</comment>", text, postStyle); ICacheManager _cache = CacheFactory.GetCacheManager(); IDnaDataReaderCreator creator = DnaMockery.CreateDatabaseReaderCreator(); var termList = new TermsList(commentForum.ForumID, false, true); termList.Terms.Add(new TermDetails { Value = forumTerm, Action = TermAction.Refer }); Error error = termList.UpdateTermsInDatabase(creator, _cache, forumReason, 6, false); SendTermsSignal(); //new TermsFilterImportPageTests().TermsFilterImportPage_AddSingleReferTermToAll_PassesValidation(); // Setup the request url string url = String.Format("https://" + _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(); CommentInfo returnedComment = (CommentInfo)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentInfo)); Assert.IsTrue(returnedComment.text == text); Assert.IsTrue(returnedComment.PostStyle == postStyle); Assert.IsNotNull(returnedComment.User); Assert.IsTrue(returnedComment.User.UserId == request.CurrentUserID); Console.WriteLine("After CreateComment"); CheckTermsInDB(forumTerm); }
public void UpdateTermsWithHistoryId_InvalidTerms_ReturnsCorrectError() { var cacheManager = Mocks.DynamicMock<ICacheManager>(); var historyReader = Mocks.DynamicMock<IDnaDataReader>(); historyReader.Stub(x => x.Read()).Return(false); var creator = Mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterterm")).Return(Mocks.DynamicMock<IDnaDataReader>()); creator.Stub(x => x.CreateDnaDataReader("gettermsbymodclassid")).Return(historyReader); Mocks.ReplayAll(); Error expected = new Error { Type = "UpdateTermForModClassId", ErrorMessage = "Term value cannot be empty." + Environment.NewLine + "Term value cannot be empty." }; var target = new TermsList(); target.Terms.Add(new TermDetails());//empty is invalid target.Terms.Add(new TermDetails()); var actual = target.UpdateTermsWithHistoryId(creator, cacheManager, 1, true); Assert.AreEqual(expected.ErrorMessage, actual.ErrorMessage); Assert.AreEqual(expected.Type, actual.Type); creator.Stub(x => x.CreateDnaDataReader("gettermsbyforumid")).Return(historyReader); Mocks.ReplayAll(); Error forumExpected = new Error { Type = "UpdateTermForForumId", ErrorMessage = "Term value cannot be empty." + Environment.NewLine + "Term value cannot be empty." }; var forumActual = target.UpdateTermsWithHistoryId(creator, cacheManager, 1, false); Assert.AreEqual(forumExpected.ErrorMessage, forumActual.ErrorMessage); Assert.AreEqual(forumExpected.Type, forumActual.Type); }
/// <summary> /// Checks the term is in the db correctly /// </summary> /// <param name="termStr"></param> private void CheckTermsInDB(string termStr) { var threadModId = 0; var modClassId = 0; var userId = 6; var termId = 0; using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("select * from threadmod where modid = (select max(modid) from threadmod)"); Assert.IsTrue(reader.Read()); Assert.AreEqual("Filtered terms: " + termStr, reader.GetStringNullAsEmpty("notes")); reader.ExecuteDEBUGONLY("select ID from TermsLookUp where term='" + termStr + "'"); Assert.IsTrue(reader.Read()); termId = reader.GetInt32("ID"); reader.ExecuteDEBUGONLY("select * from ForumModTermMapping where threadmodid = (select max(modid) from threadmod)"); Assert.IsTrue(reader.Read()); Assert.AreEqual(termId, reader.GetInt32("TermID")); threadModId = reader.GetInt32("ThreadModID"); reader.ExecuteDEBUGONLY("SELECT s.modclassid AS ModClassID FROM threadmod TM INNER JOIN sites S ON TM.SiteID = S.SiteID WHERE modid = (select max(modid) from threadmod) "); Assert.IsTrue(reader.Read()); modClassId = reader.GetInt32("ModClassID"); } } //ensure an update so that there is a reson in db var reason = "test reason"; IDnaDataReaderCreator creator = DnaMockery.CreateDatabaseReaderCreator(); var termsLists = new TermsLists(); var term = new TermDetails() { Value = termStr, Action = TermAction.Refer }; var termsList = new TermsList(modClassId); termsList.Terms.Add(term); termsLists.Termslist.Add(termsList); termsLists.UpdateTermsInDatabase(creator, CacheFactory.GetCacheManager(), reason, userId, true); //check reason is valid in output termsList = TermsList.GetTermsListByThreadModIdFromThreadModDB(creator, threadModId, true); Assert.AreEqual(termStr, termsList.Terms[0].Value); Assert.AreEqual(reason, termsList.Terms[0].Reason); }
public void UpdateTermsInDatabase_InvalidTerms_ReturnsCorrectError() { var cacheManager = Mocks.DynamicMock<ICacheManager>(); var historyReader = Mocks.DynamicMock<IDnaDataReader>(); historyReader.Stub(x => x.GetInt32NullAsZero("historyId")).Return(1); historyReader.Stub(x => x.Read()).Return(true).Repeat.Once(); var creator = Mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterterm")).Return(Mocks.DynamicMock<IDnaDataReader>()); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterupdate")).Return(historyReader); var getTermsReader = Mocks.DynamicMock<IDnaDataReader>(); getTermsReader.Stub(x => x.Read()).Return(false); creator.Stub(x => x.CreateDnaDataReader("gettermsbymodclassid")).Return(getTermsReader); Mocks.ReplayAll(); string reason = "a reason"; int userId = 1; Error expected = new Error { Type = "UpdateTermForModClassId", ErrorMessage = "Term value cannot be empty./r/nTerm value cannot be empty." }; var termsList = new TermsList(1); termsList.Terms.Add(new TermDetails()); TermsLists target = new TermsLists(); target.Termslist.Add(termsList); target.Termslist.Add(termsList); Error actual = target.UpdateTermsInDatabase(creator, cacheManager, reason, userId, true); Assert.AreEqual(expected.ErrorMessage, actual.ErrorMessage); Assert.AreEqual(expected.Type, actual.Type); creator.AssertWasNotCalled(x => x.CreateDnaDataReader("addtermsfilterterm")); creator.AssertWasCalled(x => x.CreateDnaDataReader("addtermsfilterupdate")); }
/// <summary> /// Constructor /// </summary> public TermsFilterAdmin() { TermsList = new TermsList(); ModerationClasses = new ModerationClassList(); }