Exemple #1
0
        public void CreateEditorsPick()
        {
            //First get a comment.
            CommentsTests_V1 comments = new CommentsTests_V1();
            CommentForumTests_V1 commentForums = new CommentForumTests_V1();

            _commentInfo = comments.CreateCommentHelper(commentForums.CommentForumCreateHelper().Id);

            Assert.IsNotNull(_commentInfo, "Unable to Create Comment");
            
            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserEditor();

             // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/{1}/editorpicks/", _sitename,_commentInfo.ID);
            
            request.RequestPageWithFullURL(url, "No data to send", "text/xml");

            //Check for Editors Pick presence.
            url = String.Format("http://" + _server + "/dna/api/comments/CommentsService.svc/V1/site/{0}/comments/?filterBy=EditorPicks", _sitename);
            request.RequestPageWithFullURL(url);

            XmlDocument xml = request.GetLastResponseAsXML();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("api", "BBC.Dna.Api");
            
            String xPath = String.Format("api:commentsList/api:comments/api:comment[api:id='{0}']", _commentInfo.ID);
            XmlNode pick = xml.SelectSingleNode(xPath, nsmgr);
            Assert.IsNotNull(pick);
        }
        public void CommentForum_BasicAddCommentWithStatsCheck()
		{
            CommentForum commentForum = new CommentForum
            {
                Id = Guid.NewGuid().ToString(),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };

            CommentForum result = CreateForum(commentForum);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.commentSummary.Total == 0);

            //add a comment 
            CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() };

            CreateComment(comment, result);

            //get forum again
            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.commentSummary.Total == 1);

            XmlDocument xStats = GetAllStatCounter();
            Assert.IsTrue(GetStatCounter(xStats, "RAWREQUESTS") == 3);
            
            //get forum again
            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.commentSummary.Total == 1);
            xStats = GetAllStatCounter();
            Assert.IsTrue(GetStatCounter(xStats, "RAWREQUESTS") == 4);

		}
 public static CommentForum CreateCommentforumToPost(bool allowAnonymousPosting, string title, string id, string text, string parentUri, string userName)
 {
     CommentForum postDataForum = new CommentForum();
     postDataForum.ParentUri = parentUri;
     postDataForum.Title = title;
     postDataForum.Id = id;
     postDataForum.allowNotSignedInCommenting = allowAnonymousPosting;
     postDataForum.commentList = new CommentsList();
     postDataForum.commentList.comments = new List<CommentInfo>();
     CommentInfo testCommentInfo = new CommentInfo();
     testCommentInfo.text = text;
     testCommentInfo.User.DisplayName = userName;
     postDataForum.commentList.comments.Add(testCommentInfo);
     return postDataForum;
 }
        public void CreateTestForumAndComment(ref CommentForum commentForum, ref CommentInfo returnedComment)
        {
            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserNormal();
            //create the forum
            if(string.IsNullOrEmpty(commentForum.Id))
            {
                commentForum = commentsHelper.CommentForumCreate("tests", Guid.NewGuid().ToString());
            }

            string text = "Functiontest Title" + Guid.NewGuid().ToString();
            string commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" +
                "<text>{0}</text>" +
                "</comment>", text);

            // Setup the request url
            string url = String.Format("https://" + _secureserver + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/", _sitename, commentForum.Id);
            // now get the response
            request.RequestPageWithFullURL(url, commentForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaCommentForum);
            validator.Validate();

            //check the TextAsHtml element
            //string textAsHtml = xml.DocumentElement.ChildNodes[2].InnerXml;
            //Assert.IsTrue(textAsHtml == "<div class=\"dna-comment text\" xmlns=\"\">" + text + "</div>");

            returnedComment = (CommentInfo)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentInfo));
            Assert.IsTrue(returnedComment.text == text);
            Assert.IsNotNull(returnedComment.User);
            Assert.IsTrue(returnedComment.User.UserId == request.CurrentUserID);

            DateTime created = DateTime.Parse(returnedComment.Created.At);
            DateTime createdTest = BBC.Dna.Utils.TimeZoneInfo.GetTimeZoneInfo().ConvertUtcToTimeZone(DateTime.Now.AddMinutes(5));
            Assert.IsTrue(created < createdTest);//should be less than 5mins
            Assert.IsTrue(!String.IsNullOrEmpty(returnedComment.Created.Ago));
        }
Exemple #5
0
        private CommentInfo AddToCommentRepository(string commentForumUid, int conversationId, CommentInfo comment)
        {
            using (var reader = CreateReader("dna.AddComment"))
            {
                reader.AddParameter("bbcIdentityUserId", CallingUser.IdentityUserID);
                reader.AddParameter("commentForumId", commentForumUid);
                reader.AddParameter("commentText", comment.text);
                reader.AddParameter("trusetedSource", CallingUser.IsTrustedUser());
                reader.AddParameter("threadId", conversationId);
                reader.AddParameter("trustedSource", CallingUser.IsTrustedUser());
                reader.Execute();

                if(reader.HasRows && reader.Read())
                {
                    //fill in comment
                }
            }
            return comment;         
        }
Exemple #6
0
 private int AddCommentToPreModerationQueue(string commentForumUid, int conversationId, CommentInfo comment, int modId)
 {
     using (var reader = CreateReader("dna.AddCommentToPreModerationQueue"))
     {
         reader.AddParameter("commentForumId", commentForumUid);
         reader.AddParameter("bbcIdentityUserId", CallingUser.IdentityUserID);
         reader.AddParameter("userName", CallingUser.UserName);
         reader.AddParameter("text", comment.text);
         reader.AddParameter("hash", GenerateHash(comment.text, commentForumUid, CallingUser.IdentityUserID));
         reader.AddParameter("threadId", conversationId);
         reader.AddParameter("subject", comment.Title);
         reader.Execute();
         if (reader.HasRows && reader.Read())
         {
             modId = reader.GetInt32NullAsZero("ModerationQueueId");
         }
     }
     return modId;
 }
