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);

		}
Пример #2
0
        public void StartUp()
        {
            SnapshotInitialisation.RestoreFromSnapshot();
            _context = new FullInputContext("");

            _siteList = _context.SiteList;

            // Create a comment forums to post tweets to, and the corresponding URLs
            CommentsTests_V1 ct = new CommentsTests_V1();
            _commentForumReactive = ct.CommentForumCreate("Tests Reactive", Guid.NewGuid().ToString(),ModerationStatus.ForumStatus.Reactive);
            _tweetPostUrlReactive= String.Format("http://" + _server + "/dna/api/comments/TwitterService.svc/V1/site/{0}/commentsforums/{1}/",_sitename, _commentForumReactive.Id);

            _commentForumPremod = ct.CommentForumCreate("Tests Premod", Guid.NewGuid().ToString(),ModerationStatus.ForumStatus.PreMod);
            _tweetPostUrlPremod = String.Format("http://" + _server + "/dna/api/comments/TwitterService.svc/V1/site/{0}/commentsforums/{1}/", _sitename, _commentForumPremod.Id);
        }
Пример #3
0
 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;
 }
Пример #4
0
        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));
        }
Пример #5
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;
            }
        }
Пример #6
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);

        }
Пример #7
0
        public void CommentForumCreate_InReactive()
        {
            CommentForum commentForum = new CommentForum
            {
                
                Id = "CommentForumCreate_InReactive",
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum",
                ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive
            };
            

            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);
            
            Assert.IsTrue(result.ModerationServiceGroup == ModerationStatus.ForumStatus.Reactive);

        }
Пример #8
0
 public void CommentForumCreate_MissingTitle()
 {
     CommentForum commentForum = new CommentForum
     {
         Id = "testCommentForum_MissingTitle",
         ParentUri = "http://www.bbc.co.uk/dna/h2g2/"
     };
     try
     {
         CommentForum result = _comments.CreateCommentForum(commentForum, site);
     }
     catch (ApiException ex)
     {
         Assert.IsTrue(ex.type == ErrorType.InvalidForumTitle);
     }
 }
Пример #9
0
        public void CommentForumCreate_Duplicate()
        {
            CommentForum commentForum = new CommentForum
            {
                Id = "testCommentForum_dupe",
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };
            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);

            //should return the same forum
            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);

        }
Пример #10
0
 public void CommentForumCreate_Good()
 {
     CommentForum commentForum = new CommentForum
     {
         Id = "testCommentForum_good",
         ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
         Title = "testCommentForum"
     };
     
     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);
  
 }
Пример #11
0
        /// <summary>
        /// Returns the comment forum uid from cache
        /// </summary>
        /// <param name="site">the site of the forum</param>
        /// <param name="forum">The return forum</param>
        /// <returns>true if found in cache otherwise false</returns>
        private void AddCommentForumToCache(CommentForum forum, ISite site)
        {
            string cacheKey = CommentForumCacheKey(forum.Id, site.SiteID);
            //ICacheItemExpiration expiry = SlidingTime.
            CacheManager.Add(cacheKey + CacheLastupdated, forum.LastUpdate, CacheItemPriority.Normal,
                             null, new SlidingTime(TimeSpan.FromMinutes(Cacheexpiryminutes)));

            CacheManager.Add(cacheKey, forum, CacheItemPriority.Normal,
                             null, new SlidingTime(TimeSpan.FromMinutes(Cacheexpiryminutes)));
        }
