static public ForumThreadPosts CreateThread() { ForumThreadPosts thread = new ForumThreadPosts() { Post = new System.Collections.Generic.List<ThreadPost>(), FirstPostSubject = String.Empty, }; thread.Post.Add(ThreadPostTest.CreateThreadPost()); return thread; }
public void ApplySiteOptions_ValidSiteOption_ReturnsCorrectObject() { int siteId=1; MockRepository mocks = new MockRepository(); ISite site = mocks.DynamicMock<ISite>(); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false).Constraints(Is.Anything()); ISiteList siteList = mocks.DynamicMock<ISiteList>(); siteList.Stub(x => x.GetSiteOptionValueInt(siteId, "Forum", "PostLimit")).Return(10); siteList.Stub(x => x.GetSite(siteId)).Return(site); IUser user = mocks.DynamicMock<IUser>(); user.Stub(x => x.UserId).Return(1); user.Stub(x => x.IsEditor).Return(true); mocks.ReplayAll(); ForumThreadPosts target = new ForumThreadPosts() { SiteId = siteId }; target.ApplySiteOptions(user, siteList); Assert.AreEqual(target.ForumPostLimit, 10); }
public void ApplyUserSettings_AsEditor_ReturnsReadWriteObject() { int siteId = 1; MockRepository mocks = new MockRepository(); ISite site = mocks.DynamicMock<ISite>(); site.Stub(x => x.SiteID).Return(siteId); IUser user = mocks.DynamicMock<IUser>(); user.Stub(x => x.UserId).Return(1); user.Stub(x => x.IsEditor).Return(true); IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getthreadgroupalertid")).Return(reader); mocks.ReplayAll(); ForumThreadPosts target = new ForumThreadPosts(); target.ApplyUserSettings(user, creator); Assert.AreEqual(target.CanRead, 1); Assert.AreEqual(target.CanWrite, 1); //test as superuser user = mocks.DynamicMock<IUser>(); user.Stub(x => x.UserId).Return(1); user.Stub(x => x.IsSuperUser).Return(true); mocks.ReplayAll(); target.ApplyUserSettings(user, creator); Assert.AreEqual(target.CanRead, 1); Assert.AreEqual(target.CanWrite, 1); }
public void ApplyUserSettings_SiteClosedAndSuperUser_ReturnsCorrectPermissions() { ISite site; IUser user; IDnaDataReaderCreator creator; ApplyUserSettingsTestSetup(out site, out user, out creator); ForumThreadPosts target = new ForumThreadPosts(); //with editor/superuser target = new ForumThreadPosts() { CanWrite = 0, CanRead = 0 }; user.Stub(x => x.IsSuperUser).Return(true); target.ApplyUserSettings(user, creator); Assert.AreEqual(target.CanRead, 1); Assert.AreEqual(target.CanWrite, 1); }
public void ApplyUserSettings_SiteScheduledClosed_ReturnsCorrectPermissions() { ISite site; IUser user; IDnaDataReaderCreator creator; ApplyUserSettingsTestSetup(out site, out user, out creator); ForumThreadPosts target = new ForumThreadPosts(); //try scheduled closed site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(true); target.ApplyUserSettings(user, creator); Assert.AreEqual(target.CanRead, 1); Assert.AreEqual(target.CanWrite, 0); }
public void ApplyUserSettings_SiteEmergencyClosed_ReturnsCorrectPermissions() { ISite site; IUser user; IDnaDataReaderCreator creator; ApplyUserSettingsTestSetup(out site, out user, out creator); ForumThreadPosts target = new ForumThreadPosts(); target.ApplyUserSettings(user, creator); Assert.AreEqual(target.CanRead, 1); Assert.AreEqual(target.CanWrite, 0); }
public void ApplyUserSettings_StandardUserWithPermissions_ReturnsCorrectPermissions() { int siteId = 1; MockRepository mocks = new MockRepository(); ISite site = mocks.DynamicMock<ISite>(); site.Stub(x => x.SiteID).Return(siteId); site.Stub(x => x.IsEmergencyClosed).Return(false); site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false); IUser user = mocks.DynamicMock<IUser>(); user.Stub(x => x.UserId).Return(1); IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true); reader.Stub(x => x.GetBoolean("CanWrite")).Return(false); reader.Stub(x => x.GetBoolean("CanRead")).Return(true); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getthreadpermissions")).Return(reader); creator.Stub(x => x.CreateDnaDataReader("getthreadgroupalertid")).Return(reader);//required for emailalertgroup stuff mocks.ReplayAll(); ForumThreadPosts target = new ForumThreadPosts(); target.ApplyUserSettings(user, creator); Assert.AreEqual(target.CanRead, 1); Assert.AreEqual(target.CanWrite, 0); //try the reverse target.Post = new System.Collections.Generic.List<ThreadPost>(); target.Post.Add(ThreadPostTest.CreateThreadPost()); reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.HasRows).Return(true); reader.Stub(x => x.Read()).Return(true); reader.Stub(x => x.GetBoolean("CanRead")).Return(false); reader.Stub(x => x.GetBoolean("CanWrite")).Return(true); creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getthreadpermissions")).Return(reader); creator.Stub(x => x.CreateDnaDataReader("getthreadgroupalertid")).Return(reader);//required for emailalertgroup stuff mocks.ReplayAll(); target.ApplyUserSettings(user, creator); Assert.AreEqual(target.CanRead, 0); Assert.AreEqual(target.CanWrite, 1); Assert.AreEqual(target.Post.Count, 0);//can read is 0 so no posts please. }