示例#1
0
        /// <summary>
        /// If comment forum exists, then update an existing comment forum 
        /// Else create a new comment forum
        /// </summary>
        /// <param name="siteName"></param>
        /// <param name="commentObj"></param>
        /// <param name="site"></param>
        /// <param name="createCommentForum"></param>
        /// <returns></returns>
        private BaseResult UpdateCommentForum(string siteName, Comments commentObj, ISite site, CommentForum createCommentForum)
        {
            CommentForum commentForumUpdateData = commentObj.GetCommentForumByUid(_profileId, site);

            if (commentForumUpdateData != null)
            {
                commentForumUpdateData.ParentUri = _commentForumURI;
                commentForumUpdateData.Title = _title;
                commentForumUpdateData = commentObj.CreateAndUpdateCommentForum(commentForumUpdateData, site, false);

                if (commentForumUpdateData != null && commentForumUpdateData.Id == _profileId)
                {
                    string[] str = InputContext.CurrentDnaRequest.UrlReferrer.AbsoluteUri.Split('?').ToArray();

                    var commentforumlistURI = str[0].Replace("moderation", siteName);
                    commentforumlistURI = commentforumlistURI.Replace("twitterprofile", "commentforumlist?dnahostpageurl=" + commentForumUpdateData.ParentUri.Trim());

                    return new Result("TwitterProfileUpdated", String.Format("Twitter profile, {0} updated successfully.", _profileId), commentforumlistURI);
                }
                else
                {
                    return new Error { Type = "COMMENTFORUMUPDATEINVALIDACTION", ErrorMessage = "Comment Forum update failed: " + _profileId };
                }
            }
            else
            {
                return CreateCommentForum(siteName, commentObj, createCommentForum, site);
            }
        }