Exemple #7
0
        public void CommentListReadBySiteNameAndPrefix()
        {
            string prefix = "prefixtestsbycomments" + Guid.NewGuid().ToString();
            CommentForum commentForum = new CommentForum
            {
                Id = prefix + "_" + Guid.NewGuid().ToString(),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };
            

            //create the forum
            CommentForum result = _comments.CreateCommentForum(commentForum, site);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            //create the comment
            //set up test data
            for (int i = 0; i < 10; i++)
            {
                CommentInfo comment = new CommentInfo
                {
                    text = "this is a nunit generated comment."
                };
                comment.text += Guid.NewGuid().ToString();//have to randomize the string to post
                string IPAddress = String.Empty;
                Guid BBCUid = Guid.NewGuid();
                //normal user
                _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
                _comments.CallingUser.CreateUserFromDnaUserID(TestUtils.TestUserAccounts.GetNormalUserAccount.UserID, site.SiteID);
                CommentInfo commentInfo = _comments.CreateComment(result, comment);
                Assert.IsTrue(commentInfo != null);
                Assert.IsTrue(commentInfo.ID > 0);
                Assert.IsTrue(commentInfo.text == comment.text);
            }


            //test good site
            CommentsList resultList = _comments.GetCommentsListBySite(site, prefix);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.TotalCount == 10);
            //test paging
            _comments.ItemsPerPage = 3;
            _comments.StartIndex = 5;
            resultList = _comments.GetCommentsListBySite(site, prefix);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.TotalCount == 10);
            Assert.IsTrue(resultList.ItemsPerPage == _comments.ItemsPerPage);
            Assert.IsTrue(resultList.StartIndex == _comments.StartIndex);

        }
Exemple #8
0
        public Stream CreateRatingThreadComment(string ratingForumID, string threadID, string siteName, CommentInfo comment)
        {
            int id = 0;
            if (!Int32.TryParse(threadID, out id))
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidThreadID));
            }
            CommentInfo ratingThreadCommentInfo = null;
            try
            {
                ISite site = GetSite(siteName);
                RatingForum ratingForumData = null;
                ratingForumData = _ratingObj.RatingForumReadByUID(ratingForumID, site);
                _ratingObj.CallingUser = GetCallingUser(site);
                ratingThreadCommentInfo = _ratingObj.RatingCommentCreate(ratingForumData, id, comment);

            }
            catch (ApiException ex)
            {
                throw new DnaWebProtocolException(ex);
            }
            return GetOutputStream(ratingThreadCommentInfo);

        }
Exemple #9
0
 private CommentInfo SetupComment()
 {
     //create the comment
     CommentInfo comment = new CommentInfo
     {
         text = "this is a nunit generated comment."
     };
     comment.text += Guid.NewGuid().ToString();//have to randomize the string to post
     string IPAddress = String.Empty;
     Guid BBCUid = Guid.NewGuid();
     //normal user
     _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
     _comments.CallingUser.CreateUserFromDnaUserID(TestUtils.TestUserAccounts.GetNormalUserAccount.UserID, site.SiteID);
     return comment;
 }
        private CommentInfo CreateComment(CommentInfo info, CommentForum forum)
        {
            string commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" +
                "<text>{0}</text>" +
                "</comment>", info.text);

            DnaTestURLRequest request = new DnaTestURLRequest(_sitename);
            request.SetCurrentUserNormal();

            // Setup the request url
            string url = String.Format("https://" + _secureserver + "/dna/api/comments/CommentsService.svc/V1/site/{0}/commentsforums/{1}/", _sitename, forum.Id);
            // now get the response
            request.RequestPageWithFullURL(url, commentForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            CommentInfo returnedComment = (CommentInfo)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(CommentInfo));
            Assert.IsNotNull(returnedComment.User);
            Assert.IsTrue(returnedComment.User.UserId == request.CurrentUserID);

            return returnedComment;
        }
