Ejemplo n.º 1
0
 public ThreadPost CreateThread(string siteName, string forumId, ThreadPost threadPost)
 {
     return CreateThreadPost(siteName, forumId, "0", threadPost);
 }
Ejemplo n.º 2
0
 public void FirstChildSpecified_SomethingSet_ReturnsTrue()
 {
     ThreadPost target = new ThreadPost();
     target.FirstChild = 1;
     Assert.IsTrue(target.FirstChildSpecified);
 }
Ejemplo n.º 3
0
        public void PostToForum_ReturnValueNotZero_ThrowsException()
        {
            var forumId = 1;
            var threadId = 1;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);
            ISite site = mocks.DynamicMock<ISite>();
            IUser viewingUser = mocks.DynamicMock<IUser>();
            ISiteList siteList = mocks.DynamicMock<ISiteList>();

            viewingUser.Stub(x => x.UserId).Return(1);
            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            CreatePostFreq(mocks, ref readerCreator, 0);
            IDnaDataReader readerReturn = mocks.DynamicMock<IDnaDataReader>();
            readerReturn.Stub(x => x.Read()).Return(true);
            readerReturn.Stub(x => x.DoesFieldExist("errorcode")).Return(true);
            readerReturn.Stub(x => x.GetInt32NullAsZero("errorcode")).Return(547);
            readerCreator.Stub(x => x.CreateDnaDataReader("posttoforum")).Return(readerReturn);

            mocks.ReplayAll();
            //(ICacheManager cacheManager, IDnaDataReaderCreator readerCreator, ISite site, 
            //IUser viewingUser, ISiteList siteList, string _iPAddress, Guid bbcUidCookie, int forumId)

            var threadPost = new ThreadPost()
            {
                Text = "test post",
                Subject = "test subject",
                ThreadId = threadId
            };

            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            }
            catch (ApiException e)
            {
                Assert.IsTrue(e.Message.IndexOf("547") > 0);
            }

        }
Ejemplo n.º 4
0
 public void NextIndexSpecified_SomethingSet_ReturnsTrue()
 {
     ThreadPost target = new ThreadPost();
     target.NextIndex = 1;
     Assert.IsTrue(target.NextIndexSpecified);
 }
Ejemplo n.º 5
0
 public void InReplyToSpecified_SomethingSet_ReturnsTrue()
 {
     ThreadPost target = new ThreadPost();
     target.InReplyTo = 1;
     Assert.IsTrue(target.InReplyToSpecified);
 }
Ejemplo n.º 6
0
 public void ThreadIdSpecified_SomethingSet_ReturnsTrue()
 {
     ThreadPost target = new ThreadPost(); 
     bool actual;
     target.ThreadId = 1;
     actual = target.ThreadIdSpecified;
     Assert.AreEqual(true, actual);
 }
Ejemplo n.º 7
0
 public void PrevSiblingSpecified_SomethingSet_ReturnsTrue()
 {
     ThreadPost target = new ThreadPost();
     target.PrevSibling = 1;
     Assert.IsTrue(target.PrevSiblingSpecified);
 }
Ejemplo n.º 8
0
        public void PostToForum_WithProfanityInSubjectOfReply_NoError()
        {// subject is not checked on subsequent replies
            var forumId = 1;
            var threadId = 1;
            var postId = 10;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            CreatePostToForumObjects(mocks, ref readerCreator, postId, threadId, false);
            CreatePostFreq(mocks, ref readerCreator, 0);
            var viewingUser = CreateUserObject(mocks, false, false, false);
            ISite site = CreateSiteObject(mocks, false, false);
            ISiteList siteList = CreateSiteList(mocks, 1, 0, 0, false);
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);

            mocks.ReplayAll();



            var threadPost = new ThreadPost()
            {
                Text = "contains profanity  ",
                Subject = "test subject (ock and",
                ThreadId = threadId,
                InReplyTo = 1
            };



            threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            
        }
