Ejemplo n.º 1
0
        public void EnsureValidH2G2IDSucceedsToCreate()
        {
            // Create a mockery of the input context
            Mockery mockery = new Mockery();
            IInputContext mockedContext = mockery.NewMock<IInputContext>();

            IDnaDataReader mockedReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("AddParameter").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).GetProperty("HasRows").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Read").Will(Return.Value(true));
            
            // Set the expiry date to be 1 minute from now
            Stub.On(mockedReader).Method("GetInt32").With("seconds").Will(Return.Value(60));
            Stub.On(mockedReader).Method("Dispose").Will(Return.Value(null));

            Stub.On(mockedContext).Method("CreateDnaDataReader").With("cachegetarticleinfo").Will(Return.Value(mockedReader));

            // Return false for now as it's bloody inpossible to test methods that use ref params!!!
            Stub.On(mockedContext).Method("FileCacheGetItem").Will(Return.Value(false));

            // Now create the setup object and create the guideentry
            GuideEntrySetup setup = new GuideEntrySetup(388217);
            GuideEntry testEntry = new GuideEntry(mockedContext, setup);

            // Test the initialisation code.
            Assert.IsTrue(testEntry.Initialise(), "Valid h2g2id should return true!");
        }
Ejemplo n.º 2
0
        public void EnsureInvalidH2G2IDFailsToCreate()
        {
            // Create a mockery of the input context
            Mockery mockery = new Mockery();
            IInputContext mockedContext = mockery.NewMock<IInputContext>();

            // Now create the setup object and create the guideentry
            GuideEntrySetup setup = new GuideEntrySetup(123456789);
            GuideEntry testEntry = new GuideEntry(mockedContext, setup);

            // Test the initialisation code.
            Assert.IsFalse(testEntry.Initialise(), "Invalid h2g2id should return false!");
        }
