Пример #1
0
        /// <summary>
        /// tests successful RatingForumIdentityUserCreate 
        /// </summary>
        private RatingForum RatingForumIdentityUserCreate(string nameSpace, string id, ModerationStatus.ForumStatus moderationStatus, DateTime closingDate)
        {
            Console.WriteLine("Before RatingForumIdentityUserCreate");
            string identitySitename = "identity606";
            DnaTestURLRequest request = new DnaTestURLRequest(identitySitename);

            string userName = "******" + DateTime.Now.Ticks.ToString();
            string userEmail = userName + "@bbc.co.uk";

            Assert.IsTrue(request.SetCurrentUserAsNewIdentityUser(userName, "password", "RatingForum User", userEmail, "1989-12-31", TestUserCreator.IdentityPolicies.Adult, 1, TestUserCreator.UserType.SuperUser), "Failed to create a test identity user");
            //Assert.IsTrue(request.SetCurrentUserAsNewIdentityUser(userName, "password", "RatingForum User", userEmail, "1989-12-31", TestUserCreator.IdentityPolicies.Adult, true, true), "Failed to create a test identity user");
            //using (IDnaDataReader reader = DnaMockery.CreateDatabaseInputContext().CreateDnaDataReader(""))
            //{
            //    string sql = "EXEC dbo.createnewuserfromidentityid " + request.CurrentIdentityUserID + ",0,'" + userName + "','" + userEmail + "',74";
            //    reader.ExecuteDEBUGONLY(sql);
            //    if (reader.Read())
            //    {
            //        int dnauserid = reader.GetInt32NullAsZero("userid");
            //        sql = "UPDATE dbo.Users SET Status = 2 WHERE UserID = " + dnauserid.ToString();
            //        reader.ExecuteDEBUGONLY(sql);
            //    }
            //}

            string title = "FunctionalTest Title";
            string parentUri = "http://www.bbc.co.uk/dna/h2g2/";
            string ratingForumXml = String.Format("<ratingForum xmlns=\"BBC.Dna.Api\">" +
                "<id>{0}</id>" +
                "<namespace>{3}</namespace>" +
                "<title>{1}</title>" +
                "<parentUri>{2}</parentUri>" +
                "<closeDate>{4}</closeDate>" +
                "<moderationServiceGroup>{5}</moderationServiceGroup>" +
                "</ratingForum>", id, title, parentUri, nameSpace, closingDate.ToString("yyyy-MM-dd"), moderationStatus);

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/", identitySitename);
            // now get the response
            request.RequestPageWithFullURL(url, ratingForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaRatingForum);
            validator.Validate();

            BBC.Dna.Api.RatingForum returnedForum = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum));
            Assert.IsTrue(returnedForum.Id == id);

            Assert.IsTrue(returnedForum.ParentUri == parentUri);
            Assert.IsTrue(returnedForum.Title == title);
            Assert.IsTrue(returnedForum.ModerationServiceGroup == moderationStatus);

            Console.WriteLine("After RatingForumIdentityUserCreate");

            return returnedForum;
        }
Пример #2
0
        /// <summary>
        /// tests successful RatingForumCreate 
        /// </summary>
        private RatingForum RatingForumCreate(string nameSpace, string id, ModerationStatus.ForumStatus moderationStatus, DateTime closingDate)
        {
            Console.WriteLine("Before CreateRatingForum");

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

            string title = "Functiontest Title";
            string parentUri = "http://www.bbc.co.uk/dna/h2g2/";
            string ratingForumXml = String.Format("<ratingForum xmlns=\"BBC.Dna.Api\">" +
                "<id>{0}</id>" +
                "<namespace>{3}</namespace>" +
                "<title>{1}</title>" +
                "<parentUri>{2}</parentUri>" +
                "<closeDate>{4}</closeDate>" +
                "<moderationServiceGroup>{5}</moderationServiceGroup>" +
                "</ratingForum>", id, title, parentUri, nameSpace, closingDate.ToString("yyyy-MM-dd"), moderationStatus);

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/", _sitename);
            // now get the response
            request.RequestPageWithFullURL(url, ratingForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaRatingForum);
            validator.Validate();

            BBC.Dna.Api.RatingForum returnedForum = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum));
            Assert.IsTrue(returnedForum.Id == id);
            
            Assert.IsTrue(returnedForum.ParentUri == parentUri);
            Assert.IsTrue(returnedForum.Title == title);
            Assert.IsTrue(returnedForum.ModerationServiceGroup == moderationStatus);
            return returnedForum;
        }