Ejemplo n.º 9
0
        public void PostToForum_ProcessPreMod_ReturnsIsPreModPosting()
        {
            var forumId = 1;
            var postId = 0;
            var threadId = 1;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            CreatePostToForumObjects(mocks, ref readerCreator, postId, threadId, true);
            CreatePostFreq(mocks, ref readerCreator, 0);
            var viewingUser = CreateUserObject(mocks, false, false, false);
            ISite site = CreateSiteObject(mocks, false, false);
            ISiteList siteList = CreateSiteList(mocks, 1, 0, 0, false);
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);

            mocks.ReplayAll();
            //(ICacheManager cacheManager, IDnaDataReaderCreator readerCreator, ISite site, 
            //IUser viewingUser, ISiteList siteList, string _iPAddress, Guid bbcUidCookie, int forumId)

            var threadPost = new ThreadPost()
            {
                Text = "contains txt",
                Subject = "test subject",
                ThreadId = threadId
            };


            ApiException e = null;
            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            }
            catch (ApiException err)
            {
                e = err;
            }
            Assert.IsNull(e);

            Assert.AreEqual(postId, threadPost.PostId);
            Assert.AreEqual(threadId, threadPost.ThreadId);
            Assert.IsTrue(threadPost.IsPreModPosting);
        }
Ejemplo n.º 10
0
        public void CreateThreadPost_WithValidValues_CreatesRecord()
        {
            // 1) prepare the test
            int postid = 222;
            int threadid = 333;
            int userid = 999;
            int forumid = 888;
            int inReplyTo = 123;
            int threadId = 465;
            string subject = "subject";
            string text = "text";
            bool ignoreModeration = true;
            bool notablable = true;
            bool iscomment = false;
            string ipAddress = "1.1.1.1";
            Guid bbcUID = Guid.NewGuid();
            bool allowQueing = false;
            bool forcePreModerate = true;
            bool forceModerate = true;

            // essential details
            ThreadPost newThreadPost = new ThreadPost();            
            newThreadPost.InReplyTo = inReplyTo;
            newThreadPost.ThreadId = threadId;
            newThreadPost.Subject = subject;
            newThreadPost.Text = text;
            newThreadPost.Style = PostStyle.Style.richtext;

            var reader = Mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.DoesFieldExist("postid")).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("postid")).Return(postid);
            reader.Stub(x => x.DoesFieldExist("threadid")).Return(true);   
            reader.Stub(x => x.GetInt32NullAsZero("threadid")).Return(threadid);             

            var readerCreator = Mocks.DynamicMock<IDnaDataReaderCreator>();
            readerCreator.Stub(x => x.CreateDnaDataReader("posttoforum")).Return(reader);
            Mocks.ReplayAll();

            // 2) execute the test
            newThreadPost.CreateForumPost(readerCreator,
                userid,
                forumid,
                ignoreModeration,
                notablable,
                ipAddress,
                bbcUID,
                iscomment,
                allowQueing,
                forcePreModerate,
                forceModerate,
                "",string.Empty);

            // 3) verify the results
            Assert.AreEqual(postid, newThreadPost.PostId);
            Assert.AreEqual(threadid, newThreadPost.ThreadId);

        }
Ejemplo n.º 11
0
        public void PostToForum_InvalidHTML_NoError()
        {
            // due to the added protection and encoding ont he front end - this is no longer checked.
            //it was causing issues with double encoding and historical posts need to be maintained.
            var forumId = 1;
            var threadId = 1;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);


            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            var viewingUser = CreateUserObject(mocks, false, false, false);
            ISite site = CreateSiteObject(mocks, false, false);
            ISiteList siteList = CreateSiteList(mocks, 1, 0, 0, false);

            mocks.ReplayAll();
            //(ICacheManager cacheManager, IDnaDataReaderCreator readerCreator, ISite site, 
            //IUser viewingUser, ISiteList siteList, string _iPAddress, Guid bbcUidCookie, int forumId)

            var threadPost = new ThreadPost()
            {
                Text = "<div>more than 5 chars",
                Subject = "test subject",
                ThreadId = threadId,
                Style = PostStyle.Style.richtext
            };

            threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            
        }