Exemple #11
0
        /// <summary>
        /// Creates a comment for the given comment forum id
        /// </summary>
        /// <param name="commentForum"></param>
        /// <param name="comment">The comment to add</param>
        /// <returns>The created comment object</returns>
        public CommentInfo CreateComment(Forum commentForum, CommentInfo comment)
        {
            ISite site = SiteList.GetSite(commentForum.SiteName);
            bool ignoreModeration;
            bool forceModeration;
            var notes = string.Empty;
            string profanityxml = string.Empty;
            
            List<Term> terms = null;

            ValidateComment(commentForum, comment, site, out ignoreModeration, out forceModeration, out notes, out terms);

            if (terms != null && terms.Count > 0)
            {
                profanityxml = new Term().GetProfanityXML(terms);
            }

            //create unique comment hash
            Guid guid = DnaHasher.GenerateCommentHashValue(comment.text, commentForum.Id, CallingUser.UserID);
            //add comment to db
            try
            {
                using (IDnaDataReader reader = CreateReader("commentcreate"))
                {
                    reader.AddParameter("commentforumid", commentForum.Id);
                    reader.AddParameter("userid", CallingUser.UserID);
                    if (commentForum.isContactForm)
                    {
                        reader.AddParameter("content", CONTACT_POST_TEXT);
                    }
                    else
                    {
                        reader.AddParameter("content", comment.text);
                    }
                    reader.AddParameter("hash", guid);
                    reader.AddParameter("forcemoderation", forceModeration);
                    //reader.AddParameter("forcepremoderation", (commentForum.ModerationServiceGroup == ModerationStatus.ForumStatus.PreMod?1:0));
                    reader.AddParameter("ignoremoderation", ignoreModeration);
                    reader.AddParameter("isnotable", CallingUser.IsUserA(UserTypes.Notable));
                    reader.AddParameter("applyprocesspremodexpirytime", comment.ApplyProcessPremodExpiryTime);

                    if (CallingUser.UserID != commentForum.NotSignedInUserId)
                    {//dont include as this is data protection
                        reader.AddParameter("ipaddress", IpAddress);
                        reader.AddParameter("bbcuid", BbcUid);
                    }

                    if (CallingUser.UserID == commentForum.NotSignedInUserId && comment.User != null && !String.IsNullOrEmpty(comment.User.DisplayName))
                    {//add display name for not signed in comment
                        reader.AddParameter("nickname", comment.User.DisplayName);
                    }
                    reader.AddIntReturnValue();
                    reader.AddParameter("poststyle", (int) comment.PostStyle);
                    if (!String.IsNullOrEmpty(notes))
                    {
                        reader.AddParameter("modnotes", notes);
                    }

                    if (false == string.IsNullOrEmpty(profanityxml))
                    {
                        reader.AddParameter("profanityxml", profanityxml);
                    }

                    reader.Execute();

                    if (reader.HasRows && reader.Read())
                    {
//all good - create comment
                        comment.PreModPostingsModId = reader.GetInt32NullAsZero("PreModPostingModId");
                        comment.IsPreModerated = (reader.GetInt32NullAsZero("IsPreModerated") == 1);
                        comment.hidden = (comment.IsPreModerated
                                              ? CommentStatus.Hidden.Hidden_AwaitingPreModeration
                                              : CommentStatus.Hidden.NotHidden);
                        comment.text = CommentInfo.FormatComment(comment.text, comment.PostStyle, comment.hidden, CallingUser.IsUserA(UserTypes.Editor));
                        var displayName = CallingUser.UserName;
                        if (CallingUser.UserID == commentForum.NotSignedInUserId && comment.User != null && !String.IsNullOrEmpty(comment.User.DisplayName))
                        {//add display name for not signed in comment
                            displayName = comment.User.DisplayName;
                        }
                        comment.User = UserReadByCallingUser(site);
                        comment.User.DisplayName = displayName;
                        comment.Created = new DateTimeHelper(DateTime.Now);

                        if (reader.GetInt32NullAsZero("postid") != 0)
                        {
// no id as it is may be pre moderated
                            comment.ID = reader.GetInt32NullAsZero("postid");
                            var replacement = new Dictionary<string, string>();
                            replacement.Add("sitename", site.SiteName);
                            replacement.Add("postid", comment.ID.ToString());
                            comment.ComplaintUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                            SiteList.GetSiteOptionValueString(site.SiteID, "General", "ComplaintUrl")
                                                                                            , replacement);

                            replacement = new Dictionary<string, string>();
                            replacement.Add("commentforumid", commentForum.Id);
                            replacement.Add("sitename", site.SiteName);

                            UriDiscoverability.UriType uriType = UriDiscoverability.UriType.CommentForumById;
                            if (commentForum.isContactForm)
                            {
                                uriType = UriDiscoverability.UriType.ContactFormById;

                                // We now need to store the comment in the encrypted thread entries table.
                                using (IDnaDataReader contactDataReader = CreateReader("addencryptedcontactdetails"))
                                {
                                    contactDataReader.AddParameter("postid", comment.ID);
                                    contactDataReader.AddParameter("text", comment.text);
                                    contactDataReader.Execute();
                                }
                            }

                            comment.ForumUri = UriDiscoverability.GetUriWithReplacments(BasePath, uriType, replacement);
                        }
                        else
                        {
                            comment.ID = 0;
                        }
                    }
                    else
                    {
                        int returnValue;
                        reader.TryGetIntReturnValue(out returnValue);
                        ParseCreateCommentSpError(returnValue);
                    }
                }
            }
            catch (ApiException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ApiException(ex.Message, ex.InnerException);
            }
            //return new comment complete with id etc
            return comment;
        }
        public void CommentForum_ComplaintHideComment()
        {
            CommentForum commentForum = new CommentForum
            {
                Id = Guid.NewGuid().ToString(),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };

            CommentForum result = CreateForum(commentForum);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            Assert.IsTrue(result.commentSummary.Total == 0);

            //add a comment 
            CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() };

            

            CreateComment(comment, result);

            //get forum again
            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            Assert.IsTrue(result.commentSummary.Total == 1);

            // Now ste the closing date of the forum to something in the past.
            using (FullInputContext _context = new FullInputContext(true))
            {

                using (IDnaDataReader dataReader = _context.CreateDnaDataReader("hidepost"))
                {
                    dataReader.AddParameter("postid", result.commentList.comments[0].ID);
                    dataReader.AddParameter("hiddenid", 6);
                    dataReader.Execute();
                }
          
            }
            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.commentList.comments[0].text == "This post has been removed.", "Comment not hidden!");
            Assert.IsTrue(result.commentList.comments[0].hidden == CommentStatus.Hidden.Removed_EditorComplaintTakedown);



        }
        public void CommentForum_PreMod_PassWithEdit()
        {
            CommentForum commentForum = new CommentForum
            {
                Id = Guid.NewGuid().ToString(),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum",
                ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod
            };

            CommentForum result = CreateForum(commentForum);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            Assert.IsTrue(result.commentSummary.Total == 0);

            //add a comment 
            CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() };

            

            CreateComment(comment, result);

            //get forum again
            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.commentList.comments[0].hidden == CommentStatus.Hidden.Hidden_AwaitingPreModeration);
            Assert.IsTrue(result.commentList.comments[0].text == "This post is awaiting moderation.", "Comment not hidden!");
            Assert.IsTrue(result.commentSummary.Total == 1);


            string newText = " this is editted text";
            // Now ste the closing date of the forum to something in the past.
            ModerateComment(result.commentList.comments[0].ID, result.ForumID, BBC.Dna.Component.ModeratePosts.Status.PassedWithEdit, newText);

            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.commentList.comments[0].text == newText);
        }
        public void CommentForum_ChangeCanWriteFlag()
        {
            CommentForum commentForum = new CommentForum
            {
                Id = Guid.NewGuid().ToString(),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };

            CommentForum result = CreateForum(commentForum);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            Assert.IsTrue(result.commentSummary.Total == 0);

            //add a comment 
            CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() };



            CreateComment(comment, result);

            //get forum again
            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            Assert.IsTrue(result.commentSummary.Total == 1);
            Assert.IsFalse(result.isClosed);

            // Now ste the closing date of the forum to something in the past.
            using (FullInputContext _context = new FullInputContext(true))
            {
                using (IDnaDataReader dataReader = _context.CreateDnaDataReader("updatecommentforumstatus"))
                {
                    dataReader.AddParameter("uid", result.Id);
                    dataReader.AddParameter("canwrite", 0);
                    dataReader.Execute();
                }
            }
            result = ReadForum(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.isClosed);

            //try and read it again as json - to check the isclosed forum flag is honoured.
            result = ReadForumJson(result.Id);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.isClosed);
            


        }
        public void CommentsBySite_BasicAddCommentWithStatsCheck()
        {
            CommentForum commentForum = new CommentForum
            {
                Id = Guid.NewGuid().ToString(),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };

            CommentForum result = CreateForum(commentForum);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            Assert.IsTrue(result.commentSummary.Total == 0);

            //get total for this site
            CommentsList list = ReadCommentsReadBySite("");
            Assert.IsTrue(list.TotalCount != 0);

            CommentsList listPrefix = ReadCommentsReadBySite(commentForum.Id.Substring(0, 4));
            Assert.IsTrue(listPrefix.TotalCount == 0);

            //add a comment 
            CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() };
            CreateComment(comment, result);

            //get total for this site
            CommentsList listAfter = ReadCommentsReadBySite("");
            Assert.IsTrue(listAfter.TotalCount == list.TotalCount+1);

            XmlDocument xStats = GetAllStatCounter();
            Assert.IsTrue(GetStatCounter(xStats, "RAWREQUESTS") == 5);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEHITS") == 0);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEMISSES") == 3);

            CommentsList listPrefixAfter = ReadCommentsReadBySite(commentForum.Id.Substring(0, 4));
            Assert.IsTrue(listPrefixAfter.TotalCount == 1);
            xStats = GetAllStatCounter();
            Assert.IsTrue(GetStatCounter(xStats, "RAWREQUESTS") == 6);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEHITS") == 0);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEMISSES") == 4);

            //reget totals
            listAfter = ReadCommentsReadBySite("");
            Assert.IsTrue(listAfter.TotalCount == list.TotalCount + 1);
            xStats = GetAllStatCounter();
            Assert.IsTrue(GetStatCounter(xStats, "RAWREQUESTS") == 7);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEHITS") == 1);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEMISSES") == 4);

            listPrefixAfter = ReadCommentsReadBySite(commentForum.Id.Substring(0, 4));
            Assert.IsTrue(listPrefixAfter.TotalCount == 1);
            xStats = GetAllStatCounter();
            Assert.IsTrue(GetStatCounter(xStats, "RAWREQUESTS") == 8);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEHITS") == 2);
            Assert.IsTrue(GetStatCounter(xStats, "HTMLCACHEMISSES") == 4);

        }
