public void RemoveThreadFromSticky_Authorised_ReturnsNoError() { var viewingUser = mocks.DynamicMock<IUser>(); viewingUser.Stub(x => x.IsEditor).Return(true); viewingUser.Stub(x => x.IsSuperUser).Return(false); var siteList = mocks.DynamicMock<ISiteList>(); siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "EnableStickyThreads")).Return(true); var reader = mocks.DynamicMock<IDnaDataReader>(); var creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("removethreadfromstickylist")).Return(reader).Repeat.AtLeastOnce(); mocks.ReplayAll(); var target = new ForumHelper(creator, viewingUser, siteList); target.RemoveThreadFromStickyList(0, 0, 0); Assert.IsNull(target.LastError); }
public void RemoveThreadFromSticky_DatabaseError_ReturnsValidError() { var viewingUser = mocks.DynamicMock<IUser>(); viewingUser.Stub(x => x.IsEditor).Return(false); viewingUser.Stub(x => x.IsSuperUser).Return(true); var siteList = mocks.DynamicMock<ISiteList>(); siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "EnableStickyThreads")).Return(true); var reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Execute()).IgnoreArguments().Throw(new Exception("Database error")); var creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("removethreadfromstickylist")).Return(reader).Repeat.AtLeastOnce(); mocks.ReplayAll(); var target = new ForumHelper(creator, viewingUser, siteList); target.RemoveThreadFromStickyList(0, 0, 0); Assert.AreEqual("RemoveThreadFromStickyList", target.LastError.Type); Assert.AreEqual("Unable to update database.", target.LastError.ErrorMessage); }
public void RemoveThreadFromSticky_NotAuthorised_ReturnsValidError() { var viewingUser = mocks.DynamicMock<IUser>(); viewingUser.Stub(x => x.IsEditor).Return(false); viewingUser.Stub(x => x.IsSuperUser).Return(false); var siteList = mocks.DynamicMock<ISiteList>(); siteList.Stub(x => x.GetSiteOptionValueBool(0, "Forum", "EnableStickyThreads")).Return(true); //var reader = mocks.DynamicMock<IDnaDataReader>(); var creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("removethreadfromstickylist")).Throw(new Exception("RemoveThreadFromStickyList should not have been called")); mocks.ReplayAll(); var target = new ForumHelper(creator, viewingUser, siteList); target.RemoveThreadFromStickyList(0, 0, 0); Assert.AreEqual("RemoveThreadFromStickyList", target.LastError.Type); Assert.AreEqual("Viewing user unauthorised.", target.LastError.ErrorMessage); }