Пример #12
0
        /// <summary>
        /// Returns the comment forum uid from cache
        /// </summary>
        /// <param name="uid">The uid of the forum</param>
        /// <param name="site">the site of the forum</param>
        /// <param name="forum">The return forum</param>
        /// <returns>true if found in cache otherwise false</returns>
        private bool GetCommentForumByUidFromCache(string uid, ISite site, ref CommentForum forum)
        {
            string cacheKey = CommentForumCacheKey(uid, site.SiteID);
            object tempLastUpdated = CacheManager.GetData(cacheKey + CacheLastupdated);

            if (tempLastUpdated == null)
            {
//not found
                forum = null;
                Statistics.AddCacheMiss();
                return false;
            }
            var lastUpdated = (DateTime) tempLastUpdated;

            //check if cache is up to date
            if (DateTime.Compare(lastUpdated, CommentForumGetLastUpdate(uid, site.SiteID)) != 0 || lastUpdated == DateTime.MinValue)
            {
//cache out of date so delete
                DeleteCommentForumFromCache(uid, site);
                forum = null;
                Statistics.AddCacheMiss();
                return false;
            }
            //get actual cached object
            forum = (CommentForum) CacheManager.GetData(cacheKey);
            if (forum == null)
            {
//cache out of date so delete
                DeleteCommentForumFromCache(uid, site);
                Statistics.AddCacheMiss();
                return false;
            }
            //apply site variables
            forum = ApplySiteVariables(forum, site);
            Statistics.AddCacheHit();

            //readd to cache to add sliding window affect
            AddCommentForumToCache(forum, site);
            return true;
        }
Пример #13
0
        /// <summary>
        /// Creates the commentforumdata from a given reader
        /// </summary>
        /// <param name="reader">The database reaser</param>
        /// <returns>A Filled comment forum object</returns>
        private CommentForum CommentForumCreateFromReader(IDnaDataReader reader)
        {
            var closingDate = reader.GetDateTime("forumclosedate");
            //if (closingDate == null)
            //{
            //    closingDate = DateTime.MaxValue;
            //}
            var site = SiteList.GetSite(reader.GetStringNullAsEmpty("sitename"));

            var commentForum = new CommentForum();

            commentForum.Title = reader.GetStringNullAsEmpty("Title");
            commentForum.Id = reader.GetStringNullAsEmpty("UID");
            commentForum.CanRead = reader.GetByteNullAsZero("canRead") == 1;
            commentForum.CanWrite = reader.GetByteNullAsZero("canWrite") == 1;
            commentForum.ParentUri = reader.GetStringNullAsEmpty("Url");
            commentForum.SiteName = reader.GetStringNullAsEmpty("sitename");
            commentForum.CloseDate = closingDate;
            commentForum.LastUpdate = reader.GetDateTime("LastUpdated");
            if (reader.GetDateTime("lastposted") > commentForum.LastUpdate)
            {
//use last posted as it is newer
                commentForum.LastUpdate = reader.GetDateTime("lastposted");
            }
            commentForum.Updated = new DateTimeHelper(commentForum.LastUpdate);
            commentForum.Created = new DateTimeHelper(reader.GetDateTime("DateCreated"));
            commentForum.commentSummary = new CommentsSummary
                                              {
                                                  Total = reader.GetInt32NullAsZero("ForumPostCount"),
                                                  EditorPicksTotal = reader.GetInt32NullAsZero("editorpickcount")
                                              };
            commentForum.ForumID = reader.GetInt32NullAsZero("forumid");
            commentForum.isClosed = !commentForum.CanWrite || site.IsEmergencyClosed ||
                                    site.IsSiteScheduledClosed(DateTime.Now) ||
                                    (DateTime.Now > closingDate);
            //MaxCharacterCount = siteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "'MaxCommentCharacterLength")
            var replacements = new Dictionary<string, string>();
            replacements.Add("commentforumid", reader.GetStringNullAsEmpty("uid"));
            replacements.Add("sitename", site.SiteName);

            if (reader.Exists("IsContactForm") && !reader.IsDBNull("IsContactForm"))
            {
                commentForum.isContactForm = true;
                commentForum.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.ContactFormById,
                                                                            replacements);
                commentForum.commentSummary.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                           UriDiscoverability.UriType.ContactFormById,
                                                                                           replacements);
            }
            else
            {
                commentForum.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.CommentForumById,
                                                                            replacements);
                commentForum.commentSummary.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                           UriDiscoverability.UriType.CommentsByCommentForumId,
                                                                                           replacements);
            }

            //get moderation status
            commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Unknown;
            if (!reader.IsDBNull("moderationstatus"))
            {
//if it is set for the specific forum
                commentForum.ModerationServiceGroup =
                    (ModerationStatus.ForumStatus) (reader.GetTinyIntAsInt("moderationstatus"));
            }
            if (commentForum.ModerationServiceGroup == ModerationStatus.ForumStatus.Unknown)
            {
//else fall back to site moderation status
                switch (site.ModerationStatus)
                {
                    case ModerationStatus.SiteStatus.UnMod:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive;
                        break;
                    case ModerationStatus.SiteStatus.PreMod:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod;
                        break;
                    case ModerationStatus.SiteStatus.PostMod:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod;
                        break;
                    default:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive;
                        break;
                }
            }

            commentForum.NotSignedInUserId = reader.GetInt32NullAsZero("NotSignedInUserId");
            commentForum.allowNotSignedInCommenting = commentForum.NotSignedInUserId != 0;

            return commentForum;
        }