Exemple #16
0
 public Stream CreateRatingThreadCommentHtml(string ratingForumID, string threadid, string siteName, NameValueCollection formsData)
 {
     CommentInfo ratingThreadCommentInfo = null;
     try
     {
         ratingThreadCommentInfo = new CommentInfo { text = formsData["text"] };
         if (!String.IsNullOrEmpty(formsData["PostStyle"]))
         {
             try
             {
                 ratingThreadCommentInfo.PostStyle =
                     (PostStyle.Style)Enum.Parse(typeof(PostStyle.Style), formsData["PostStyle"], true);
             }
             catch
             {
                 throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidPostStyle));
             }
         }
     }
     catch (ApiException ex)
     {
         throw new DnaWebProtocolException(ex);
     }
     return CreateRatingThreadComment(ratingForumID, threadid, siteName, ratingThreadCommentInfo);
 }
Exemple #17
0
        /// <summary>
        /// Creates a commentinfo object
        /// </summary>
        /// <param name="reader">A reader with all information</param>
        /// <param name="site">site information</param>
        /// <returns>Comment info object</returns>
        private CommentInfo CommentCreateFromReader(IDnaDataReader reader, ISite site)
        {
            var commentInfo = new CommentInfo
                                  {
                                      Created =
                                          new DateTimeHelper(DateTime.Parse(reader.GetDateTime("Created").ToString())),
                                      User = UserReadById(reader, site),
                                      ID = reader.GetInt32NullAsZero("id")
                                  };

            commentInfo.hidden = (CommentStatus.Hidden) reader.GetInt32NullAsZero("hidden");
            if (reader.IsDBNull("poststyle"))
            {
                commentInfo.PostStyle = PostStyle.Style.richtext;
            }
            else
            {
                commentInfo.PostStyle = (PostStyle.Style) reader.GetTinyIntAsInt("poststyle");
            }

            commentInfo.IsEditorPick = reader.GetBoolean("IsEditorPick");
            commentInfo.Index = reader.GetInt32NullAsZero("PostIndex");

            //get complainant
            var replacement = new Dictionary<string, string>();
            replacement.Add("sitename", site.SiteName);
            replacement.Add("postid", commentInfo.ID.ToString());
            commentInfo.ComplaintUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                SiteList.GetSiteOptionValueString(site.SiteID, "General", "ComplaintUrl"),
                                                                                replacement);

            replacement = new Dictionary<string, string>();
            replacement.Add("commentforumid", reader.GetString("forumuid"));
            replacement.Add("sitename", site.SiteName);
            commentInfo.ForumUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.CommentForumById,
                                                                            replacement);

            replacement = new Dictionary<string, string>();
            replacement.Add("parentUri", reader.GetString("parentUri"));
            replacement.Add("postid", commentInfo.ID.ToString());
            commentInfo.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.Comment,
                                                                       replacement);

            if(reader.DoesFieldExist("nerovalue"))
            {
                commentInfo.NeroRatingValue = reader.GetInt32NullAsZero("nerovalue");
            }

            if (reader.DoesFieldExist("neropositivevalue"))
            {
                commentInfo.NeroPositiveRatingValue = reader.GetInt32NullAsZero("neropositivevalue");
            }

            if (reader.DoesFieldExist("neronegativevalue"))
            {
                commentInfo.NeroNegativeRatingValue = reader.GetInt32NullAsZero("neronegativevalue");
            }
            
            if (reader.DoesFieldExist("tweetid"))
            {
                commentInfo.TweetId = reader.GetLongNullAsZero("tweetid");
            }

            commentInfo.text = CommentInfo.FormatComment(reader.GetStringNullAsEmpty("text"), commentInfo.PostStyle, commentInfo.hidden, commentInfo.User.Editor);

            if (reader.DoesFieldExist("twitterscreenname"))
            {
                commentInfo.TwitterScreenName = reader.GetStringNullAsEmpty("twitterscreenname");
            }

            if (reader.DoesFieldExist("retweetid"))
            {
                commentInfo.RetweetId = reader.GetLongNullAsZero("retweetid");
            }

            if (reader.DoesFieldExist("retweetedby"))
            {
                commentInfo.RetweetedBy = reader.GetStringNullAsEmpty("retweetedby");
            }

            if (reader.DoesFieldExist("DmID"))
            {
                if (reader.IsDBNull("DmID") == false)
                {
                    commentInfo.DistressMessage = IncludeDistressMessage(reader, site);
                }
            }

            return commentInfo;
        }