Ejemplo n.º 12
0
        private static void NotifyAuthorOnPersonalSpace(IDnaDataReaderCreator readerCreator,
            int submitterId,
            string submitterUsername,
            int editorId, 
            string editorUsername, 
            int articleId,
            BBC.Dna.Sites.ISite site, 
            int reviewForumId,
            int newThreadForumId,
            int newThreadThreadId,
            int newThreadPostId, 
            string subject, 
            string comments)
        {

            int personalSpaceForumID = FetchPersonalSpaceForum(readerCreator, editorId, site.SiteID);

            ReviewForum reviewForum = ReviewForum.CreateFromDatabase(readerCreator, reviewForumId, true);

            string generatedSubject = "Your entry has been submitted to '" + reviewForum.ForumName + "'";

            string generatedBody = "Entry: " + subject + " - A" + articleId + " \n";
            generatedBody += "Author: " + editorUsername + " - U" + editorId + " \n";
            generatedBody += "Submitter: " + submitterUsername + " - U" + submitterId + "\n\n";

            generatedBody += "This is an automated message.\n\n";

            generatedBody += "Your entry above has been submitted to the Review Forum '" + reviewForum.ForumName + "'"
                           + " by the Researcher named above. For more information about what happens next check out <./>ReviewForums-Next</.>.\n\n";

            generatedBody += "You can see the discussion about your entry at " + "F" + newThreadForumId.ToString() + "?thread=" + newThreadThreadId.ToString() + "\n\n";

            generatedBody += "If you'd rather your entry wasn't in this Review Forum then you can remove it by visiting "
                           + "<./>" + reviewForum.UrlFriendlyName + "</.> and clicking on the relevant 'Remove' link."
                           + " To prevent it being put into a Review Forum in the future, please click on the 'Edit Entry' button and tick the 'Not for Review' box.\n\n";


            bool forceModeration;
            CheckForProfanities(site, generatedBody, out forceModeration);           
            
            //TODO URL and Email filter


            // save the Post in the database
            ThreadPost post = new ThreadPost();
            post.InReplyTo = 0;
            post.ThreadId = 0;
            post.Subject = generatedSubject;
            post.Text = generatedBody;
            post.Style = PostStyle.Style.plaintext;

            post.CreateForumPost(readerCreator,
                submitterId,
                personalSpaceForumID, 
                false, 
                false, 
                "", 
                System.Guid.Empty, 
                false, 
                false, 
                false, 
                forceModeration,
                string.Empty,
                string.Empty);
        
        }
Ejemplo n.º 13
0
        public ThreadPost CreateThreadPost(string siteName, string forumId, string threadId, ThreadPost threadPost)
        {
            int forumIdAsInt;
            try
            {
                forumIdAsInt = Convert.ToInt32(forumId);
            }
            catch
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.ForumIDNotWellFormed));
            }
            int threadIdAsInt = 0;
            if (!Int32.TryParse(threadId, out threadIdAsInt))
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidThreadID));
            }


            // Check 1) get the site and check if it exists
            ISite site = GetSite(siteName);

            // Check 2) get the calling user             
            CallingUser callingUser = GetCallingUser(site);
            if (callingUser == null || callingUser.UserID == 0)
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.NotAuthorized));
            }

            bool requireSecurePost = siteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "EnforceSecurePosting") == 1;
            if (requireSecurePost && !callingUser.IsSecureRequest)
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.NotSecure));
            }

            // Check 3) check threadid is well formed
            
            ForumHelper helper = new ForumHelper(readerCreator);

            
            // save the Post in the database
            threadPost.ThreadId = threadIdAsInt;
            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, (Objects.User)callingUser, siteList, _iPAddress, bbcUidCookie, forumIdAsInt);
            }
            catch (ApiException e)
            {
                throw new DnaWebProtocolException(e);
            }

            return threadPost;
        }
Ejemplo n.º 14
0
        public ThreadPost CreateThreadPostHtml(string siteName, string forumId, string threadId, NameValueCollection formsData)
        {
            ThreadPost post = new ThreadPost();
            post.InReplyTo = Convert.ToInt32(formsData["inReplyTo"]);
            post.ThreadId = Convert.ToInt32(threadId);
            post.Subject = formsData["subject"];
            post.Text = formsData["text"];
            post.Style = (BBC.Dna.Objects.PostStyle.Style)Enum.Parse(typeof(BBC.Dna.Objects.PostStyle.Style), formsData["style"]);

            return CreateThreadPost(siteName, forumId, threadId, post);                                               
        }
