public void CreateTermAdmin_FromCache_ReturnsValidObject() { ModerationClassListTest.InitialiseClasses(); TermsList termsList = TermsListTest.GetTermsList(); const int modClassId = 1; var cacheManager = Mocks.DynamicMock<ICacheManager>(); TermDetails termDetail = new TermDetails(); termDetail.Id = 1; termDetail.Value = "whoopsy"; termDetail.Reason = "It's not right"; DateTime updatedDate = DateTime.Now; termDetail.UpdatedDate = new DateElement(updatedDate); termDetail.UserID = 123456978; termDetail.UserName = "******"; termDetail.Action = TermAction.ReEdit; var reader = Mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.AddParameter("modClassId", modClassId)).Return(reader); reader.Stub(x => x.Execute()).Return(reader); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); reader.Stub(x => x.GetInt32NullAsZero("TermID")).Return(termDetail.Id); reader.Stub(x => x.GetStringNullAsEmpty("Term")).Return(termDetail.Value); reader.Stub(x => x.GetStringNullAsEmpty("Reason")).Return(termDetail.Reason); reader.Stub(x => x.GetDateTime("UpdatedDate")).Return(updatedDate); reader.Stub(x => x.GetInt32NullAsZero("UserID")).Return(termDetail.UserID); reader.Stub(x => x.GetStringNullAsEmpty("UserName")).Return(termDetail.UserName); reader.Stub(x => x.GetByteNullAsZero("actionId")).Return((byte)termDetail.Action); var readerCreator = Mocks.DynamicMock<IDnaDataReaderCreator>(); readerCreator.Stub(x => x.CreateDnaDataReader("gettermsbymodclassid")).Return(reader); Mocks.ReplayAll(); var termAdmin = TermsFilterAdmin.CreateTermAdmin(readerCreator, cacheManager, modClassId); Assert.AreEqual(1, termAdmin.TermsList.Terms.Count); Assert.AreEqual(1, termAdmin.ModerationClasses.ModClassList.Count); Assert.AreEqual(termDetail.Id, termAdmin.TermsList.Terms[0].Id); Assert.AreEqual(termDetail.Value, termAdmin.TermsList.Terms[0].Value); Assert.AreEqual(termDetail.Reason, termAdmin.TermsList.Terms[0].Reason); Assert.AreEqual(termDetail.UpdatedDate.Date.DateTime, termAdmin.TermsList.Terms[0].UpdatedDate.Date.DateTime); Assert.AreEqual(termDetail.UserID, termAdmin.TermsList.Terms[0].UserID); Assert.AreEqual(termDetail.UserName, termAdmin.TermsList.Terms[0].UserName); Assert.AreEqual(termDetail.Action, termAdmin.TermsList.Terms[0].Action); }
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); }
/// <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); }