Exemple #18
0
 public Stream CreateComment(string commentForumId, string siteName, CommentInfo comment)
 {
     ISite site = GetSite(siteName);
     if (site == null)
     {
         throw ApiException.GetError(ErrorType.UnknownSite);
     }
     CommentInfo commentInfo;
     try
     {
         CommentForum commentForumData = _commentObj.GetCommentForumByUid(commentForumId, site, true);
         _commentObj.CallingUser = GetCallingUser(site);
         if (commentForumData == null)
         {
             throw ApiException.GetError(ErrorType.ForumUnknown);
         }
         commentInfo = _commentObj.CreateComment(commentForumData, comment);
     }
     catch (ApiException ex)
     {
         throw new DnaWebProtocolException(ex);
     }
     return GetOutputStream(commentInfo);
 }
Exemple #19
0
        private CommentInfo IncludeDistressMessage(IDnaDataReader reader, ISite site)
        {
            var commentInfo = new CommentInfo();

            commentInfo.Created = new DateTimeHelper(DateTime.Parse(reader.GetDateTime("DmCreated").ToString()));
            commentInfo.ID = reader.GetInt32NullAsZero("DmId");
            commentInfo.User = DmUserFromReader(reader, site);

            commentInfo.hidden = (CommentStatus.Hidden)reader.GetInt32NullAsZero("DmHidden");
            if (reader.IsDBNull("DmPostStyle"))
            {
                commentInfo.PostStyle = PostStyle.Style.richtext;
            }
            else
            {
                commentInfo.PostStyle = (PostStyle.Style)reader.GetTinyIntAsInt("DmPostStyle");
            }
            commentInfo.Index = reader.GetInt32NullAsZero("DmPostIndex");

            commentInfo.text = CommentInfo.FormatComment(reader.GetStringNullAsEmpty("DmText"), 
                commentInfo.PostStyle, 
                commentInfo.hidden, 
                commentInfo.User.Editor);

            var replacement = new Dictionary<string, string>();
            replacement.Add("commentforumid", reader.GetString("forumuid"));
            replacement.Add("sitename", site.SiteName);
            commentInfo.ForumUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.CommentForumById,
                                                                            replacement);
            replacement = new Dictionary<string, string>();
            replacement.Add("parentUri", reader.GetString("parentUri"));
            replacement.Add("postid", commentInfo.ID.ToString());
            commentInfo.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.Comment,
                                                                       replacement);

            return commentInfo;
        }
Exemple #20
0
        public void CreateCommentHtml(string commentForumId, string siteName, NameValueCollection formsData)
        {
            ErrorType error;
            DnaWebProtocolException dnaWebProtocolException = null;
            CommentInfo commentInfo;
            try
            {
                commentInfo = new CommentInfo {text = formsData["text"]};
                if (!String.IsNullOrEmpty(formsData["PostStyle"]))
                {
                    try
                    {
                        commentInfo.PostStyle =
                            (PostStyle.Style) Enum.Parse(typeof (PostStyle.Style), formsData["PostStyle"]);
                    }
                    catch
                    {
                        throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidPostStyle));
                    }
                }
                CreateComment(commentForumId, siteName, commentInfo);
                error = ErrorType.Ok;
            }
            catch (DnaWebProtocolException ex)
            {
                error = ex.ErrorType;

                dnaWebProtocolException = ex;
            }


            string ptrt = WebFormat.GetPtrtWithResponse(error.ToString());
            if (String.IsNullOrEmpty(ptrt))
            {
//none returned...
                if (error == ErrorType.Ok)
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Created;
                    return;
                }
                else
                {
                    throw dnaWebProtocolException;
                }
            }
            //do response redirect...
            WebOperationContext.Current.OutgoingResponse.Location = ptrt;
            WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.MovedPermanently;
        }
