예제 #1
0
        public void CommentCreate_PreModSiteWithProcessPreMod()
        {

            using (FullInputContext inputcontext = new FullInputContext(""))
            {
                using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
                {
                    reader.ExecuteDEBUGONLY("update sites set premoderation=1 where siteid=" + site.SiteID.ToString());//set premod
                    reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() +",'Moderation', 'ProcessPreMod','1',1,'test premod value')");

                    
                }
                _siteList = SiteList.GetSiteList();
                site = _siteList.GetSite("h2g2");
                _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), inputcontext.SiteList);
            }

            try
            {

                //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();
                string commentForumID = "testCommentForum" + Guid.NewGuid().ToString();

                CommentForum commentForum = CommentForumCreate(commentForumID, ModerationStatus.ForumStatus.Unknown);//should override this with the site value
                //normal user
                _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
                _comments.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUtils.TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty);

                CommentInfo result = _comments.CreateComment(commentForum, comment);

                Assert.IsTrue(result != null);
                Assert.IsTrue(result.ID == 0);//should be have no post ID
                Assert.IsTrue(result.text == "This post is awaiting moderation.");

                //check if post in PreModPostings queue table
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
                    {
                        reader.ExecuteDEBUGONLY("select top 1 * from PreModPostings where dateposted > DATEADD(mi, -1, getdate())");//must be within 2 mins of post date
                        if (!reader.Read() || !reader.HasRows)
                        {
                            Assert.Fail("Post not in ThreadMod PreModPostings and moderation queue");
                        }
                    }
                }
            }
            finally 
            { 
                //reset h2g2 site
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
                    {
                        reader.ExecuteDEBUGONLY("update sites set premoderation=0 where siteid=" + site.SiteID.ToString());//set premod
                        reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='ProcessPreMod'");
                    }
                    _siteList = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);
                    site = _siteList.GetSite("h2g2");
                    _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                }
            }
        }
예제 #2
0
        public void CommentCreate_CommentOnEmergencyClosedSite()
        {
            //create comments objects

            _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
            _comments.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUtils.TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty);
            var callingUser = _comments.CallingUser;
            //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();
            string commentForumID = "testCommentForum" + Guid.NewGuid().ToString();
            
            CommentForum commentForum = CommentForumCreate(commentForumID);

            try
            {//turn the site into emergency closed mode
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = true;
                using (var inputcontext = new FullInputContext(""))
                {
                    _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator,
                                             CacheFactory.GetCacheManager(), _siteList);
                    _comments.CallingUser = callingUser;
                }
                CommentInfo result = _comments.CreateComment(commentForum, comment);
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.SiteIsClosed, ex.type);
            }
            finally
            {//reset the site into emergency closed mode
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = false;
            }
        }
예제 #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++;
            }
        }
예제 #4
0
        public void CommentCreate_WithCharLimit()
        {
            try
            {
                //set max char option
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
                    {
                        reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() + ",'CommentForum', 'MaxCommentCharacterLength','15',0,'test MaxCommentCharacterLength value')");
                        _siteList = SiteList.GetSiteList();
                        _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                    }
                }
                string commentForumID = "good" + Guid.NewGuid().ToString();
                CommentForum commentForum = CommentForumCreate(commentForumID);
                //set up test data
                CommentInfo comment = new CommentInfo{text = Guid.NewGuid().ToString().Substring(0,10)};
                //normal user
                _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
                _comments.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUtils.TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty);
                CommentInfo result = _comments.CreateComment(commentForum, comment);//should pass successfully
                Assert.IsTrue(result != null);
                Assert.IsTrue(result.ID > 0);
                Assert.IsTrue(result.text == comment.text);

                //with some markup
                comment.text = String.Format("<div><b><i><u>{0}</u></i></b></div>", Guid.NewGuid().ToString().Substring(0, 10));
                result = _comments.CreateComment(commentForum, comment);//should pass successfully
                Assert.IsTrue(result != null);
                Assert.IsTrue(result.ID > 0);
                Assert.IsTrue(result.text == comment.text);

                //string too large with html
                comment.text = String.Format("<div><b><i><u>{0}</u></i></b></div>", "stringtopad".PadRight(20));
                try
                {
                    result = _comments.CreateComment(commentForum, comment);
                }
                catch (ApiException ex)
                {
                    Assert.IsTrue(ex.type == ErrorType.ExceededTextLimit);
                }

                //string too large without html
                comment.text = String.Format("{0}", "stringtopad".PadRight(20));
                try
                {
                    result = _comments.CreateComment(commentForum, comment);
                }
                catch (ApiException ex)
                {
                    Assert.IsTrue(ex.type == ErrorType.ExceededTextLimit);
                }
            }
            finally 
            {
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
                    {
                        reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='MaxCommentCharacterLength'");
                        _siteList = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);
                        _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                    }
                }
            }
        }
예제 #5
0
파일: Reviews.cs 프로젝트: rocketeerbkw/DNA
        /// <summary>
        /// Creates a rating for the given rating forum
        /// </summary>
        /// <param name="RatingForum">The forum to post to</param>
        /// <param name="rating">The rating to add</param>
        /// <returns>The created rating object</returns>
        public RatingInfo RatingCreate(RatingForum RatingForum, RatingInfo rating)
        {
            ISite site = SiteList.GetSite(RatingForum.SiteName);
            //check for repeat posting
            ValidateRating(RatingForum, rating, site);

            Comments commentsObj = new Comments(DnaDiagnostics, DnaDataReaderCreator, CacheManager, SiteList);
            commentsObj.CallingUser = CallingUser;
            commentsObj.BbcUid = BbcUid;
            commentsObj.IpAddress = IpAddress;


            //create the thread entry
            RatingInfo createdRating = (RatingInfo)commentsObj.CreateComment((Forum)RatingForum, (CommentInfo)rating);
            using (var reader = CreateReader("ratingscreate"))
            {
                reader.AddParameter("entryid", createdRating.ID);
                reader.AddParameter("uid", RatingForum.Id);
                reader.AddParameter("rating", rating.rating);
                reader.AddParameter("userid", CallingUser.UserID);
                reader.AddParameter("siteid", site.SiteID);
                reader.Execute();
            }
            createdRating.rating = rating.rating;
            return createdRating;
        }