示例#2
0
        /// <summary>
        /// Get specific profile details from Buzz
        /// </summary>
        /// <param name="twitterProfileId"></param>
        /// <returns></returns>
        private BaseResult GetProfileFromBuzz(string twitterProfileId)
        {
            BuzzClient client;
            BuzzTwitterProfile twitterProfile = null;
            CommentForum commentForum = null;
            Comments commentObj = new Comments(dnaDiagnostic, readerCreator, AppContext.DnaCacheManager, InputContext.TheSiteList);
            try
            {
                client = new BuzzClient();
                twitterProfile = new BuzzTwitterProfile();
                commentForum = new CommentForum();

                //Get the twitter profile from Buzz

                twitterProfile = client.GetProfile(twitterProfileId);

                if (twitterProfile != null)
                {
                    var twitterUserIds = string.Empty;

                    if (twitterProfile.Users.Count > 0)
                    {
                        twitterUserIds = string.Join(",", twitterProfile.Users.ToArray());
                        twitterProfile.Users = GetTwitterScreenNamesFromDNA(twitterUserIds);
                    }

                    try
                    {
                        ISite site = InputContext.TheSiteList.GetSite(_siteName);

                        if (site != null)
                        {
                            commentForum = commentObj.GetCommentForumByUid(twitterProfile.ProfileId, site);

                            if (commentForum != null)
                            {
                                _commentForumURI = commentForum.ParentUri;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        InputContext.Diagnostics.WriteExceptionToLog(ex);
                    }

                    //seperate method to fill up the twitter profile xml
                    CreateTwitterProfileXML(twitterProfile, _commentForumURI, true);
                   
                    string[] str1 = InputContext.CurrentDnaRequest.UrlReferrer.AbsoluteUri.Split('?').ToArray();

                    var commentforumlistURI = string.Empty;

                    if (commentForum != null && (false == String.IsNullOrEmpty(commentForum.SiteName)) )
                    {
                        commentforumlistURI = str1[0].Replace("moderation", commentForum.SiteName);
                        commentforumlistURI = commentforumlistURI.Replace("twitterprofilelist", "commentforumlist?dnahostpageurl=" + commentForum.ParentUri.Trim());

                        return new Result("TwitterProfileRetrieved", String.Format("Twitter profile, '{0}' retrieved successfully.", twitterProfileId), commentforumlistURI);
                    }

                    return new Result("TwitterProfileRetrieved", String.Format("Twitter profile, '{0} retrieved successfully but comment forum hasn't been created yet.", twitterProfileId));
                }
                else
                {
                    return new Error { Type = "GETTWITTERPROFILEINVALIDACTION", ErrorMessage = "Twitter Profile retrieval from Buzz failed" };
                }
            }
            catch (Exception ex)
            {
                InputContext.Diagnostics.WriteExceptionToLog(ex);
                return new Error { Type = "GETTWITTERPROFILEINVALIDACTION", ErrorMessage = "Twitter Profile retrieval failed" };
            }
        }
示例#3
0
        public void GivenIHaveAnCommentInTheReferalQueue()
        {
            //To get to this stage we need:-
            //1. Create a comment forum (make it pre-mod)
            //2. Add at least 2 posts
            //3. Refer the first post
            //  a) for a post to be referred it should be in the mod queue (so - make the comment forum pre-mod
            //Let's not make a web request if possible - we'll need the databse though
            //SnapshotInitialisation.RestoreFromSnapshot(); //TODO: SnapshotInitialisation should not depend on IIS at all. 
            //Whatever info is required should be injected.
            //TODO: get this from config
            string connectionString =
                @"database=smallGuide; server=.\MSSQL2008R2; user id=sa; password=Thanatos99; pooling=false";
            
            DataReaderCreator = new DnaDataReaderCreator(connectionString, Diagnostics.Object);

            SiteList = new SiteList(DataReaderCreator,
                                    Diagnostics.Object,
                                    CacheManager.Object,
                                    RipleyServerAddresses,
                                    DotNetServerAddresses);

            var comments = new BBC.Dna.Api.Comments(Diagnostics.Object,
                                                    DataReaderCreator,
                                                    CacheManager.Object,
                                                    SiteList);

            Forum = new Forum();
            Forum.Id = "distress-message-fun-and-games";
            Forum.ParentUri = "http://www.bbc.co.uk/dna/h2g2";
            Forum.Title = "distress-message-fun-and-games";

            Forum.ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod;
            
            Site.Setup(x => x.SiteID).Returns(1);
            Site.Setup(x => x.SiteName).Returns("h2g2");

            //see if this comment forum already exists
            var commentForum = comments.GetCommentForumByUid(Forum.Id, Site.Object, true);
            if (commentForum == null)
            {
                commentForum = comments.CreateCommentForum(Forum, Site.Object);
            }
            //save the forumid for later in the test
            CommentForumId = commentForum.ForumID;

            //if we have less than 2 comments we need to get up to 2
            int commentCount = commentForum.commentList.TotalCount;
            while (commentCount < 2)
            {
                //Ok this is what I want to do but...
                //commentForum.Post(new Comment(...));
                //TODO: can we add this method through a good refactor
                var commentInfo = new CommentInfo();
                commentInfo.text = "Simple comment text " + commentCount.ToString();
                
                var callingUser = new Mock<ICallingUser>();
                callingUser.Setup(x => x.UserID).Returns(TestUserAccounts.GetNormalUserAccount.UserID);
                callingUser.Setup(x => x.IsSecureRequest).Returns(true);
                comments.CallingUser = callingUser.Object;
                
                var info = comments.CreateComment(commentForum, commentInfo);

                commentCount++;
            }
        }
        public void CommentForum_SiteEmergencyClose()
        {
            try
            {
                CommentForum commentForum = new CommentForum
                {
                    Id = Guid.NewGuid().ToString(),
                    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);
                Assert.IsTrue(result.commentSummary.Total == 0);

                //add a comment 
                CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() };
                //normal user
                _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
                _comments.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty);
                _comments.CreateComment(result, comment);

                //get forum again
                result = _comments.GetCommentForumByUid(result.Id, 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.commentSummary.Total == 1);

                //close site
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = true;
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                    
                }

                result = _comments.GetCommentForumByUid(result.Id, site);
                Assert.IsTrue(result != null);
                Assert.IsTrue(result.isClosed);

                //reopen site
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = false;
            }
            finally
            {
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = false;
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    _siteList = SiteList.GetSiteList();
                    site = _siteList.GetSite("h2g2");
                    _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                }
            }
        }
示例#5
0
        public void ThenTheDistressMessageWillAppearInTheCommentsModuleAsAReplyToTheReferredMessage()
        {
            var comments = new BBC.Dna.Api.Comments(Diagnostics.Object,
                                                    DataReaderCreator,
                                                    CacheManager.Object,
                                                    SiteList);

            //see if this comment forum already exists
            comments.SortBy = (SortBy)Enum.Parse(typeof(SortBy), SortBy);
            comments.SortDirection = (SortDirection)Enum.Parse(typeof(SortDirection), SortDirection);
            var commentForum = comments.GetCommentForumByUid(Forum.Id, Site.Object, true);
            if (commentForum != null)
            {
                foreach (var comment in commentForum.commentList.comments)
                {
                    if (comment.DistressMessage != null)
                    {
                        Assert.AreEqual("body", comment.DistressMessage.text);
                        return;
                    }
                }
            }
            Assert.Fail("No distress message found");
        }