Exemple #21
0
        /// <summary>
        /// Completes all checks on the data before creating it
        /// </summary>
        /// <param name="commentForum"></param>
        /// <param name="comment"></param>
        /// <param name="site"></param>
        /// <param name="ignoreModeration"></param>
        /// <param name="forceModeration"></param>
        public void ValidateComment(Forum commentForum, CommentInfo comment, ISite site, 
            out bool ignoreModeration, out bool forceModeration, out string notes, out List<Term> terms)
        {
            if (CallingUser == null || CallingUser.UserID == 0)
            {
                throw ApiException.GetError(ErrorType.MissingUserCredentials);
            }

            //check if the posting is secure
            try
            {
                int requireSecurePost = SiteList.GetSiteOptionValueInt(site.SiteID, "CommentForum",
                                                                  "EnforceSecurePosting");
                if (!CallingUser.IsSecureRequest && requireSecurePost == 1)
                {
                    throw ApiException.GetError(ErrorType.NotSecure);
                }
            }
            catch (SiteOptionNotFoundException e)
            {
                DnaDiagnostics.WriteExceptionToLog(e);
            }

            ignoreModeration = CallingUser.IsUserA(UserTypes.Editor) || CallingUser.IsUserA(UserTypes.SuperUser);
            if (CallingUser.IsUserA(UserTypes.BannedUser))
            {
                throw ApiException.GetError(ErrorType.UserIsBanned);
            }

            //check if site is open
            if (!ignoreModeration && (site.IsEmergencyClosed || site.IsSiteScheduledClosed(DateTime.Now)))
            {
                throw ApiException.GetError(ErrorType.SiteIsClosed);
            }
            // reject comments that do not have any text
            if (String.IsNullOrEmpty(comment.text))
            {
                throw ApiException.GetError(ErrorType.EmptyText);
            }
            try
            {
//check for option - if not set then it throws exception
                int maxCharCount = SiteList.GetSiteOptionValueInt(site.SiteID, "CommentForum",
                                                                  "MaxCommentCharacterLength");
                string tmpText = StringUtils.StripFormattingFromText(comment.text);
                if (maxCharCount != 0 && tmpText.Length > maxCharCount)
                {
                    throw ApiException.GetError(ErrorType.ExceededTextLimit);
                }
            }
            catch (SiteOptionNotFoundException)
            {
            }

            try
            {
//check for option - if not set then it throws exception
                int minCharCount = SiteList.GetSiteOptionValueInt(site.SiteID, "CommentForum",
                                                                  "MinCommentCharacterLength");
                string tmpText = StringUtils.StripFormattingFromText(comment.text);
                if (minCharCount != 0 && tmpText.Length < minCharCount)
                {
                    throw ApiException.GetError(ErrorType.MinCharLimitNotReached);
                }
            }
            catch (SiteOptionNotFoundException)
            {
            }

            //strip out invalid chars
            comment.text = StringUtils.StripInvalidXmlChars(comment.text);

            // Check to see if we're doing richtext and check if its valid xml
            if (comment.PostStyle == PostStyle.Style.unknown)
            {
//default to plain text...
                comment.PostStyle = PostStyle.Style.richtext;
            }
            if (comment.PostStyle == PostStyle.Style.richtext)
            {
                string errormessage = string.Empty;
                // Check to make sure that the comment is made of valid XML
                if (!HtmlUtils.ParseToValidGuideML(comment.text, ref errormessage))
                {
                    DnaDiagnostics.WriteWarningToLog("Comment box post failed xml parse.", errormessage);
                    throw ApiException.GetError(ErrorType.XmlFailedParse);
                }
            }

            if (commentForum.isContactForm)
            {
                //We don't want to do any terms filtering on contact forms.
                ignoreModeration = true;
                forceModeration = false;
                notes = string.Empty;
                terms = null;
            }
            else
            {
                //run against profanity filter
                notes = string.Empty;

                CheckForProfanities(site, comment.text, out forceModeration, out notes, out terms, commentForum.ForumID);
                forceModeration = forceModeration ||
                                  (commentForum.ModerationServiceGroup > ModerationStatus.ForumStatus.Reactive);
                //force moderation if anything greater than reactive
            }
        }
Exemple #22
0
        private void CreateCommentForum(ICallingUser user, out CommentForum commentForum, out CommentInfo comment, out CommentInfo result)
        {
            string commentForumID = "good" + Guid.NewGuid().ToString();
            commentForum = CommentForumCreate(commentForumID);

            //set up test data
            comment = new CommentInfo { text = Guid.NewGuid().ToString().Substring(0, 10) };

            // Add the user
            _comments.CallingUser = user;

            result = _comments.CreateComment(commentForum, comment);//should pass successfully
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.ID > 0);
            Assert.IsTrue(result.text == comment.text);
        }
Exemple #23
0
 public Stream CreateCommentPreview(string commentForumId, string siteName, CommentInfo comment)
 {
     bool isEditor = false;
     try
     {
         ISite site = GetSite(siteName);
         _commentObj.CallingUser = GetCallingUser(site);
         isEditor = _commentObj.CallingUser.IsUserA(UserTypes.Editor);
     }
     catch{}
     comment.text = CommentInfo.FormatComment(comment.text, comment.PostStyle, comment.hidden, isEditor);
     return GetOutputStream(comment);
 }
