Beispiel #1
0
        public void StartUp()
        {
            Console.WriteLine("StartUp()");
            if (!_setupRun)
            {
                Console.WriteLine("Setting up");


                string rootPath = TestConfig.GetConfig().GetRipleyServerPath();
                BBC.Dna.AppContext.OnDnaStartup(rootPath);

                //Create the mocked inputcontext
                Mockery mock = new Mockery();
                _context = DnaMockery.CreateDatabaseInputContext();

                // Create a mocked site for the context
                ISite mockedSite = DnaMockery.CreateMockedSite(_context, 1, "h2g2", "h2g2", true, "comment");
                Stub.On(_context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));
                Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1));

                Stub.On(_context).Method("FileCacheGetItem").Will(Return.Value(false));
                Stub.On(_context).Method("FileCachePutItem").Will(Return.Value(false));

                // Initialise the profanities object
                var p = new ProfanityFilter(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);
                BBC.Dna.User user = new BBC.Dna.User(_context);
                Stub.On(_context).GetProperty("ViewingUser").Will(Return.Value(user));
                
                _setupRun = true;
            }
            Console.WriteLine("Finished StartUp()");
        }
Beispiel #2
0
        /// <summary>
        /// Constructor for the User Tests to set up the context for the tests
        /// </summary>
        public UserListTests()
        {
            string rootPath = TestConfig.GetConfig().GetRipleyServerPath();
            BBC.Dna.AppContext.OnDnaStartup(rootPath);


            Console.WriteLine("Before RecentSearch - AddRecentSearchTests");

            //Create the mocked _InputContext
            Mockery mock = new Mockery();
            _InputContext = DnaMockery.CreateDatabaseInputContext();

            // Create a mocked site for the context
            ISite mockedSite = DnaMockery.CreateMockedSite(_InputContext, 1, "h2g2", "h2g2", true, "comment");
            Stub.On(_InputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite));
            Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1));


            BBC.Dna.User user = new BBC.Dna.User(_InputContext);
            Stub.On(_InputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(_InputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            //Create sub editor group and users
            //create test sub editors
            DnaTestURLRequest dnaRequest = new DnaTestURLRequest("h2g2");
            dnaRequest.SetCurrentUserEditor();
            TestDataCreator testData = new TestDataCreator(_InputContext);
            int[] userIDs = new int[10];
            Assert.IsTrue(testData.CreateNewUsers(mockedSite.SiteID, ref userIDs), "Test users not created");
            Assert.IsTrue(testData.CreateNewUserGroup(dnaRequest.CurrentUserID, "subs"), "CreateNewUserGroup not created");
            Assert.IsTrue(testData.AddUsersToGroup(userIDs, mockedSite.SiteID, "subs"), "Unable to add users to group not created");


        }
		/// <summary>
		/// Create the XML for the subscribedUsers list
		/// </summary>
		/// <param name="userID">ID of user whose list we want</param>
		/// <param name="skip">skip to this index in the list</param>
		/// <param name="show">show this many items in the list</param>
		/// <returns></returns>
		public bool CreateSubscribingUsersList(int userID, int skip, int show)
		{
			// check object is not already initialised
			if (userID <= 0 || show <= 0)
			{
				return false;
			}

			int count = show;

			XmlElement SubscribingUsersList = AddElementTag(RootElement, "SUBSCRIBINGUSERS-LIST");
			AddAttribute(SubscribingUsersList, "SKIP", skip);
			AddAttribute(SubscribingUsersList, "SHOW", show);

			using (IDnaDataReader dataReader = GetSubscribingUsersList(userID, skip, show + 1))	// Get +1 so we know if there are more left
			{
				// Check to see if we found anything
				string userName = String.Empty;
				if (dataReader.HasRows && dataReader.Read())
				{
					User subscribedTo = new User(InputContext);
                    subscribedTo.AddPrefixedUserXMLBlock(dataReader, userID, "subscribedTo", SubscribingUsersList);

                    _userAcceptsSubscriptions = dataReader.GetBoolean("SubscribedToAcceptSubscriptions");
                    
                    //Get the list from the second recordset
                    dataReader.NextResult();
                    if (dataReader.HasRows && dataReader.Read())
                    {
                        XmlElement users = CreateElement("USERS");
                        do
                        {
                            User subscribingUser = new User(InputContext);
                            int subscribingUserID = dataReader.GetInt32NullAsZero("UserID");

                            subscribingUser.AddUserXMLBlock(dataReader, subscribingUserID, users);

                            count--;

                        } while (count > 0 && dataReader.Read());	// dataReader.Read won't get called if count == 0

                        SubscribingUsersList.AppendChild(users);

                        // See if there's an extra row waiting
                        if (count == 0 && dataReader.Read())
                        {
                            AddAttribute(SubscribingUsersList, "MORE", 1);
                        }
                    }
				}
			}
			//AddAttribute(UserSubscriptionsList, "COUNT", count);

			return true;
		}
Beispiel #4
0
        public void AddRecentSearchTests()
        {
            string rootPath = TestConfig.GetConfig().GetRipleyServerPath();
            BBC.Dna.AppContext.OnDnaStartup(rootPath);



            Console.WriteLine("Before RecentSearch - AddRecentSearchTests");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            Stub.On(context).Method("GetParamIntOrZero").WithAnyArguments().Will(Return.Value(0));

            // Create a mocked site for the context
            ISite mockedSite = DnaMockery.CreateMockedSite(context, 70, "mbiplayer", "mbiplayer", true, "comment");//changed to miss cache
            Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));
            Stub.On(context).Method("DoesParamExist").With("forumid", "forumid").Will(Return.Value(false));
            Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1));


            BBC.Dna.User user = new BBC.Dna.User(context);
            Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));


            // Initialise the profanities object
            var p = new ProfanityFilter(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);

            RecentSearch recentsearch = new RecentSearch(context);
            Assert.IsTrue(recentsearch.AddSearchTerm("test article", RecentSearch.SEARCHTYPE.ARTICLE),"Adding valid artical search");
            Assert.IsTrue(recentsearch.AddSearchTerm("test forum", RecentSearch.SEARCHTYPE.FORUM), "Adding valid forum search");
            Assert.IsFalse(recentsearch.AddSearchTerm("This contains the profanity f**k", RecentSearch.SEARCHTYPE.ARTICLE), "Failing to add search term with profanity");
            Assert.IsFalse(recentsearch.AddSearchTerm("This contains the an email - [email protected]", RecentSearch.SEARCHTYPE.ARTICLE), "Failing to add search term with email");


            recentsearch.ProcessRequest();
            XmlElement xml = recentsearch.RootElement;
            Assert.IsTrue(xml.SelectSingleNode("RECENTSEARCHES") != null, "The xml is not generated correctly!!!");
          
            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri);
            validator.Validate();

            Console.WriteLine("after RecentSearch - AddRecentSearchTests");
        }
        public void GetSubNotificationEmailTest()
        {
            string rootPath = TestConfig.GetConfig().GetRipleyServerPath();
            BBC.Dna.AppContext.OnDnaStartup(rootPath);

            Console.WriteLine("Before SubNotificationEmailTests - GetSubNotificationEmailTest");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            // Create a mocked site for the context
            ISite mockedSite = DnaMockery.CreateMockedSite(context, 1, "h2g2", "h2g2", true, "comment");
            Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));
            Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1));


            BBC.Dna.User user = new BBC.Dna.User(context);
            Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            CreateAndRecommendAndAllocateArticle(context);

            SubNotificationEmail subNotificationEmail = new SubNotificationEmail(context);
            bool toSend = false;
            string emailAddress = String.Empty;
            string emailSubject = String.Empty;
            string emailText = String.Empty;

            subNotificationEmail.CreateNotificationEmail(6, ref toSend, ref emailAddress, ref emailSubject, ref emailText);

            XmlElement xml = subNotificationEmail.RootElement;
            Assert.IsTrue(xml.SelectSingleNode("EMAIL") != null, "The xml is not generated correctly!!!");

            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri);
            validator.Validate();

            Console.WriteLine("After SubNotificationEmailTests - GetSubNotificationEmailTest");
        }