Пример #14
0
        public static void CheckCommentIsOrIsNotInTheCommentList(DnaTestURLRequest request, bool isInList, string textToCheck, CommentForum commentForum)
        {
            CallGETCommentForumAPIRequest(request, "h2g2", commentForum.Id);
            var currentCommentForum = (CommentForum)request.GetLastResponseAsJSONObject(typeof(CommentForum));
            bool match = false;
            Console.WriteLine("Text just posted : " + textToCheck);
            foreach (CommentInfo comment in currentCommentForum.commentList.comments)
            {
                match |= textToCheck.CompareTo(comment.text) == 0;
                Console.WriteLine("Comment in list : " + comment.text);
            }

            Console.WriteLine("Post found in comment list : " + match);

            if (isInList)
            {
                Assert.IsTrue(match);
            }
            else
            {
                Assert.IsFalse(match);
            }
        }
Пример #15
0
        /// <summary>
        /// Method that choses the way the retweet needs to be handled
        /// </summary>
        /// <param name="site"></param>
        /// <param name="commentForumData"></param>
        /// <param name="tweet"></param>
        /// <param name="commentObj"></param>
        /// <returns></returns>
        private Stream HandleRetweet(ISite site, CommentForum commentForumData, Tweet tweet)
        {
            if (false == string.IsNullOrEmpty(tweet.Text))
            {
                var callingOriginalTweetuser = GetCallingTwitterUser(site, tweet.RetweetedStatus);

                if (callingOriginalTweetuser.IsTrustedUser())
                {
                    return HandleRetweetOriginalTweetByTrustedUsers(site, commentForumData, tweet);
                }
                else
                {
                    return HandleRetweetOriginalTweetByPublicUsers(site, commentForumData, tweet);
                }
            }
            else
            {
                throw ApiException.GetError(ErrorType.EmptyText);
            }
        }
Пример #16
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);

		}
Пример #17
0
 public void CommentsReadByForumID()
 {
     CommentForum commentForum = new CommentForum
     {
         Id = "testCommentForum_good" + Guid.NewGuid().ToString(),
         ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
         Title = "testCommentForum"
     };
     
     CommentForum resultCommentForum = _comments.CreateCommentForum(commentForum, site);
     Assert.IsTrue(resultCommentForum != null);
     Assert.IsTrue(resultCommentForum.Id == commentForum.Id);
     Assert.IsTrue(resultCommentForum.ParentUri == commentForum.ParentUri);
     Assert.IsTrue(resultCommentForum.Title == commentForum.Title);
 }
Пример #18
0
 /// <summary>
 /// applies the site specific items
 /// </summary>
 /// <param name="forum"></param>
 /// <param name="site"></param>
 /// <returns></returns>
 private static CommentForum ApplySiteVariables(CommentForum forum, ISite site)
 {
     forum.isClosed = forum.isClosed || site.IsEmergencyClosed || site.IsSiteScheduledClosed(DateTime.Now) ||
                      (DateTime.Now > forum.CloseDate);
     return forum;
 }