Ejemplo n.º 15
0
 public void Hidden_SetValue_ReturnsCorrectGet()
 {
     ThreadPost target = new ThreadPost(); 
     byte expected = (byte)CommentStatus.Hidden.NotHidden;
     byte actual;
     target.Hidden = expected;
     actual = target.Hidden;
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 16
0
        public void PostToForum_PreModerateNewDiscussionsAsEditor_ReturnsUnModeratedPost()
        {
            var forumId = 1;
            var postId = 10;
            var threadId = 1;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            CreatePostToForumObjects(mocks, ref readerCreator, postId, threadId, false);
            var viewingUser = CreateUserObject(mocks, false, true, false);
            ISite site = CreateSiteObject(mocks, false, false);
            ISiteList siteList = CreateSiteList(mocks, 1, 0, 0, true);
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);

            mocks.ReplayAll();



            var threadPost = new ThreadPost()
            {
                Text = "contains referred term txt",
                Subject = "test subject",
                ThreadId = threadId,
            };

            ApiException e = null;
            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            }
            catch (ApiException err)
            {
                e = err;
            }
            Assert.IsNull(e);

            Assert.AreEqual(postId, threadPost.PostId);
            Assert.AreEqual(threadId, threadPost.ThreadId);

            var reader = readerCreator.CreateDnaDataReader("posttoforum");
            reader.AssertWasCalled(x => x.AddParameter("forcepremoderation", false));

        }
Ejemplo n.º 17
0
 public void ThreadIdSpecified_NothingSet_ReturnsFalse()
 {
     ThreadPost target = new ThreadPost(); 
     bool actual;
     actual = target.ThreadIdSpecified;
     Assert.AreEqual(false, actual);
 }
Ejemplo n.º 18
0
        public void PostToForum_WithinPostFreq_ThrowsException()
        {
            var forumId = 1;
            var threadId = 1;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);
            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            CreatePostFreq(mocks, ref readerCreator, 20);
            var viewingUser = CreateUserObject(mocks, false, false, false);
            ISite site = CreateSiteObject(mocks, false, false);
            ISiteList siteList = CreateSiteList(mocks, 1, 0, 0, false);

            mocks.ReplayAll();



            var threadPost = new ThreadPost()
            {
                Text = "contains text ",
                Subject = "test subject",
                ThreadId = threadId
            };



            ApiException e = null;
            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            }
            catch (ApiException err)
            {
                e = err;
            }
            Assert.AreEqual(ErrorType.PostFrequencyTimePeriodNotExpired, e.type);

        }
Ejemplo n.º 19
0
 public void PrevSiblingSpecified_NothingSet_ReturnsFalse()
 {
     ThreadPost target = new ThreadPost();
     Assert.IsFalse(target.PrevSiblingSpecified);
 }
Ejemplo n.º 20
0
        public void PostToForum_WithinPostFreqAsNotableUser_ThrowsException()
        {
            var forumId = 1;
            var threadId = 1;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();
            var postId = 10;

            MockRepository mocks = new MockRepository();
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);
            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            CreatePostFreq(mocks, ref readerCreator, 20);
            var viewingUser = CreateUserObject(mocks, false, false, false);
            viewingUser.Stub(x => x.IsNotable).Return(true);
            ISite site = CreateSiteObject(mocks, false, false);
            ISiteList siteList = CreateSiteList(mocks, 1, 0, 0, false);
            CreatePostToForumObjects(mocks, ref readerCreator, postId, threadId, false);

            mocks.ReplayAll();



            var threadPost = new ThreadPost()
            {
                Text = "contains text ",
                Subject = "test subject",
                ThreadId = threadId
            };



            ApiException e = null;
            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            }
            catch (ApiException err)
            {
                e = err;
            }
            Assert.IsNull(e);

            Assert.AreEqual(postId, threadPost.PostId);
            Assert.AreEqual(threadId, threadPost.ThreadId);

            var reader = readerCreator.CreateDnaDataReader("posttoforum");

        }
Ejemplo n.º 21
0
 public void NextIndexSpecified_NothingSet_ReturnsFalse()
 {
     ThreadPost target = new ThreadPost(); 
     Assert.IsFalse(target.NextIndexSpecified);
 }
Ejemplo n.º 22
0
 public void TextElement_RichText_ReturnsValidXml()
 {
     ThreadPost target = new ThreadPost();
     target.Style = PostStyle.Style.richtext;
     string expected = "This is the default comment.";
     XmlElement actual;
     target.Text = expected;
     actual = target.TextElement;
     Assert.AreEqual(expected, actual.InnerXml);
 }