Ejemplo n.º 3
0
        /*		    <FORUMSOURCE>
                        <JOURNAL>
                            <USER>
                                <USERID>6</USERID>
                                <USERNAME>Jim Lynn</USERNAME>
                            </USER>
                        </JOURNAL>
                    </FORUMSOURCE>
    				
                    or

                    <FORUMSOURCE>
                        <ARTICLE>
                            <H2G2ID>12345</H2G2ID>
                            <SUBJECT>Hello there</SUBJECT>
                        </ARTICLE>
                    </FORUMSOURCE>

                    or

                    <FORUMSOURCE>
                        <USERPAGE>
                            <USER>
                                <USERID>6</USERID>
                                <USERNAME>Jim Lynn</USERNAME>
                            </USER>
                        </USERPAGE>
                    </FORUMSOURCE>

                    or 

                    <FORUMSOURCE>
                        <CLUB ID= '1'>
                            <NAME>Dharmesh Club</NAME>
                        </CLUB>
                    </FORUMSOURCE> 
         */
        /// <summary>
        /// Builds an XML representation of the forum source, vis:
        /// </summary>
        /// <param name="forumID">ID of forum</param>
        /// <param name="threadID">ID of forum thread</param>
        /// <param name="includeArticle">flag to include article data</param>
        /// <param name="type">Type of forum</param>
        /// <param name="ID">ID either H2G2ID or club ID</param>
        /// <param name="title">Title</param>
        /// <param name="siteID">Site ID</param>
        /// <param name="url">URL involved</param>
        public void GetTitle(int forumID, int threadID, bool includeArticle, ref int type, ref int ID, ref string title, ref int siteID, ref string url)
        {
            string subject = "";	// Subject based on type found
            int userID = 0;
            int reviewForumID = 0;
            int alertInstantly = 0;
            int hiddenStatus = 0;
            int articleStatus = 0;
            int realForumID = 0;

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("getforumsource"))
            {
                dataReader.AddParameter("ForumID", forumID);
                dataReader.AddParameter("ThreadID", threadID);
                dataReader.AddParameter("CurrentSiteID", InputContext.CurrentSite.SiteID);
                dataReader.Execute();

                if (dataReader.HasRows && dataReader.Read())
                {
                    // Fill in return values
                    ID = dataReader.GetInt32NullAsZero("h2g2ID");
                    type = dataReader.GetInt32NullAsZero("Type");
                    hiddenStatus = dataReader.GetInt32NullAsZero("HiddenStatus");
                    articleStatus = dataReader.GetInt32NullAsZero("ArticleStatus");
                    alertInstantly = dataReader.GetInt32NullAsZero("AlertInstantly");
                    siteID = dataReader.GetInt32NullAsZero("SiteID");
                    realForumID = dataReader.GetInt32NullAsZero("ForumID");

                    reviewForumID = 0;
                    userID = 0;

                    if (dataReader.GetInt32NullAsZero("JournalOwner") > 0)
                    {
                        title = dataReader.GetStringNullAsEmpty("JournalUserName");
                        userID = dataReader.GetInt32NullAsZero("JournalOwner");
                    }
                    else if (dataReader.GetInt32NullAsZero("UserID") > 0)
                    {
                        title = dataReader.GetStringNullAsEmpty("UserName");
                        userID = dataReader.GetInt32NullAsZero("UserID");
                    }
                    else if (!dataReader.IsDBNull("ReviewForumID"))
                    {
                        title = dataReader.GetStringNullAsEmpty("ReviewForumName");
                        reviewForumID = dataReader.GetInt32NullAsZero("ReviewForumID");
                    }
                    else if (!dataReader.IsDBNull("URL"))
                    {
                        url = dataReader.GetStringNullAsEmpty("URL");
                    }
                    else
                    {
                        title = dataReader.GetStringNullAsEmpty("Subject");
                    }

                    XmlElement forumSource = AddElementTag(RootElement, "FORUMSOURCE");

                    if (type == 0)
                    {
                        AddAttribute(forumSource, "TYPE", "journal");

                        User journalOwner = new User(InputContext);
                        journalOwner.AddPrefixedUserXMLBlock(dataReader, userID, "Journal", forumSource);
                    }
                    else if (type == 3)
                    {
                        // It's a review forum
                        AddAttribute(forumSource, "TYPE", "reviewforum");

                        XmlElement reviewForum = AddElementTag(forumSource, "REVIEWFORUM");
                        AddAttribute(reviewForum, "ID", reviewForumID);
                        AddTextTag(reviewForum, "REVIEWFORUMNAME", subject);
                        AddTextTag(reviewForum, "URLFRIENDLYNAME", "RF" + reviewForumID.ToString());
                    }
                    else if (type == 1)
                    {
                        AddAttribute(forumSource, "TYPE", "article");
                    }
                    /*else if (type == 5)
                    {
                        AddAttribute(forumSource, "TYPE", "club");

                        XmlElement club = AddElementTag(forumSource, "CLUB");
                        AddAttribute(club, "ID", clubID);
                        AddTextTag(club, "NAME", subject);
                    }
                    else if (type == 6)
                    {
                        AddAttribute(forumSource, "TYPE", "clubforum");

                        XmlElement club = AddElementTag(forumSource, "CLUB");
                        AddAttribute(club, "ID", clubID);
                        AddTextTag(club, "NAME", subject);
                    }
                    else if (type == 7)
                    {
                        AddAttribute(forumSource, "TYPE", "clubjournal");

                        XmlElement club = AddElementTag(forumSource, "CLUB");
                        AddAttribute(club, "ID", clubID);
                        AddTextTag(club, "NAME", subject);
                    }*/
                    else if (type == 4)
                    {
                        AddAttribute(forumSource, "TYPE", "privateuser");
                        XmlElement userPage = AddElementTag(forumSource, "USERPAGE");
                        User user = new User(InputContext);
                        user.AddUserXMLBlock(dataReader, userID, userPage);
                    }
                    else if (type == 8)
                    {
                        AddAttribute(forumSource, "TYPE", "noticeboard");
                    }
                    else
                    {
                        AddAttribute(forumSource, "TYPE", "userpage");
                        XmlElement userPage = AddElementTag(forumSource, "USERPAGE");
                        User user = new User(InputContext);
                        user.AddUserXMLBlock(dataReader, userID, userPage);
                    }

                    if (ID > 0)
                    {
                        if (includeArticle)
                        {
                            GuideEntrySetup guideEntrySetup = new GuideEntrySetup(ID);
                            guideEntrySetup.ShowEntryData = true;
                            guideEntrySetup.ShowPageAuthors = true;
                            guideEntrySetup.ShowReferences = true;
                            guideEntrySetup.SafeToCache = true;

                            GuideEntry guideEntry = new GuideEntry(InputContext, guideEntrySetup);
                            if (!guideEntry.Initialise())
                            {
                                throw new DnaException("The article doesn't exist. " + ID.ToString());
                            }

                            if (!guideEntry.IsDeleted)
                            {
                                AddInside(guideEntry, "FORUMSOURCE");
                                XmlElement article = (XmlElement)forumSource.SelectSingleNode("ARTICLE");
                                AddIntElement(article, "H2G2ID", ID);
                            }
                            else
                            {
                                XmlElement deletedArticle = AddElementTag(forumSource, "ARTICLE");
                                AddIntElement(deletedArticle, "H2G2ID", ID);
                                AddTextTag(deletedArticle, "SUBJECT", "Deleted");
                                AddIntElement(deletedArticle, "HIDDEN", hiddenStatus);
                                XmlNode statusNode = AddTextTag(deletedArticle, "STATUS", GuideEntry.GetDescriptionForStatusValue(articleStatus));
                                AddAttribute(statusNode, "TYPE", articleStatus);
                            }
                        }
                        else
                        {
                            XmlElement defaultArticle = AddElementTag(forumSource, "ARTICLE");
                            AddIntElement(defaultArticle, "H2G2ID", ID);
                            AddTextTag(defaultArticle, "SUBJECT", subject);
                            AddIntElement(defaultArticle, "HIDDEN", hiddenStatus);
                            XmlNode statusNode = AddTextTag(defaultArticle, "STATUS", GuideEntry.GetDescriptionForStatusValue(articleStatus));
                            AddAttribute(statusNode, "TYPE", articleStatus);
                        }

                        AddIntElement(forumSource, "ALERTINSTANTLY", alertInstantly);
                    }
                }
            }
        }