public void HideThread_NotRead_ReturnsValidError() { IUser viewingUser = mocks.DynamicMock<IUser>(); viewingUser.Stub(x => x.IsEditor).Return(false); viewingUser.Stub(x => x.IsSuperUser).Return(true); ISiteList siteList = mocks.DynamicMock<ISiteList>(); IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.HasRows).Return(false); reader.Stub(x => x.Read()).Return(false); reader.Stub(x => x.GetInt32NullAsZero("ThreadBelongsToForum")).Return(0); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("SetThreadVisibletoUsers")).Return(reader).Repeat.Once(); mocks.ReplayAll(); ForumHelper target = new ForumHelper(creator, viewingUser, siteList); target.HideThread(0, 0); Assert.AreEqual("HideThread", target.LastError.Type); Assert.AreEqual("Unable to hide thread", target.LastError.ErrorMessage); }
public void HideThread_IsInForum_ReturnsSuccess() { IUser viewingUser = mocks.DynamicMock<IUser>(); viewingUser.Stub(x => x.IsEditor).Return(false); viewingUser.Stub(x => x.IsSuperUser).Return(true); ISiteList siteList = mocks.DynamicMock<ISiteList>(); IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.HasRows).Return(false); reader.Stub(x => x.Read()).Return(true); reader.Stub(x => x.GetInt32NullAsZero("ThreadBelongsToForum")).Return(1); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("SetThreadVisibletoUsers")).Return(reader).Repeat.AtLeastOnce(); mocks.ReplayAll(); ForumHelper target = new ForumHelper(creator, viewingUser, siteList); target.HideThread(0, 0); Assert.IsNull(target.LastError); }
public void HideThread_NotSuperUser_ReturnsValidError() { IUser viewingUser = mocks.DynamicMock<IUser>(); viewingUser.Stub(x => x.IsEditor).Return(false); viewingUser.Stub(x => x.IsSuperUser).Return(false); ISiteList siteList = mocks.DynamicMock<ISiteList>(); siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "ArticleAuthorCanCloseThreads")).Return(true); IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.HasRows).Return(false); reader.Stub(x => x.Read()).Return(false); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("SetThreadVisibletoUsers")).Throw(new Exception("SetThreadVisibletoUsers should not have been called")); mocks.ReplayAll(); ForumHelper target = new ForumHelper(creator, viewingUser, siteList); target.HideThread(0,0); Assert.AreEqual("HideThread", target.LastError.Type); Assert.AreEqual("Logged in user is not authorised to hide threads", target.LastError.ErrorMessage); }