Beispiel #6
0
        public void Test08GetUITemplateForValidationParamsWithProfanity()
        {
            Console.WriteLine("Before Test08GetUITemplateForValidationParamsWithProfanity");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = DnaMockery.CreateDatabaseInputContext();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            Stub.On(site).GetProperty("ModClassID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the site options for the new mocked site
            SiteOptionList siteOptionList = new SiteOptionList();
            siteOptionList.CreateFromDatabase(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default);
            siteOptionList.SetValueBool(1, "Forum", "EmailAddressFilter", true, DnaMockery.CreateDatabaseReaderCreator(), null);
            siteOptionList.SetValueBool(1, "General", "IsURLFiltered", true, DnaMockery.CreateDatabaseReaderCreator(), null);

            // Stub the call to the siteoption
            Stub.On(mockedInputContext).Method("GetSiteOptionValueBool").With("Forum", "EmailAddressFilter").Will(Return.Value(true));
            // Stub the call to the siteoption
            Stub.On(mockedInputContext).Method("GetSiteOptionValueBool").With("General", "IsURLFiltered").Will(Return.Value(true));

            // Initialise the profanities object
            var p = new ProfanityFilter(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);

            using (IDnaDataReader reader = mockedInputContext.CreateDnaDataReader("getuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = _createdUITemplateID;
                testUITemplate.LoadTemplate();
                List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>();

                KeyValuePair<string, string> subject = new KeyValuePair<string, string>("SUBJECT", "TestSubject");
                parameters.Add(subject);
                KeyValuePair<string, string> description = new KeyValuePair<string, string>("Description", "TestDescription with f**k");
                parameters.Add(description);

                testUITemplate.ProcessParameters(parameters);

                testUITemplate.Validate();

                DnaXmlValidator validator = new DnaXmlValidator(testUITemplate.RootElement.InnerXml, _schemaUri);
                validator.Validate();
            }
            Console.WriteLine("After Test08GetUITemplateForValidationParamsWithProfanity");
        }
Beispiel #7
0
        public void Test06GetIncorrectUITemplate()
        {
            Console.WriteLine("Before Test06GetIncorrectUITemplate");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the UITemplate object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("getuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = 999999999;
                testUITemplate.LoadTemplate();

                Assert.IsTrue(testUITemplate.HasErrors, "The template should return an error.");
            }
            Console.WriteLine("After Test06GetIncorrectUITemplate");
        }
Beispiel #8
0
        public void Test02GetUITemplate()
        {
            Console.WriteLine("Before Test02GetUITemplate");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the UITemplate object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("getuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = _createdUITemplateID;
                testUITemplate.LoadTemplate();

                DnaXmlValidator validator = new DnaXmlValidator(testUITemplate.RootElement.InnerXml, _schemaUri);
                validator.Validate();
            }
            Console.WriteLine("After Test02GetUITemplate");
        }
Beispiel #9
0
        /// <summary>
        /// Initialises a new default user from a sso uid
        /// </summary>
        public void InitUserFromCookie(string identity, string identityHttps)
        {
            if (_identityCookie == null)
            {
                _identityCookie = new DnaCookie(new System.Web.HttpCookie("IDENTITY"));
                _identitySecureCookie = new DnaCookie(new System.Web.HttpCookie("IDENTITY-HTTPS"));
            }
            _identityCookie.Value = identity;
            _identitySecureCookie.Value = identityHttps;

            _viewingUser = new BBC.Dna.User(this);
            _viewingUser.CreateUser();
        }
Beispiel #10
0
        /// <summary>
        /// Sets the editor XML from the given dataReader
        /// </summary>
        /// <param name="dataReader">DataReader contain the row with the editor user columns</param>
        public void SetEditor(IDnaDataReader dataReader)
        {
            string editor = dataReader.GetStringNullAsEmpty("editor");
            int editorID = 0;
            Int32.TryParse(editor, out editorID);

            _editor.RemoveAll();
            _editor = CreateElement("Editor");

            User editorUser = new User(InputContext);
            editorUser.AddPrefixedUserXMLBlock(dataReader, editorID, "editor", _editor);
        }
Beispiel #11
0
        /// <summary>
        /// Produce XML for users posts tagged to the specified node.
        /// </summary>
        /// <param name="nodeID">The node ID in question</param>
        /// <returns>An XML Element contain the list of users for a node</returns>
        public XmlElement GetUsersForNodeID(int nodeID)
        {
            // Check the NodeID!
            if (nodeID == 0)
            {
                throw new DnaException("Category - NoNodeIDGiven - Illegal NodeID (0)");
            }

            XmlElement userMemberList = CreateElement("USERMEMBERLIST");
            // Now get the list for the given list id
            using (IDnaDataReader reader = InputContext.CreateDnaDataReader("getusersfornode"))
            {
                reader.AddParameter("nodeID", nodeID);
                reader.AddParameter("siteID", InputContext.CurrentSite.SiteID);
                reader.Execute();

                if (reader.HasRows)
                {
                    int userMemberCount = 0;
                    while (reader.Read())
                    {                      
                        User user = new User(InputContext);
                        int userID = reader.GetInt32NullAsZero("UserID");
                        user.AddUserXMLBlock(reader, userID, userMemberList);

                        userMemberCount++;
                    }
                    AddIntElement(userMemberList, "USERMEMBERCOUNT", userMemberCount);
                }
            }
            return userMemberList;
        }
Beispiel #12
0
        /// <summary>
        /// This method gets all the related articles for a given article h2g2ID
        /// </summary>
        /// <param name="h2g2ID">The id of the article you want to get the related articles for</param>
        public void GetRelatedArticles(int h2g2ID)
        {
            // Create the datareader to get the articles
            using (IDnaDataReader reader = InputContext.CreateDnaDataReader("getrelatedarticles"))
            {
                reader.AddParameter("h2g2ID", h2g2ID);
                reader.AddParameter("CurrentSiteID", 0);
                reader.Execute();

                XmlNode relatedArticlesNode = AddElementTag(RootElement, "RELATEDARTICLES");

                // Add each article in turn
                while (reader.Read())
                {
                    XmlNode relatedArticleNode = AddElementTag(relatedArticlesNode, "ARTICLEMEMBER");
                    AddIntElement(relatedArticleNode, "H2G2ID", h2g2ID);
                    string articleName = reader.GetString("Subject");
                    AddTextElement((XmlElement)relatedArticleNode, "NAME", articleName);
                    if (_includeStrippedNames)
                    {
                        string strippedName = StringUtils.StrippedName(articleName);
                        AddTextElement((XmlElement)relatedArticleNode, "STRIPPEDNAME", strippedName);
                    }
                    XmlNode userNode = AddElementTag(relatedArticleNode, "EDITOR");
                    User articleEditor = new User(InputContext);
                    articleEditor.AddPrefixedUserXMLBlock(reader, reader.GetInt32("Editor"), "Editor", userNode);
                    int status = reader.GetInt32("Status");
                    XmlNode statusNode = AddTextElement((XmlElement)relatedArticleNode, "STATUS", GuideEntry.GetDescriptionForStatusValue(status));
                    AddAttribute(statusNode, "TYPE", status);
                    ExtraInfo articleExtraInfo = new ExtraInfo();
                    int articleType = reader.GetInt32("Type");
                    int articleHidden = 0;
                    if (reader.Exists("Hidden") && !reader.IsDBNull("Hidden"))
                    {
                        articleHidden = reader.GetInt32("Hidden");
                    }
                    
                    // Create and add the article extra info
                    articleExtraInfo.TryCreate(articleType, reader.GetString("ExtraInfo"));
                    AddInside(relatedArticleNode, articleExtraInfo);

                    if (reader.Exists("DateCreated"))
                    {
                        XmlNode dateCreatedNode = AddElementTag(relatedArticleNode, "DATECREATED");
                        dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true));
                    }
                    if (reader.Exists("Lastupdated"))
                    {
                        XmlNode dateCreatedNode = AddElementTag(relatedArticleNode, "LASTUPDATE");
                        dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true));
                    }

                    // NOW ADD KEYPHRASES, MEDIA ASSETS, POLLS
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// CreateLinkXML from a dataReader.
        /// Allows standard Link XML to be generated from different resultsets.
        /// </summary>
        /// <param name="dataReader"></param>
        /// <param name="parent"></param>
        /// <param name="createAuthorXML"></param>
        /// <param name="createSubmitterXML"></param>
        /// <returns></returns>
        public void CreateLinkXML(IDnaDataReader dataReader, XmlNode parent, bool createSubmitterXML, bool createAuthorXML )
        {
            RootElement.RemoveAll();
            String type = dataReader.GetStringNullAsEmpty("destinationtype");
            XmlNode link = CreateElementNode("LINK");
            AddAttribute(link, "TYPE", type);
            AddAttribute(link, "LINKID", dataReader.GetInt32NullAsZero("linkid"));
            AddAttribute(link, "TEAMID", dataReader.GetInt32NullAsZero("teamid"));
            AddAttribute(link, "RELATIONSHIP", dataReader.GetStringNullAsEmpty("relationship"));
            AddAttribute(link, "PRIVATE", dataReader.GetTinyIntAsInt("private"));

            //Create appropriate URL from link type. 
            int destinationId = dataReader.GetInt32NullAsZero("DestinationID");
            switch (type)
            {
                case "article"  :
                {
                    AddAttribute(link, "DNAUID", "A" + destinationId );
                    break;
                }
                case "userpage" :
                {
                    AddAttribute(link, "DNAUID", "U" + destinationId);
                    break;
                }
                case "category" :
                {
                    AddAttribute(link, "DNAUID", "C" + destinationId);
                    break;
                }
                case "forum" :
                {
                    AddAttribute(link, "DNAUID", "F" + destinationId);
                    break;
                }
                case "thread" :
                {
                     AddAttribute(link, "DNAUID", "T" + destinationId);
                    break;
                }
                case "posting" :
                {
                    AddAttribute(link, "DNAUID", "TP" + destinationId);
                    break;
                }
                default : // "club" )
                {
                    AddAttribute(link, "DNAUID", "G" + destinationId);
                    break;
                }
            }

            //AddTextTag(link, "TITLE", dataReader.GetStringNullAsEmpty("title"));
            AddTextTag(link, "DESCRIPTION", dataReader.GetStringNullAsEmpty("linkdescription"));
            
            //Create Submitter XML if required .
            if ( createSubmitterXML )
            {
                int submitterId = dataReader.GetInt32NullAsZero("submitterid");
                if (submitterId > 0)
                {
                    XmlNode submitterXML = AddElementTag(link, "SUBMITTER");
                    User submitter = new User(InputContext);
                    submitter.AddPrefixedUserXMLBlock(dataReader, submitterId, "submitter", submitterXML);
                }
            }

            //Create author XML if required.
            if (createAuthorXML)
            {
                int authorId = dataReader.GetInt32NullAsZero("authorid");
                if (authorId > 0)
                {
                    XmlNode authorXML = AddElementTag(link, "AUTHOR");
                    User author = new User(InputContext);
                    author.AddPrefixedUserXMLBlock(dataReader, authorId, "author", authorXML);
                }
            }

            if (!dataReader.IsDBNull("datelinked"))
                AddDateXml(dataReader.GetDateTime("datelinked"),link,"DATELINKED");
            if ( !dataReader.IsDBNull("lastupdated") )
                AddDateXml(dataReader.GetDateTime("lastupdated"),link,"LASTUPDATED");

            XmlNode importXml = parent.OwnerDocument.ImportNode(link, true);
            parent.AppendChild(importXml);
        }
Beispiel #14
0
        /// <summary>
        /// Helper method to create the list after a specific stored procedure
        ///		has been called to return an appropriate results set.
        /// </summary>
        /// <param name="dataReader">The data reader containing results</param>
        /// <param name="userlistXML">returned XmlElement</param>
        /// <param name="maxNumber">max number of rows to add</param>
        /// <param name="skip">number of rows to skip</param>
        /// <returns>true if successful, false if not.</returns>
        private bool CreateList(IDnaDataReader dataReader, ref XmlElement userlistXML, int maxNumber, int skip)
        {
            if (!dataReader.HasRows)
            {
                return false;
            }

            int numberShown = 0;

            if (skip > 0)
            {
                //Read/skip over the skip number of rows
                for (int i = 0; i < skip; i++)
                {
                    dataReader.Read();
                }
            }

            //add rows, assume that sp has limited the amount returned
            while (maxNumber > numberShown && dataReader.Read())           
            {
                User user = new User(InputContext);
                user.AddUserXMLBlock(dataReader, dataReader.GetInt32NullAsZero("USERID"), userlistXML);

                numberShown++;
            } 

            if (dataReader.Read())
            {
                AddAttribute(userlistXML, "MORE", 1);
            }

            AddAttribute(userlistXML, "COUNT", numberShown);

            return true;
        }
Beispiel #15
0
        public void Test01CreateUITemplate()
        {
            Console.WriteLine("Before Test01CreateUITemplate");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the UITemplate object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("createuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("createuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = 0;
                XmlDocument templateDoc = new XmlDocument();
                templateDoc.LoadXml(_testTemplateXML);

                XmlElement test = ((XmlElement)templateDoc.SelectSingleNode("H2G2/UITEMPLATE"));
                test.SetAttribute("UITEMPLATEID", _createdUITemplateID.ToString());

                test = ((XmlElement)templateDoc.SelectSingleNode("H2G2/UITEMPLATE/NAME"));
                test.InnerText = test.InnerText + DateTime.Now.ToString();

                testUITemplate.SaveTemplate((XmlElement)templateDoc.FirstChild.FirstChild);
                _createdUITemplateID = testUITemplate.UITemplateID;

                DnaXmlValidator validator = new DnaXmlValidator(testUITemplate.RootElement.InnerXml, _schemaUri);
                validator.Validate();
            }
            Console.WriteLine("After Test01CreateUITemplate");
        }
        private void CreateFormXml(IDnaDataReader dataReader, string comments, bool acceptButton, bool rejectButton, bool cancelButton, bool fetchButton, bool byRecommendationID)
        {
            RootElement.RemoveAll();
            _processRecommendationForm = AddElementTag(RootElement, "PROCESS-RECOMMENDATION-FORM");

            int recommendationID = dataReader.GetInt32NullAsZero("recommendationID");
            int h2g2ID = dataReader.GetInt32NullAsZero("h2g2ID");
            int entryID = dataReader.GetInt32NullAsZero("entryID");
            string entrySubject = dataReader.GetStringNullAsEmpty("Subject");

            int editorID = dataReader.GetInt32NullAsZero("EditorID");
            string editorName = dataReader.GetStringNullAsEmpty("EditorName");
            User editor = new User(InputContext);

            int scoutID = dataReader.GetInt32NullAsZero("ScoutID");
            string scoutName = dataReader.GetStringNullAsEmpty("ScoutName");
            User scout = new User(InputContext);

            DateTime dateRecommended = dataReader.GetDateTime("DateRecommended");
            string retrievedComments = dataReader.GetStringNullAsEmpty("Comments");

            AddIntElement(_processRecommendationForm, "RECOMMENDATION-ID", recommendationID);
            AddIntElement(_processRecommendationForm, "H2G2-ID", h2g2ID);
            AddTextTag(_processRecommendationForm, "SUBJECT", entrySubject);
            AddTextTag(_processRecommendationForm, "COMMENTS", retrievedComments);

            XmlElement editorElement = AddElementTag(_processRecommendationForm, "EDITOR");
            editor.AddPrefixedUserXMLBlock(dataReader, editorID, "editor", editorElement);

            XmlElement scoutElement = AddElementTag(_processRecommendationForm, "SCOUT");
            scout.AddPrefixedUserXMLBlock(dataReader, scoutID, "scout", scoutElement);

            AddDateXml(dateRecommended, _processRecommendationForm, "DATE-RECOMMENDED");

            // if we know what the decision is going to be then create an appropriate
            // default email to send
            string scoutEmailSubject = String.Empty;
            string scoutEmailText = String.Empty;
            string authorEmailSubject = String.Empty;
            string authorEmailText = String.Empty;

            if (acceptButton && !rejectButton)
            {
                CreateScoutAcceptanceEmail(scoutName, entrySubject, h2g2ID, dateRecommended, ref scoutEmailSubject, ref scoutEmailText);
                if (byRecommendationID)
                {
                    CreateAuthorAcceptanceEmail(editorName, entrySubject, h2g2ID, dateRecommended, ref authorEmailSubject, ref authorEmailText);
                }
            }
            else if (rejectButton && !acceptButton)
            {
                CreateScoutRejectionEmail(scoutName, entrySubject, h2g2ID, dateRecommended, ref scoutEmailSubject, ref scoutEmailText);
            }

            if (byRecommendationID)
            {
                XmlElement scoutEmail = AddElementTag(_processRecommendationForm, "SCOUT-EMAIL");
                AddTextTag(scoutEmail, "SUBJECT", scoutEmailSubject);
                AddTextTag(scoutEmail, "TEXT", scoutEmailText);

                XmlElement authorEmail = AddElementTag(_processRecommendationForm, "AUTHOR-EMAIL");
                AddTextTag(authorEmail, "SUBJECT", authorEmailSubject);
                AddTextTag(authorEmail, "TEXT", authorEmailText);
            }
            else
            {
                AddTextTag(_processRecommendationForm, "EMAIL-SUBJECT", scoutEmailSubject);
                AddTextTag(_processRecommendationForm, "EMAIL-TEXT", scoutEmailText);
            }

            XmlElement functions = AddElementTag(_processRecommendationForm, "FUNCTIONS");
            if (acceptButton)
            {
                AddElementTag(functions, "ACCEPT");
            }
            if (rejectButton)
            {
                AddElementTag(functions, "REJECT");
            }
            if (cancelButton)
            {
                AddElementTag(functions, "CANCEL");
            }
            if (fetchButton)
            {
                AddElementTag(functions, "FETCH");
            }
        }
Beispiel #17
0
        private void GenerateXml(IDnaDataReader reader, int h2g2Id, int postId, string exLinkUrl)
        {
            XmlElement modHistory = AddElementTag(RootElement, "MODERATION-HISTORY");
            reader.Read();

            if (h2g2Id > 0)
                AddAttribute(modHistory, "H2G2ID", h2g2Id);
            else if (postId > 0)
            {
                AddAttribute(modHistory, "POSTID", postId);
                if ( reader.HasRows )
                {
                    AddAttribute(modHistory, "FORUMID", reader.GetInt32NullAsZero("forumid") );
                    AddAttribute(modHistory, "THREADID", reader.GetInt32NullAsZero("threadid") );
                }
            }
            else if (exLinkUrl != String.Empty)
                AddAttribute(modHistory, "EXLINKURL", exLinkUrl );

            if (reader.HasRows)
            {
                int rowCount = 0;
                do
                {
                    if (rowCount == 0)
                    {
                        AddXmlTextTag(modHistory, "SUBJECT", reader.GetStringNullAsEmpty("subject"));

                        if (reader.DoesFieldExist("authoruserid") && !reader.IsDBNull("authoruserid"))
                        {
                            XmlElement editorNode = AddElementTag(modHistory, "EDITOR");
                            User editor = new User(InputContext);
                            editor.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("authoruserid"), "Author", editorNode);
                        }
                    }

                    XmlElement moderation = AddElementTag(modHistory, "MODERATION");
                    AddAttribute(moderation, "MODID", reader.GetInt32NullAsZero("modid"));
                    AddIntElement(moderation, "STATUS", reader.GetInt32NullAsZero("status"));
                    AddTextElement(moderation, "URLNAME", InputContext.TheSiteList.GetSite(reader.GetInt32NullAsZero("siteid")).SiteName);
                    if (reader.DoesFieldExist("reasonid") && reader.GetInt32NullAsZero("reasonid") > 0)
                    {
                        AddIntElement(moderation, "REASONID", reader.GetInt32NullAsZero("reasonid"));
                    }

                    User user = new User(InputContext);

                    if ( !reader.IsDBNull("lockedbyuserid") )
                    {
                        XmlElement locked = AddElementTag(moderation, "LOCKED-BY");
                        user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("LockedBy"), "lockedby", locked);
                    }

                    if (!reader.IsDBNull("referredbyuserid"))
                    {
                        XmlElement referred = AddElementTag(moderation, "REFERRED-BY");
                        user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("referredbyuserid"), "referredby", referred);
                    }

                    XmlElement complaint = AddElementTag(moderation, "COMPLAINT");
                    AddTextElement(complaint, "COMPLAINT-TEXT", reader.GetStringNullAsEmpty("complainttext"));

                    if (reader.DoesFieldExist("complainantuserid") && !reader.IsDBNull("complainantuserid"))
                    {
                        user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("complainantuserid"), "complainant", complaint);
                    }

                    AddTextElement(complaint, "IPADDRESS", reader.GetStringNullAsEmpty("ipaddress"));
                    AddTextElement(complaint, "BBCUID", reader.GetGuidAsStringOrEmpty("bbcuid").ToString());
                    AddTextElement(complaint, "EMAIL-ADDRESS", reader.GetStringNullAsEmpty("correspondenceemail"));
                    AddTextElement(moderation, "NOTES", HtmlUtils.ReplaceCRsWithBRs(reader.GetStringNullAsEmpty("notes")));

                    AddDateXml(reader.GetDateTime("datequeued"), moderation, "DATE-QUEUED");
                    if (!reader.IsDBNull("datelocked"))
                    {
                        AddDateXml(reader.GetDateTime("datelocked"), moderation, "DATE-LOCKED");
                    }

                    if (!reader.IsDBNull("datereferred"))
                    {
                        AddDateXml(reader.GetDateTime("datereferred"), moderation, "DATE-REFERRED");
                    }

                    if (!reader.IsDBNull("datecompleted"))
                    {
                        AddDateXml(reader.GetDateTime("datecompleted"), moderation, "DATE-COMPLETED");
                    }

                    ++rowCount;
                }
                while (reader.Read());
            }
        }