Пример #19
0
        public void CommentForumCreate_WithTooManyUIDChars()
        {
            //create namespace and ID which equal 255
            CommentForum commentForum = new CommentForum
            {
                Id = "".PadRight(256, 'I'),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };

            try
            {
                //should throw error stating uid length too long
                CommentForum result = _comments.CreateCommentForum(commentForum, site);
            }
            catch (ApiException ex)
            {
                Assert.IsTrue(ex.type == ErrorType.InvalidForumUid);
            }

        }
Пример #20
0
        /// <summary>
        /// Comment forum that reads comments from multiple forums
        /// </summary>
        /// <param name="uidList">List of form uid</param>
        /// <param name="site"></param>
        /// <returns>Comment forum object including comments from all the forums</returns>
        public CommentForum GetCommentForumByUids(string uidList, ISite site)
        {
            CommentForum commentForum = null;
            
            if (GetCommentForumByUidFromCache(uidList, site, ref commentForum))
            {
                return commentForum;
            }

            try
            {
                commentForum = new CommentForum();
                commentForum.commentSummary = new CommentsSummary();
                commentForum.Id = uidList;
                commentForum.commentList = GetCommentsListByForumIds(uidList, site);

                commentForum.identityPolicy = site.IdentityPolicy;
                AddCommentForumToCache(commentForum, site);
            }
            catch (Exception ex)
            {
                throw new ApiException(ex.Message, ex.InnerException);
                //DnaApiWebProtocalException.ThrowDnaApiWebProtocalException(System.Net.HttpStatusCode.InternalServerError, ex.Message, ex);
            }
            return commentForum;
        }
Пример #21
0
        public void CommentForumCreate_MissingUri()
        {
            CommentForum commentForum = new CommentForum
            {
                Id = "testCommentForum_MissingParentUri",
                Title = "testCommentForum_MissingParentUri"
            };

            try
            {
                CommentForum result = _comments.CreateCommentForum(commentForum, site);
            }
            catch (ApiException ex)
            {
                Assert.IsTrue(ex.type == ErrorType.InvalidForumParentUri);
            }

            //check with an invalid url
            commentForum = new CommentForum
            {
                Id = "testCommentForum_MissingParentUri",
                Title = "testCommentForum_MissingParentUri",
                ParentUri ="http://www.google.com"
            };

            try
            {
                CommentForum result = _comments.CreateCommentForum(commentForum, site);
            }
            catch (ApiException ex)
            {
                Assert.IsTrue(ex.type == ErrorType.InvalidForumParentUri);
            }
        }
Пример #22
0
        public Stream CreateCommentForumWithComment(string sitename, CommentForum commentForum, string commentForumId)
        {
            ISite site = GetSite(sitename);
            try
            {
                commentForum.Id = commentForumId;
                CommentForum commentForumData = _commentObj.CreateCommentForum(commentForum, site);

                _commentObj.CallingUser = GetCallingUserOrNotSignedInUser(site, commentForumData);
                
                if (commentForum.commentList != null && commentForum.commentList.comments != null &&
                    commentForum.commentList.comments.Count > 0)
                {
                    //check if there is a rating to add
                    CommentInfo commentInfo = _commentObj.CreateComment(commentForumData,
                                                                        commentForum.commentList.comments[0]);
                    return GetOutputStream(commentInfo);
                }
                return GetOutputStream(commentForumData);
            }
            catch (ApiException ex)
            {
                throw new DnaWebProtocolException(ex);
            }
        }
Пример #23
0
 public void CommentForumCreate_MissingSiteName()
 {
     CommentForum commentForum = new CommentForum
     {
         Id = "testCommentForum_missingSitename",
         ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
         Title = "testCommentForum"
     };
     try
     {
         CommentForum result = _comments.CreateCommentForum(commentForum, null);
     }
     catch (ApiException ex)
     {
         Assert.IsTrue(ex.type == ErrorType.UnknownSite);
     }
 }