Ejemplo n.º 23
0
 public void InReplyToSpecified_NothingSet_ReturnsFalse()
 {
     ThreadPost target = new ThreadPost(); 
     Assert.IsFalse(target.InReplyToSpecified);
 }
Ejemplo n.º 24
0
 public void TextElement_InvalidXml_ReturnsEscapedXml()
 {
     ThreadPost target = new ThreadPost();
     target.Style = PostStyle.Style.richtext;
     string expected = "This is the default &lt;notcomplete&gt; comment.";
     XmlElement actual;
     target.Text = "This is the default <notcomplete> comment.";
     actual = target.TextElement;
     Assert.AreEqual(expected, actual.InnerXml);
 }
Ejemplo n.º 25
0
 public void FirstChildSpecified_NothingSet_ReturnsFalse()
 {
     ThreadPost target = new ThreadPost(); 
     Assert.IsFalse(target.FirstChildSpecified);
 }
Ejemplo n.º 26
0
        public void TextElement_PlainTextWithNewLine_ReturnsValidXml()
        {
            ThreadPost target = new ThreadPost();
            target.Style = PostStyle.Style.plaintext;
            string expected = @"This is the <BR />default comment.";
            XmlElement actual;
            target.Text = ThreadPost.FormatPost(@"This is the 
default comment.", CommentStatus.Hidden.NotHidden, true, false);
            actual = target.TextElement;
            Assert.AreEqual(expected, actual.InnerXml);
        }
Ejemplo n.º 27
0
        public void PostToForum_CanWriteForumFalse_ThrowsException()
        {
            var forumId = 1;
            var threadId = 0;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);
            ISite site = mocks.DynamicMock<ISite>();
            IUser viewingUser = mocks.DynamicMock<IUser>();
            ISiteList siteList = mocks.DynamicMock<ISiteList>();
            viewingUser.Stub(x => x.UserId).Return(1);

            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, false);

            mocks.ReplayAll();
            //(ICacheManager cacheManager, IDnaDataReaderCreator readerCreator, ISite site, 
            //IUser viewingUser, ISiteList siteList, string _iPAddress, Guid bbcUidCookie, int forumId)

            var threadPost = new ThreadPost()
            {
                Text = "test post",
                Subject = "test subject",
                ThreadId = threadId
            };

            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            }
            catch (ApiException e)
            {
                Assert.AreEqual(ErrorType.ForumReadOnly, e.type);
            }

        }
Ejemplo n.º 28
0
 public void TextElement_RichTextWithTags_ReturnsWithWithoutTags()
 {
     ThreadPost target = new ThreadPost();
     target.Style = PostStyle.Style.richtext;
     string expected = @"This is the default comment.";
     XmlElement actual;
     target.Text = ThreadPost.FormatPost("This is the <B>default</B> comment.", CommentStatus.Hidden.NotHidden, true, false);
     actual = target.TextElement;
     Assert.AreEqual(expected, actual.InnerXml);
 }