Пример #3
0
        /// <summary>
        /// tests successful RatingForumCreate 
        /// </summary>
        private RatingForum RatingForumCreate(string Namespace, string id, ModerationStatus.ForumStatus moderationStatus)
        {
            return RatingForumCreate(Namespace, id, moderationStatus, DateTime.MinValue);

        }
Пример #4
0
        /// <summary>
        /// tests successful CommentForumCreate 
        /// </summary>
        public CommentForum CommentForumCreate(string id, ModerationStatus.ForumStatus moderationStatus)
        {
            return CommentForumCreate(id, moderationStatus, DateTime.MinValue);

        }
Пример #5
0
 /// <summary>
 /// tests successful CommentForumCreate 
 /// </summary>
 public CommentForum CommentForumCreate(string id, ModerationStatus.ForumStatus moderationStatus, DateTime closingDate)
 {
     CommentForum commentForum = new CommentForum
     {
         Id = id,
         ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
         Title = "testCommentForum",
         ModerationServiceGroup = moderationStatus,
         CloseDate = closingDate
     };
     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);
     return result;
 }
Пример #6
0
        private void SetPermissions(ModerationStatus.SiteStatus siteStatus, ModerationStatus.ForumStatus forumStatus, 
            ModerationStatus.ForumStatus threadStatus, ModerationStatus.ForumStatus userStatus, bool processPreMod)
        {
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader dataReader = context.CreateDnaDataReader(""))
            {
                switch (siteStatus)
                {
                    case ModerationStatus.SiteStatus.PreMod:
                        dataReader.ExecuteDEBUGONLY("update sites set premoderation=1, unmoderated=0 where siteid=" + _siteId);
                        break;

                    case ModerationStatus.SiteStatus.PostMod:
                        dataReader.ExecuteDEBUGONLY("update sites set premoderation=0, unmoderated=0 where siteid=" + _siteId);
                        break;

                    case ModerationStatus.SiteStatus.UnMod:
                        dataReader.ExecuteDEBUGONLY("update sites set premoderation=0, unmoderated=1 where siteid=" + _siteId);
                        break;
                }

                dataReader.ExecuteDEBUGONLY(string.Format("update forums set moderationstatus={0} where forumid={1}", (int)forumStatus, _forumId));
                dataReader.ExecuteDEBUGONLY(string.Format("update threads set moderationstatus={0} where threadid={1}", (int)threadStatus, _threadId));


                dataReader.ExecuteDEBUGONLY(string.Format("delete from Preferences where userid={0} and siteid={1}", _userId, _siteId));
                if (userStatus != ModerationStatus.ForumStatus.Reactive)
                {
                    dataReader.ExecuteDEBUGONLY(string.Format("insert into Preferences (userid, siteid, AutoSinBin, prefstatus, AgreedTerms) values ({0},{1},{2},{3},1)", _userId, _siteId, 
                        (userStatus == ModerationStatus.ForumStatus.PreMod)?1:0, (int)userStatus));
                }

                dataReader.ExecuteDEBUGONLY(string.Format("delete from siteoptions where siteid={0} and name='ProcessPreMod'", _siteId));
                if (processPreMod)
                {
                    dataReader.ExecuteDEBUGONLY(string.Format("insert into siteoptions (section, siteid, name, value, type,description) values ('Moderation',{0},'ProcessPreMod', 1, 1, 'test')", _siteId));

                }
            }

            SendSignal();

        }
Пример #7
0
        private int GetPostIdFromResponse(XmlDocument xml, ModerationStatus.ForumStatus modStatus)
        {
            var postId = 0;
            if (modStatus == ModerationStatus.ForumStatus.PreMod)
            {
                //<POSTPREMODERATED FORUM="7325075" THREAD="34" POST="65" />
                var node = xml.SelectSingleNode("//H2G2/POSTPREMODERATED");
                postId = Int32.Parse(node.Attributes["POST"].Value);

            }
            else
            {
                var redirectUrl = HtmlUtils.HtmlDecode(xml.SelectSingleNode("//H2G2/REDIRECT-TO").InnerText);
                var postPos = redirectUrl.LastIndexOf("#p") + 2;
                postId = Int32.Parse(redirectUrl.Substring(postPos, redirectUrl.Length - postPos));
            }

            return postId;
        }
