public void DeleteCommend(int id) { CommentForum commi = db.CommentForum.Single(p => p.CommentForum_id == id); db.CommentForum.Remove(commi); db.SaveChanges(); }
//评论回复 public void AddCommentEssay(CommentForum commforum) { commforum.CommentTime = DateTime.Now; commforum.CommentForumParise = 1; db.CommentForum.Add(commforum); db.SaveChanges(); }
public string AddEssayCommend(CommentForum forum, string essaycontent, string forumid) { var userid = Convert.ToInt32(Session["User_id"]); var forumdew = Convert.ToInt32(forumid); if (!string.IsNullOrEmpty(essaycontent)) { forum.Content = essaycontent; forum.Forum_id = forumdew; forum.User_id = userid; ForumManage.AddCommentEssay(forum); return("success"); } else { return("fail"); } }
public void CommentCreate_NotSignedInUserWithDisplayName_ReturnCorrectObject() { var siteName = "h2g2"; var uid = "uid"; var text = "test comment"; var displayName = "notsignedin"; var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var callingUser = mocks.DynamicMock<ICallingUser>(); var commentForum = new CommentForum { Id = uid, SiteName = siteName, allowNotSignedInCommenting=true, NotSignedInUserId=1 }; var commentInfo = new CommentInfo { text = text }; commentInfo.User = new User { DisplayName = displayName }; callingUser.Stub(x => x.IsSecureRequest).Return(true); callingUser.Stub(x => x.UserID).Return(1); callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything()); cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); reader.Stub(x => x.GetInt32NullAsZero("postid")).Return(1); readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader); site.Stub(x => x.SiteID).Return(1); siteList.Stub(x => x.GetSiteOptionValueString(1, "General", "ComplaintUrl")).Return("http://www.bbc.co.uk/dna/[sitename]/comments/UserComplaintPage?PostID=[postid]&s_start=1"); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, cacheManager, siteList); comments.CallingUser = callingUser; var comment = comments.CreateComment(commentForum, commentInfo); Assert.IsNotNull(comment); Assert.AreEqual(displayName, comment.User.DisplayName); readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate")); reader.AssertWasCalled(x => x.AddParameter("nickname", displayName)); }
public void CommentForumReadByUid_CacheValid_ReturnsValidList() { var lastUpdate = DateTime.Now.AddDays(1); var uid = "testUid"; var validForum = new CommentForum { Id = uid }; var comments = new Comments(null, null, null, null); var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var readerComments = mocks.DynamicMock<IDnaDataReader>(); var readerLastUpdate = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var siteName = "h2g2"; string cacheKey = comments.CommentForumCacheKey(uid, 0); cacheManager.Stub(x => x.GetData(cacheKey + "|LASTUPDATED")).Return(lastUpdate); cacheManager.Stub(x => x.GetData(cacheKey)).Return(validForum); site.Stub(x => x.ModerationStatus).Return(ModerationStatus.SiteStatus.UnMod); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); reader.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName); readerComments.Stub(x => x.HasRows).Return(true); readerComments.Stub(x => x.Read()).Return(true).Repeat.Once(); readerComments.Stub(x => x.GetInt32NullAsZero("totalresults")).Return(1); readerLastUpdate.Stub(x => x.HasRows).Return(true); readerLastUpdate.Stub(x => x.Read()).Return(true).Repeat.Once(); readerLastUpdate.Stub(x => x.GetDateTime("lastupdated")).Return(lastUpdate); readerCreator.Stub(x => x.CreateDnaDataReader("commentforumreadbyuid")).Return(reader); readerCreator.Stub(x => x.CreateDnaDataReader("commentsreadbyforumid")).Return(readerComments); readerCreator.Stub(x => x.CreateDnaDataReader("CommentforumGetLastUpdate")).Return(readerLastUpdate); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); comments = new Comments(null, readerCreator, cacheManager, siteList); var forum = comments.GetCommentForumByUid(uid, site); Assert.IsNotNull(forum); Assert.AreEqual(uid, forum.Id); readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("commentforumreadbyuid")); readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("commentsreadbyforumid")); }
public void CreateAndUpdateCommentForum_AlreadyExists_ThenUpdate() { var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var readerComments = mocks.DynamicMock<IDnaDataReader>(); var readerUpdate = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var siteName = "h2g2"; var uid = "uid"; var commentForum = new CommentForum { Id = uid, Title = "title", ParentUri = "https://www.bbc.co.uk" }; cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.ModerationStatus).Return(ModerationStatus.SiteStatus.UnMod); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Twice(); reader.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName); reader.Stub(x => x.GetStringNullAsEmpty("UID")).Return(uid); reader.Stub(x => x.GetStringNullAsEmpty("Title")).Return(uid); reader.Stub(x => x.GetStringNullAsEmpty("Url")).Return("https://www.bbc.co.uk"); readerUpdate.Stub(x => x.HasRows).Return(true); readerUpdate.Stub(x => x.Read()).Return(true).Repeat.Once(); readerUpdate.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName); readerComments.Stub(x => x.HasRows).Return(true); readerComments.Stub(x => x.Read()).Return(true).Repeat.Twice(); readerComments.Stub(x => x.GetInt32NullAsZero("totalresults")).Return(1); readerCreator.Stub(x => x.CreateDnaDataReader("commentforumreadbyuid")).Return(reader); readerCreator.Stub(x => x.CreateDnaDataReader("commentsreadbyforumid")).Return(readerComments); readerCreator.Stub(x => x.CreateDnaDataReader("commentforumupdate")).Return(readerUpdate); site.Stub(x => x.SiteID).Return(1); siteList.Stub(x => x.GetSiteOptionValueString(1, "General", "ComplaintUrl")).Return("http://www.bbc.co.uk/dna/[sitename]/comments/UserComplaintPage?PostID=[postid]&s_start=1"); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, cacheManager, siteList); var forum = comments.CreateAndUpdateCommentForum(commentForum, site, null); Assert.IsNotNull(forum); readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentforumreadbyuid")); readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentforumupdate")); readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("commentforumcreate")); }
public void CreateCommentRating_DBThrowsException_ThrowsError() { var value = 1; var postId = 1; var userid = 0; var commentForum = new CommentForum() { ForumID = 1 }; ISite site = null; var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Read()).Return(true); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.GetInt32NullAsZero("value")).Return(value); readerCreator.Stub(x => x.CreateDnaDataReader("commentratingcreate")).Return(reader); reader.Stub(x => x.Execute()).Throw(new Exception("test")); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, null, null) { IpAddress = "1.1.1.1", BbcUid = Guid.NewGuid() }; try { comments.CreateCommentRating(commentForum, site, postId, userid, (short)value); } catch (ApiException ex) { Assert.AreEqual(ErrorType.Unknown, ex.type); } //reader.AssertWasNotCalled(x => x.Execute()); }
public void CreateCommentRating_AsUser_ReturnsValue() { var value = 1; var posvalue = 20; var negvalue = -10; var postId = 1; var userid = 1; var commentForum = new CommentForum() { ForumID = 1 }; ISite site = mocks.DynamicMock<ISite>(); site.Stub(x => x.SiteID).Return(1); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Read()).Return(true); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.GetInt32NullAsZero("nerovalue")).Return(value); reader.Stub(x => x.GetInt32NullAsZero("neropositivevalue")).Return(posvalue); reader.Stub(x => x.GetInt32NullAsZero("neronegativevalue")).Return(negvalue); readerCreator.Stub(x => x.CreateDnaDataReader("commentratingcreate")).Return(reader); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, null, null) { IpAddress = "1.1.1.1", BbcUid = Guid.NewGuid() }; var retVal = comments.CreateCommentRating(commentForum, site, postId, userid, (short)value); Assert.AreEqual(value, retVal.neroValue); Assert.AreEqual(posvalue, retVal.positiveNeroValue); Assert.AreEqual(negvalue, retVal.negativeNeroValue); reader.AssertWasCalled(x => x.Execute()); }
public void CreateCommentRating_AsAnonymousWithoutDetails_ThrowsError() { var value = 1; var postId = 1; var userid = 0; var commentForum = new CommentForum() { ForumID=1 }; ISite site = null; var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Read()).Return(true); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.GetInt32NullAsZero("value")).Return(value); readerCreator.Stub(x => x.CreateDnaDataReader("commentratingcreate")).Return(reader); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, null, null) { }; try { comments.CreateCommentRating(commentForum, site, postId, userid, (short)value); } catch (ApiException ex) { Assert.AreEqual(ErrorType.MissingUserAttributes, ex.type); } reader.AssertWasNotCalled(x => x.Execute()); }
public static void UpdateCommend(CommentForum commforum) { foru.UpdateCommend(commforum); }
public void CommentCreate_WithWhiteListTerm_AddsCorrectNotes() { var siteName = "h2g2"; var siteId = 1; var uid = "uid"; var text = " Bomb "; var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var callingUser = mocks.DynamicMock<ICallingUser>(); var commentForum = new CommentForum { Id = uid, SiteName = siteName }; var commentInfo = new CommentInfo { text = text }; callingUser.Stub(x => x.IsSecureRequest).Return(true); callingUser.Stub(x => x.UserID).Return(1); callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything()); cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.SiteID).Return(siteId); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); site.Stub(x => x.ModClassID).Return(3); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, cacheManager, siteList); comments.CallingUser = callingUser; comments.CreateComment(commentForum, commentInfo); readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate")); reader.AssertWasCalled(x => x.AddParameter("modnotes", "Filtered terms: bomb")); }
public void CommentCreate_NotSecureWithoutSiteOption_ReturnCorrectComment() { var siteName = "h2g2"; var uid = "uid"; var text = "Here is my text that is not posted securely"; var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var callingUser = mocks.DynamicMock<ICallingUser>(); var commentForum = new CommentForum { Id = uid, SiteName = siteName }; var commentInfo = new CommentInfo { text = text }; callingUser.Stub(x => x.UserID).Return(1); callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything()); cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader); siteList.Stub(x => x.GetSite(siteName)).Return(site); siteList.Stub(x => x.GetSiteOptionValueInt(0, "CommentForum", "EnforceSecurePosting")).Return(0); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, cacheManager, siteList); comments.CallingUser = callingUser; comments.CreateComment(commentForum, commentInfo); readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate")); }
public void UpdateCommend(CommentForum commforum) { db.Entry <CommentForum>(commforum).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); }
public void CommentCreate_AsPreMod_ReturnCorrectError() { var siteName = "h2g2"; var siteId = 1; var uid = "uid"; var text = "test text"; var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var callingUser = mocks.DynamicMock<ICallingUser>(); var commentForum = new CommentForum { Id = uid, SiteName = siteName, ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod }; var commentInfo = new CommentInfo { text = text }; callingUser.Stub(x => x.IsSecureRequest).Return(true); callingUser.Stub(x => x.UserID).Return(1); callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything()); cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.SiteID).Return(siteId); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, cacheManager, siteList); comments.CallingUser = callingUser; var comment = comments.CreateComment(commentForum, commentInfo); Assert.IsNotNull(comment); readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate")); }
public void CommentCreate_ForumClosed_NotableUser_ReturnResults() { var siteName = "h2g2"; var siteId = 1; var uid = "uid"; var text = "test comment"; var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var callingUser = mocks.DynamicMock<ICallingUser>(); var commentForum = new CommentForum { Id = uid, SiteName = siteName }; var commentInfo = new CommentInfo { text = text }; callingUser.Stub(x => x.IsSecureRequest).Return(true); callingUser.Stub(x => x.UserID).Return(1); callingUser.Stub(x => x.IsUserA(UserTypes.Notable)).Return(true); cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.SiteID).Return(siteId); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, cacheManager, siteList); comments.CallingUser = callingUser; var retVal = comments.CreateComment(commentForum, commentInfo); Assert.AreEqual(text, retVal.text); reader.AssertWasCalled(x => x.Execute()); }
public void CommentCreate_BannedUser_ReturnCorrectError() { var siteName = "h2g2"; var uid = "uid"; var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); var callingUser = mocks.DynamicMock<ICallingUser>(); var commentForum = new CommentForum { Id = uid, SiteName = siteName }; var commentInfo = new CommentInfo { text = "test" }; callingUser.Stub(x => x.IsSecureRequest).Return(true); callingUser.Stub(x => x.UserID).Return(1); callingUser.Stub(x => x.IsUserA(UserTypes.BannedUser)).Return(true); cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); var comments = new Comments(null, readerCreator, cacheManager, siteList); comments.CallingUser = callingUser; try { comments.CreateComment(commentForum, commentInfo); throw new Exception("No exception thrown"); } catch (ApiException ex) { Assert.AreEqual(ErrorType.UserIsBanned, ex.type); } readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("commentcreate")); }
//评论回复 public static void AddCommentEssay(CommentForum commforum) { foru.AddCommentEssay(commforum); }