Ejemplo n.º 29
0
        public void PostToForum_EmptyText_ThrowsException()
        {
            var forumId = 1;
            var threadId = 1;
            var ipAddress = "1.1.1.1";
            var bbcUid = Guid.NewGuid();

            MockRepository mocks = new MockRepository();
            ICacheManager cacheManager = CreateCacheObject(mocks, ForumSourceType.Article);
            ISiteList siteList = mocks.DynamicMock<ISiteList>();


            IDnaDataReaderCreator readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            CreateThreadPermissionObjects(mocks, ref readerCreator, true, true);
            CreateForumPermissionObjects(mocks, ref readerCreator, true, true);
            var viewingUser = CreateUserObject(mocks, false, false, false);
            ISite site = CreateSiteObject(mocks, false, false);

            mocks.ReplayAll();
            //(ICacheManager cacheManager, IDnaDataReaderCreator readerCreator, ISite site, 
            //IUser viewingUser, ISiteList siteList, string _iPAddress, Guid bbcUidCookie, int forumId)

            var threadPost = new ThreadPost()
            {
                Text = "",
                Subject = "test subject",
                ThreadId = threadId
            };

            ApiException e = null;
            try
            {
                threadPost.PostToForum(cacheManager, readerCreator, site, viewingUser, siteList, ipAddress, bbcUid, forumId);
            }
            catch (ApiException err)
            {
                e = err;
            }
            Assert.AreEqual(ErrorType.EmptyText, e.type);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates a threadpost from a given reader
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="prefix">The data base name prefix</param>
        /// <param name="postId">postId to get</param>
        /// <param name="post">The post in question to load with data</param>
        /// <param name="applySkin">Whether we need to process the text into html for output</param>
        /// <returns></returns>
        static public ThreadPost CreateThreadPostFromReader(IDnaDataReader reader, 
                                                            string prefix, 
                                                            int postId, 
                                                            ThreadPost post, 
                                                            bool applySkin)
        {
            if (post == null)
            {
                post = new ThreadPost() { PostId = postId };
            }
            
            if (reader.DoesFieldExist(prefix +"threadid"))
            {
                post.ThreadId = reader.GetInt32NullAsZero(prefix +"threadid");
            }
            if (reader.DoesFieldExist(prefix +"parent"))
            {
                post.InReplyTo = reader.GetInt32NullAsZero(prefix +"parent");
            }

            if (reader.DoesFieldExist(prefix +"replypostindex"))
            {
                post.InReplyToIndex = reader.GetInt32NullAsZero(prefix + "replypostindex");
            }

            if (reader.DoesFieldExist(prefix +"postindex"))
            {
                post.Index = reader.GetInt32NullAsZero(prefix + "postindex");
            }
            
            if (reader.DoesFieldExist(prefix +"prevSibling"))
            {
                post.PrevSibling = reader.GetInt32NullAsZero(prefix +"prevSibling");
            }
            if (reader.DoesFieldExist(prefix +"nextSibling"))
            {
                post.NextSibling = reader.GetInt32NullAsZero(prefix +"nextSibling");
            }
            if (reader.DoesFieldExist(prefix +"firstChild"))
            {
                post.FirstChild = reader.GetInt32NullAsZero(prefix +"firstChild");
            }
            if (reader.DoesFieldExist(prefix +"hidden"))
            {
                post.Hidden = (byte)reader.GetInt32NullAsZero(prefix +"hidden");
            }
            if (reader.DoesFieldExist(prefix +"subject"))
            {
                post.Subject = FormatSubject(reader.GetStringNullAsEmpty("subject"), (CommentStatus.Hidden)post.Hidden);
            }
            if (reader.DoesFieldExist(prefix + "datePosted") && reader[prefix + "datePosted"] != DBNull.Value)
            {
                post.DatePosted = new DateElement(reader.GetDateTime(prefix + "datePosted".ToString()));
            }
            if (reader.DoesFieldExist(prefix +"postStyle"))
            {
                post.Style =  (PostStyle.Style)reader.GetByteNullAsZero(prefix + "postStyle");
            }
            if (reader.DoesFieldExist(prefix +"text"))
            {
                post.Text = ThreadPost.FormatPost(reader.GetStringNullAsEmpty(prefix + "text"), (CommentStatus.Hidden)post.Hidden, true, applySkin);
            }
            if (reader.DoesFieldExist(prefix +"hostpageurl"))
            {
                post.HostPageUrl = reader.GetStringNullAsEmpty(prefix + "hostpageurl");
            }
            if (reader.DoesFieldExist(prefix +"commentforumtitle"))
            {
                post.CommentForumTitle = reader.GetStringNullAsEmpty(prefix + "commentforumtitle");
            }

            post.User = BBC.Dna.Objects.User.CreateUserFromReader(reader);

            #region Depreciated code
            /*
             * This code has been depreciated from forum.cpp ln 1066 as the functionality is no longer in use.
             // Add the event date if it has one!
		        bOk = bOk && AddDBXMLDateTag("eventdate",NULL,false,true);

		        // Get the Type of post we're looking at
		        bOk = bOk && AddDBXMLTag("type",NULL,false,true,&sPostType);

		        // Now see if we are an event or notice, if so put the taginfo in for the post
		        if (sPostType.CompareText("Notice") || sPostType.CompareText("Event"))
		        {
			        // We've got a notice or event! Get all the tag info
			        CTagItem TagItem(m_InputContext);
			        if (TagItem.InitialiseFromThreadId(ThreadID,m_SiteID,pViewer) && TagItem.GetAllNodesTaggedForItem())
			        {
				        TagItem.GetAsString(sPosts);
			        }
		        }
             */
            
            #endregion

            return post;
        }