Пример #8
0
        private void CheckPostInModQueue(XmlDocument xml, ModerationStatus.ForumStatus modStatus, bool processPreMod)
        {
            if (processPreMod)
            {
                IInputContext context = DnaMockery.CreateDatabaseInputContext();
                using (IDnaDataReader dataReader = context.CreateDnaDataReader(""))
                {
                    dataReader.ExecuteDEBUGONLY(string.Format("select * from premodpostings"));
                    Assert.IsTrue(dataReader.HasRows);
                }
            }
            else
            {
                var postId = GetPostIdFromResponse(xml, modStatus);

                IInputContext context = DnaMockery.CreateDatabaseInputContext();
                using (IDnaDataReader dataReader = context.CreateDnaDataReader(""))
                {
                    dataReader.ExecuteDEBUGONLY(string.Format("select * from threadmod where postid={0}", postId));
                    if (modStatus == ModerationStatus.ForumStatus.Reactive)
                    {//not in queue
                        Assert.IsFalse(dataReader.HasRows);
                    }
                    else
                    {//in queue
                        Assert.IsTrue(dataReader.HasRows);
                    }
                }

            }
        }
Пример #9
0
        private void CheckPostInThread(XmlDocument xml, ModerationStatus.ForumStatus modStatus, bool processPreMod)
        {
             //get forum page
            var request = new DnaTestURLRequest(_siteName);
            request.SetCurrentUserNormal();
            request.RequestPage(string.Format("F{0}?thread={1}&skin=purexml", _forumId, _threadId));
            var xmlDoc = request.GetLastResponseAsXML();
            

            if (processPreMod)
            {
                var nodes = xmlDoc.SelectNodes(string.Format("//H2G2/FORUMTHREADPOSTS/POST"));
                Assert.AreEqual(1, nodes.Count);
            }
            else
            {
                var postId = GetPostIdFromResponse(xml, modStatus);

                var node = xmlDoc.SelectSingleNode(string.Format("//H2G2/FORUMTHREADPOSTS/POST[@POSTID = {0}]", postId));
                Assert.IsNotNull(node);
                if (modStatus == ModerationStatus.ForumStatus.PreMod)
                {//only hidden if premod
                    Assert.AreEqual("3", node.Attributes["HIDDEN"].Value);
                }
                else
                {
                    Assert.AreEqual("0", node.Attributes["HIDDEN"].Value);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// tests successful RatingForumIdentityUserCreate 
        /// </summary>
        private RatingForum RatingForumIdentityUserCreate(string nameSpace, string id, ModerationStatus.ForumStatus moderationStatus, DateTime closingDate)
        {
            Console.WriteLine("Before RatingForumIdentityUserCreate");
            string identitySitename = "identity606";
            DnaTestURLRequest request = new DnaTestURLRequest(identitySitename);

            string userName = "******" + DateTime.Now.Ticks.ToString();
            string userEmail = userName + "@bbc.co.uk";

            Assert.IsTrue(request.SetCurrentUserAsNewIdentityUser(userName, "password", "RatingForum User", userEmail, "1989-12-31", TestUserCreator.IdentityPolicies.Adult, identitySitename, TestUserCreator.UserType.SuperUser), "Failed to create a test identity user");

            string title = "FunctionalTest Title";
            string parentUri = "http://www.bbc.co.uk/dna/h2g2/";
            string ratingForumXml = String.Format("<ratingForum xmlns=\"BBC.Dna.Api\">" +
                "<id>{0}</id>" +
                "<namespace>{3}</namespace>" +
                "<title>{1}</title>" +
                "<parentUri>{2}</parentUri>" +
                "<closeDate>{4}</closeDate>" +
                "<moderationServiceGroup>{5}</moderationServiceGroup>" +
                "</ratingForum>", id, title, parentUri, nameSpace, closingDate.ToString("yyyy-MM-dd"), moderationStatus);

            // Setup the request url
            string url = String.Format("http://" + _server + "/dna/api/comments/ReviewService.svc/V1/site/{0}/", identitySitename);
            // now get the response
            request.RequestPageWithFullURL(url, ratingForumXml, "text/xml");
            // Check to make sure that the page returned with the correct information
            // Check to make sure that the page returned with the correct information
            XmlDocument xml = request.GetLastResponseAsXML();
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaRatingForum);
            validator.Validate();

            BBC.Dna.Api.RatingForum returnedForum = (BBC.Dna.Api.RatingForum)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(BBC.Dna.Api.RatingForum));
            Assert.IsTrue(returnedForum.Id == id);

            Assert.IsTrue(returnedForum.ParentUri == parentUri);
            Assert.IsTrue(returnedForum.Title == title);
            Assert.IsTrue(returnedForum.ModerationServiceGroup == moderationStatus);

            Console.WriteLine("After RatingForumIdentityUserCreate");

            return returnedForum;
        }
Пример #11
0
        /// <summary>
        /// tests successful RatingForumCreate 
        /// </summary>
        public RatingForum RatingForumCreate(string id, ModerationStatus.ForumStatus moderationStatus, DateTime closingDate)
        {
            RatingForum ratingForum = new RatingForum
            {
                Id = id,
                ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                Title = "testratingForum",
                ModerationServiceGroup = moderationStatus,
                CloseDate = closingDate
            };

            RatingForum result = _ratings.RatingForumCreate(ratingForum, site);
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Id == ratingForum.Id);
            Assert.IsTrue(result.ParentUri == ratingForum.ParentUri);
            Assert.IsTrue(result.Title == ratingForum.Title);
            return result;
        }