Пример #24
0
        public Stream CreateCommentForum(string sitename, CommentForum commentForum)
        {
            CommentForum commentForumData;
            try
            {
                var site = GetSite(sitename);
                try
                {
                    _commentObj.CallingUser = GetCallingUser(site);
                }
                catch (ApiException e)
                {
                    if (!_internalRequest)
                    {
                        throw e;
                    }
                }

                if (_internalRequest || _commentObj.CallingUser.IsUserA(UserTypes.Editor))
                {
                    commentForumData = _commentObj.CreateAndUpdateCommentForum(commentForum, site, null);
                }
                else
                {
                    throw ApiException.GetError(ErrorType.MissingEditorCredentials);
                }
            }
            catch (ApiException ex)
            {
                throw new DnaWebProtocolException(ex);
            }
            return GetOutputStream(commentForumData);
        }
Пример #25
0
        public void CommentForumCreate_WithFixedClosedDate()
        {
            CommentForum commentForum = new CommentForum
            {
                
                Id = "CommentForumCreate_InReactive" + Guid.NewGuid().ToString(),
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum",
                CloseDate = DateTime.Now.AddDays(2)
            };
            

            DateTime expectedCloseDate = commentForum.CloseDate.AddDays(1);//add a day
            expectedCloseDate = new DateTime(expectedCloseDate.Year, expectedCloseDate.Month, expectedCloseDate.Day);//force to midnight

            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);
            
            Assert.IsTrue(result.CloseDate == expectedCloseDate);
        }
Пример #26
0
        public void CreateCommentForumPostData(string sitename, NameValueCollection formsData)
        {
            CommentForum commentForumData;
            ErrorType error;
            DnaWebProtocolException  webEx = null;
            try
            {
                commentForumData = new CommentForum
                                       {
                                           Id = formsData["id"],
                                           Title = formsData["title"],
                                           ParentUri = formsData["parentUri"]
                                       };
                if (!String.IsNullOrEmpty(formsData["moderationServiceGroup"]))
                {
                    try
                    {
                        commentForumData.ModerationServiceGroup =
                            (ModerationStatus.ForumStatus)
                            Enum.Parse(ModerationStatus.ForumStatus.Unknown.GetType(),
                                       formsData["moderationServiceGroup"], true);
                    }
                    catch
                    {
                        throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidModerationStatus));
                    }
                }
                if (!String.IsNullOrEmpty(formsData["closeDate"]))
                {
                    DateTime closed;
                    if (!DateTime.TryParse(formsData["closeDate"], out closed))
                    {
                        throw ApiException.GetError(ErrorType.InvalidForumClosedDate);
                    }
                    commentForumData.CloseDate = closed;
                }
                CreateCommentForum(sitename, commentForumData);
                error = ErrorType.Ok;
            }
            catch (DnaWebProtocolException ex)
            {
                error = ex.ErrorType;
                webEx = ex;
            }
            string ptrt = WebFormat.GetPtrtWithResponse(error.ToString());
            if (String.IsNullOrEmpty(ptrt))
            {
//none returned...
                if (error == ErrorType.Ok)
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Created;
                    return;
                }
                throw webEx;
            }
            //do response redirect...
            WebOperationContext.Current.OutgoingResponse.Location = ptrt;
            WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.MovedPermanently;
        }