Exemple #24
0
        /// <summary>
        /// Creates a Reply comment to the given comment thread id
        /// </summary>
        /// <param name="commentForum">The forum containing the comment to post the reply to</param>
        /// <param name="threadId">The thread to post to</param>
        /// <param name="comment">The comment to add</param>
        /// <returns>The created comment object</returns>
        public CommentInfo CommentReplyCreate(Forum commentForum, int threadId, CommentInfo comment)
        {
            var site = SiteList.GetSite(commentForum.SiteName);
            bool ignoreModeration;
            bool forceModeration;
            var notes = string.Empty;
            string profanityxml = string.Empty;

            List<Term> terms = null;

            ValidateComment(commentForum, comment, site, out ignoreModeration, out forceModeration, out notes, out terms);

            if (terms != null && terms.Count > 0)
            {
                profanityxml = new Term().GetProfanityXML(terms);
            }

            //create unique comment hash
            var guid = DnaHasher.GenerateCommentHashValue(comment.text, commentForum.Id, CallingUser.UserID);
            //add comment to db
            try
            {
                using (IDnaDataReader reader = CreateReader("commentreplycreate"))
                {
                    reader.AddParameter("commentforumid", commentForum.Id);
                    reader.AddParameter("threadid", threadId);
                    reader.AddParameter("userid", CallingUser.UserID);
                    reader.AddParameter("content", comment.text);
                    reader.AddParameter("hash", guid);
                    reader.AddParameter("forcemoderation", forceModeration);
                    //reader.AddParameter("forcepremoderation", (commentForum.ModerationServiceGroup == ModerationStatus.ForumStatus.PreMod?1:0));
                    reader.AddParameter("ignoremoderation", ignoreModeration);
                    reader.AddParameter("isnotable", CallingUser.IsUserA(UserTypes.Notable));
                    reader.AddParameter("ipaddress", IpAddress);
                    reader.AddParameter("bbcuid", BbcUid);
                    reader.AddIntReturnValue();
                    reader.AddParameter("poststyle", (int) comment.PostStyle);
                    if (!String.IsNullOrEmpty(notes))
                    {
                        reader.AddParameter("modnotes", notes);
                    }

                    if (false == string.IsNullOrEmpty(profanityxml))
                    {
                        reader.AddParameter("profanityxml", profanityxml);
                    }

                    reader.Execute();
                    if (reader.HasRows && reader.Read())
                    {
                        //all good - create comment
                        comment.PreModPostingsModId = reader.GetInt32NullAsZero("PreModPostingModId");
                        comment.IsPreModerated = (reader.GetInt32NullAsZero("IsPreModerated") == 1);
                        comment.hidden = (comment.IsPreModerated
                                              ? CommentStatus.Hidden.Hidden_AwaitingPreModeration
                                              : CommentStatus.Hidden.NotHidden);
                        comment.User = UserReadByCallingUser(site);
                        comment.Created = new DateTimeHelper(DateTime.Now);

                        //count = reader.GetInt32NullAsZero("ThreadPostCount");

                        if (reader.GetInt32NullAsZero("postid") != 0)
                        {
                            // no id as it is may be pre moderated
                            comment.ID = reader.GetInt32NullAsZero("postid");
                            var replacement = new Dictionary<string, string>();
                            replacement.Add("sitename", site.SiteName);
                            replacement.Add("postid", comment.ID.ToString());
                            comment.ComplaintUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                            SiteList.GetSiteOptionValueString(site.SiteID, "General", "ComplaintUrl")
                                                                                            , replacement);

                            replacement = new Dictionary<string, string>();
                            replacement.Add("commentforumid", commentForum.Id);
                            replacement.Add("sitename", site.SiteName);
                            comment.ForumUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                        UriDiscoverability.UriType.
                                                                                            CommentForumById,
                                                                                        replacement);

                            comment.text = CommentInfo.FormatComment(comment.text, comment.PostStyle, comment.hidden, comment.User.Editor);
                        }
                        else
                        {
                            comment.ID = 0;
                        }
                    }
                    else
                    {
                        int returnValue;
                        reader.TryGetIntReturnValue(out returnValue);
                        ParseCreateCommentSpError(returnValue);
                    }
                }
            }
            catch (ApiException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ApiException(ex.Message, ex.InnerException);
            }
            //return new comment complete with id etc
            return comment;
        }
Exemple #25
0
 public Stream PostCommentToConversation(string siteName, string commentForumUid, string conversationId, CommentInfo commentInfo)
 {
     var threadId = int.Parse(conversationId);
     
     //Yuck!!!
     _commentObj.CallingUser = GetCallingUser(GetSite(siteName));
     var comment = _commentObj.PostCommentToConversation(siteName, commentForumUid, threadId, commentInfo);
     return GetOutputStream(comment);
 }
Exemple #26
0
        public CommentInfo PostCommentToConversation(string siteName, string commentForumUid, int conversationId, CommentInfo comment)
        {
            if (CallingUser == null)
            {
                throw new InvalidOperationException("Cannot post to conversation if not signed in");
            }

            var apiKey = GetApiKeyFromSiteName(siteName);

            var moderationStatus = DetermineModerationStatus(apiKey, commentForumUid);
            switch (moderationStatus)
            {
                case 0: //Reactive
                    comment = AddToCommentRepository(commentForumUid, conversationId , comment);
                    break;

                case 1: //Post
                    comment = AddToCommentRepository(commentForumUid, conversationId, comment);
                    QueueComment(moderationStatus, commentForumUid, conversationId, comment);
                    break;

                case 2 : //Pre:
                    QueueComment(moderationStatus, commentForumUid, conversationId, comment);
                    break;

                default:
                    throw new NotImplementedException("Unknown moderation method in PostComment: " + moderationStatus.ToString());
            }
            return comment;
        }
