Пример #1
0
        public void UpdateTermsInDatabase_WithoutUser_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 = 0;
            Error expected = new Error { Type = "UpdateTermsInDatabase", ErrorMessage = "Valid user must be supplied" };

            TermsLists target = new TermsLists();
            target.Termslist.Add(TermsListTest.GetTermsList());
            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.AssertWasNotCalled(x => x.CreateDnaDataReader("addtermsfilterupdate"));
        }
Пример #2
0
        /// <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;
        }
Пример #3
0
        public void UpdateTermsInDatabase_CorrectValue_ReturnsNullError()
        {
            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 = "UpdateTermsInDatabase", ErrorMessage = "Unable to get history id" };

            TermsLists target = new TermsLists();
            target.Termslist.Add(TermsListTest.GetTermsList());
            Error actual = target.UpdateTermsInDatabase(creator, cacheManager, reason, userId, true);

            Assert.IsNull(actual);

            creator.AssertWasCalled(x => x.CreateDnaDataReader("addtermsfilterterm"));
            creator.AssertWasCalled(x => x.CreateDnaDataReader("addtermsfilterupdate"));
        }
Пример #4
0
        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"));
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        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());
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        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;
        }