Пример #27
0
        public void CommentForumsReadBySitePrefix_SortBy_Created()
        {

            //create 3 with the same prefix
            string prefix = "prefixtestsbycomments" + Guid.NewGuid().ToString();
            CommentForum commentForum = new CommentForum
            {
                Id = prefix,
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/"
            };

            CommentForum result = null;
            for (int i = 0; i < 3; i++)
            {
                commentForum.Title = this.ToString();
                commentForum.Id = String.Format("{0}-{1}", prefix, Guid.NewGuid().ToString());
                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);
            }

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

            DateTime prevCreate = DateTime.MinValue;
            DateTime currentDate = DateTime.MinValue;
            for (int i = 0; i < resultList.CommentForums.Count; i++)
            {
                currentDate = DateTime.Parse(resultList.CommentForums[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.GetCommentForumListBySite(site, prefix);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.SortBy == _comments.SortBy);
            Assert.IsTrue(resultList.SortDirection == _comments.SortDirection);

            prevCreate = DateTime.MaxValue;
            for (int i = 0; i < resultList.CommentForums.Count; i++)
            {
                currentDate = DateTime.Parse(resultList.CommentForums[i].Created.At);
                Assert.IsTrue(currentDate <= prevCreate);
                prevCreate = currentDate;
            }
        }
Пример #28
0
        public void CommentReadByPostID()
        {
            CommentForum commentForum = new CommentForum
            {
                Id = "testCommentForum_CommentReadByPostIDTest",
                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);

            CommentInfo comment1 = SetupComment();
            CommentInfo createdComment1 = _comments.CreateComment(result, comment1);

            Assert.IsTrue(createdComment1 != null);
            Assert.IsTrue(createdComment1.ID > 0);
            Assert.IsTrue(createdComment1.text == comment1.text);

            CommentInfo comment2 = SetupComment();
            CommentInfo createdComment2 = _comments.CreateComment(result, comment2);

            Assert.IsTrue(createdComment2 != null);
            Assert.IsTrue(createdComment2.ID > 0);
            Assert.IsTrue(createdComment2.text == comment2.text);

            CommentInfo comment3 = SetupComment();
            CommentInfo createdComment3 = _comments.CreateComment(result, comment3);

            Assert.IsTrue(createdComment3 != null);
            Assert.IsTrue(createdComment3.ID > 0);
            Assert.IsTrue(createdComment3.text == comment3.text);


            CommentInfo returnedCommentInfo = _comments.CommentReadByPostId(createdComment1.ID.ToString(), site);
            Assert.IsTrue(createdComment1.text == returnedCommentInfo.text);

            returnedCommentInfo = _comments.CommentReadByPostId(createdComment3.ID.ToString(), site);
            Assert.IsTrue(createdComment3.text == returnedCommentInfo.text);

            returnedCommentInfo = _comments.CommentReadByPostId(createdComment2.ID.ToString(), site);
            Assert.IsTrue(createdComment2.text == returnedCommentInfo.text);

            returnedCommentInfo = null;
            try
            {
                returnedCommentInfo = _comments.CommentReadByPostId("0", site);
            }
            catch (ApiException ex)
            {
                Assert.IsTrue(ex.type == ErrorType.CommentNotFound);
            }
            Assert.IsTrue(returnedCommentInfo == null);
        }
Пример #29
0
        private void SetupACommentForum()
        {
            string prefix = "prefixtestsbycomments" + Guid.NewGuid().ToString();
            CommentForum commentForum = new CommentForum
            {
                Id = prefix,
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };
            CommentForum result = null;

            commentForum.Id = String.Format("{0}-{1}", prefix, Guid.NewGuid().ToString());
            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);
        }
Пример #30
0
        public void CommentForumsReadBySiteNameAndPrefix()
        {    
            //create 3 with the same prefix
            string prefix = "prefixtestsbycomments" + Guid.NewGuid().ToString();
            CommentForum commentForum = new CommentForum
            {
                Id = prefix,
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testCommentForum"
            };
            
            CommentForum result = null;
            for (int i = 0; i < 3; i++)
            {
                commentForum.Id = String.Format("{0}-{1}", prefix, Guid.NewGuid().ToString());
                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 one which doesn't have the prefix
            commentForum.Id = String.Format("{0}", Guid.NewGuid().ToString());
            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);

            //get comment list with prefix
            CommentForumList resultList = _comments.GetCommentForumListBySite(site, prefix);
            Assert.IsTrue(resultList != null);
            Assert.IsTrue(resultList.TotalCount == 3);

        }