Exemple #27
0
        public void CommentForumReadByUID()
		{
            CommentForum commentForum = new CommentForum
            {
                Id = "testCommentForum_readUID",
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };
            

            //create the forum
            CommentForum result = _comments.CreateCommentForum(commentForum, site);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            //create the comment
            //set up test data
            CommentInfo comment = new CommentInfo
            {
                text = "this is a nunit generated comment."
            };
            comment.text += Guid.NewGuid().ToString();//have to randomize the string to post
            string IPAddress = String.Empty;
            Guid BBCUid = Guid.NewGuid();
            //normal user
            _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
            _comments.CallingUser.CreateUserFromDnaUserID(TestUtils.TestUserAccounts.GetNormalUserAccount.UserID, site.SiteID);
            CommentInfo commentInfo = _comments.CreateComment(result, comment);
            Assert.IsTrue(commentInfo != null);
            Assert.IsTrue(commentInfo.ID > 0);
            Assert.IsTrue(commentInfo.text == comment.text);

            string badUid = "not a UID";
            //test good site
            result = _comments.GetCommentForumByUid(commentForum.Id, site);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.commentList != null);
            Assert.IsTrue(result.commentList.TotalCount != 0);
            //test paging
            _comments.ItemsPerPage = 50;
            _comments.StartIndex = 0;
            result = _comments.GetCommentForumByUid(commentForum.Id, site);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.commentList != null);
            Assert.IsTrue(result.commentList.TotalCount != 0);
            Assert.IsTrue(result.commentList.ItemsPerPage == _comments.ItemsPerPage);
            Assert.IsTrue(result.commentList.StartIndex == _comments.StartIndex);

            //test bad site name
            result = _comments.GetCommentForumByUid(badUid, site);
            Assert.IsTrue(result == null);

		}
Exemple #28
0
 private void QueueComment(int moderationStatus, string commentForumUid, int conversationId, CommentInfo comment)
 {
     int modId = 0;
     switch (moderationStatus)
     {
         case 1: //post
             modId = AddCommentToPostModerationsQueue(commentForumUid, comment, modId);
             break;
         case 2:
             modId = AddCommentToPreModerationQueue(commentForumUid, conversationId, comment, modId);
             break;
         default:
             throw new InvalidOperationException("Can't add to moderation queue using moderation method " /*+ moderationItem.ModerationPolicy.ToString()*/);
     }
 }
Exemple #29
0
        public void CommentListReadByUID_SortBy_Created()
        {
            string uid = "testCommentForum_CommentListReadBySiteName" + Guid.NewGuid().ToString();
            CommentForum commentForum = new CommentForum
            {
                Id = uid,
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };


            //create the forum
            CommentForum result = _comments.CreateCommentForum(commentForum, site);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == commentForum.Id);
            Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
            Assert.IsTrue(result.Title == commentForum.Title);
            //create the comment
            //set up test data
            for (int i = 0; i < 10; i++)
            {
                CommentInfo comment = new CommentInfo
                {
                    text = "this is a nunit generated comment."
                };
                comment.text += Guid.NewGuid().ToString();//have to randomize the string to post
                string IPAddress = String.Empty;
                Guid BBCUid = Guid.NewGuid();
                //normal user
                _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
                _comments.CallingUser.CreateUserFromDnaUserID(TestUtils.TestUserAccounts.GetNormalUserAccount.UserID, site.SiteID);
                CommentInfo commentInfo = _comments.CreateComment(result, comment);
                Assert.IsTrue(commentInfo != null);
                Assert.IsTrue(commentInfo.ID > 0);
                Assert.IsTrue(commentInfo.text == comment.text);
            }


            //test good site
            CommentForum resultList = _comments.GetCommentForumByUid(uid, site);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.commentList.TotalCount != 0);
            //test paging
            _comments.ItemsPerPage = 3;
            _comments.StartIndex = 5;
            resultList = _comments.GetCommentForumByUid(uid, site);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.commentList.TotalCount != 0);
            Assert.IsTrue(resultList.commentList.ItemsPerPage == _comments.ItemsPerPage);
            Assert.IsTrue(resultList.commentList.StartIndex == _comments.StartIndex);

            //get comment list with ascending sort
            _comments.SortBy = SortBy.Created;
            _comments.SortDirection = SortDirection.Ascending;
            resultList = _comments.GetCommentForumByUid(uid, site);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.commentList.SortBy == _comments.SortBy);
            Assert.IsTrue(resultList.commentList.SortDirection == _comments.SortDirection);

            DateTime prevCreate = DateTime.MinValue;
            DateTime currentDate = DateTime.MinValue;
            for (int i = 0; i < resultList.commentList.comments.Count; i++)
            {
                currentDate = DateTime.Parse(resultList.commentList.comments[i].Created.At);
                Assert.IsTrue(currentDate >= prevCreate);
                prevCreate = currentDate;
            }

            //get comment list with descending sort
            _comments.SortBy = SortBy.Created;
            _comments.SortDirection = SortDirection.Descending;
            resultList = _comments.GetCommentForumByUid(uid, site);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.commentList.SortBy == _comments.SortBy);
            Assert.IsTrue(resultList.commentList.SortDirection == _comments.SortDirection);

            prevCreate = DateTime.MaxValue;
            for (int i = 0; i < resultList.commentList.comments.Count; i++)
            {
                currentDate = DateTime.Parse(resultList.commentList.comments[i].Created.At);
                Assert.IsTrue(currentDate <= prevCreate);
                prevCreate = currentDate;
            }
        }
Exemple #30
0
 private int AddCommentToPostModerationsQueue(string commentForumUid, CommentInfo comment, int modId)
 {
     using (var reader = CreateReader("dna.AddCommentToPostModerationQueue"))
     {
         reader.AddParameter("commentForumId", commentForumUid);
         reader.AddParameter("commentId", comment.ID);
         reader.Execute();
         if (reader.HasRows && reader.Read())
         {
             modId = reader.GetInt32NullAsZero("ModerationQueueId");
         }
     }
     return modId;
 }