Пример #12
0
        /// <summary>
        /// tests successful RatingForumCreate 
        /// </summary>
        public RatingForum RatingForumCreate(string id, ModerationStatus.ForumStatus moderationStatus)
        {
            return RatingForumCreate(id, moderationStatus, DateTime.MinValue);

        }
Пример #13
0
        private string PostTweet(Tweet tweet, ModerationStatus.ForumStatus modStatus)
        {
            var request = new DnaTestURLRequest(_sitename);
            var tweetData = CreateTweetJsonData(tweet);

            switch (modStatus)
            {
                case ModerationStatus.ForumStatus.PreMod: request.RequestPageWithFullURL(_tweetPostUrlPremod, tweetData, "application/json"); break;
                case ModerationStatus.ForumStatus.Reactive: request.RequestPageWithFullURL(_tweetPostUrlReactive, tweetData, "application/json"); break;
                default: Assert.Fail("Unknown modStatus setting"); break;
            }

            return request.GetLastResponseAsString();
        }
Пример #14
0
        /// <summary>
        /// Helper method for checking if a user belongs to a given group. This is done by checking the XML for the user
        /// </summary>
        /// <param name="context">The context in which to create the object</param>
        /// <param name="userID">The id of the user you want to check against</param>
        /// <param name="groupToCheck">The group you want tocheck against</param>
        /// <param name="expectedResult">The expected outcome of the test</param>
        private static void CheckUserXML(IInputContext context, int userID, ModerationStatus.UserStatus prefStatus )
        {
            // Create a user object using this userid so we can check that the XML contains the correct group information
            User user = new User(context);
            user.CreateUser(userID);

           /* IDnaDataReader mockedReader = DnaMockery.CurrentMockery.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("UserName").Will(Return.Value("MR TESTER"));
            Stub.On(mockedReader).Method("DoesFieldExist").With("ZeitgeistScore").Will(Return.Value(false));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("FirstNames").Will(Return.Value("MR"));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("LastName").Will(Return.Value("TESTER"));
            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("Status").Will(Return.Value(1));
            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("TaxonomyNode").Will(Return.Value(0));
            Stub.On(mockedReader).Method("GetBoolean").With("Active").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("UserName").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("ZeitgeistScore").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("FirstNames").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("LastName").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("Status").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("TaxonomyNode").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("Active").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Exists").With("SiteSuffix").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Exists").With("Journal").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Exists").With("Area").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Exists").With("Title").Will(Return.Value(false));
            user.AddUserXMLBlock(mockedReader, userID, parentNode); */

            XmlNode parentNode = user.RootElement;

            // Check to see if the user belongs to the group
            /*XmlNode groupNode = parentNode.SelectSingleNode("//GROUPS/GROUP/NAME['" + groupToCheck + "']");

            if (expectedResult)
            {
                Assert.IsNotNull(groupNode, "Failed to find expected group - " + groupToCheck);
            }
            else
            {
                Assert.IsNull(groupNode, "The user should not belong to this group - " + groupToCheck);
            }*/

            //Check Users Pref / /Mod Status
            XmlNode node = parentNode.SelectSingleNode("//USER/MODERATIONSTATUS[@ID=" + (int) prefStatus + "]");
            Assert.IsNotNull(node, "User Pref Status XML Check");
        }