public void Test03RequestHierarchyPage()
 {
     Console.WriteLine("Test03RequestHierarchyPage");
     XmlDocument xmldoc = new XmlDocument();
     DnaTestURLRequest request = new DnaTestURLRequest("haveyoursay");
     try
     {
         request.RequestAspxPage("HierarchyPage.aspx", "_si=actionnetwork&skin=purexml");
         xmldoc.LoadXml(request.GetLastResponseAsString());
     }
     catch (Exception e)
     {
         System.Console.Write(e.Message + request.GetLastResponseAsString());
         //Assert.Fail(e.Message + _asphost.ResponseString);
     }
     Assert.IsNotNull(xmldoc.SelectSingleNode("//HIERARCHYNODES"), "Expected a HIERARCHYNODES XML Tag!!!");
     Assert.AreEqual("16", xmldoc.SelectSingleNode("//HIERARCHYNODES").Attributes["SITEID"].Value, "Incorrect site id in XML");
 }
 public void Test04RequestHierarchyPageForSiteWithNoHierarchy()
 {
     Console.WriteLine("Test04RequestHierarchyPageForSiteWithNoHierarchy");
     XmlDocument xmldoc = new XmlDocument();
     DnaTestURLRequest request = new DnaTestURLRequest("haveyoursay");
     try
     {
         request.RequestAspxPage("HierarchyPage.aspx", "_si=mb606&skin=purexml");
         xmldoc.LoadXml(request.GetLastResponseAsString());
     }
     catch (Exception e)
     {
         System.Console.Write(e.Message + request.GetLastResponseAsString());
         //Assert.Fail(e.Message + _asphost.ResponseString);
     }
     
     Assert.IsNotNull(xmldoc.SelectSingleNode("//ERROR"), "Expected an error tag!!!");
     Assert.AreEqual("nohierarchydata", xmldoc.SelectSingleNode("//ERROR").Attributes["TYPE"].Value, "Make sure the error returned is of type nohierarchydata");
 }
 public void Test05RequestHierarchyPageForActionNetwork()
 {
     Console.WriteLine("Test05RequestHierarchyPageForActionNetwork");
     DnaTestURLRequest request = new DnaTestURLRequest("actionnetwork");
     request.RequestAspxPage("HierarchyPage.aspx", @"s_popup=1");
    
     string pageOutput = request.GetLastResponseAsString();
     Assert.IsTrue(pageOutput.Contains("Location"), "Returned page did not contain \"Location\". Returned page:\n" + pageOutput);
 }
        /// <summary>
        /// Helper method that signals for a siteoption to be changed then waits for that site to receive and process the signal
        /// </summary>
        /// <param name="siteid">The site id</param>
        /// <param name="section">The site option section</param>
        /// <param name="siteoption">The site option name</param>
        /// <param name="value">The value for the site option</param>
        private static void SignalAndWaitforSiteOptionToBeSet(int siteid, string section, string name, int value)
        {
            // Create a context that will provide us with real data reader support
            IInputContext testContext = DnaMockery.CreateDatabaseInputContext();

            // Now create a datareader to set the Generate Hotlist flag
            using (IDnaDataReader reader = testContext.CreateDnaDataReader("setsiteoption"))
            {
                reader.AddParameter("SiteID", siteid);
                reader.AddParameter("Section", section);
                reader.AddParameter("Name", name);
                reader.AddParameter("Value", value);
                reader.Execute();
            }

            DnaTestURLRequest request = new DnaTestURLRequest("actionnetwork");
            request.SetCurrentUserEditor();
            request.UseEditorAuthentication = true;
            request.RequestAspxPage("dnasignal.aspx", @"action=recache-site&skin=purexml");

            // Now wait untill the .net has been signaled by ripley that we need to recache site data. Site Options are in the data!!!
            // Make sure we've got a drop clause after 15 seconds!!!
            int tries = 0;
            bool updated = false;
            Console.Write("Waiting for signal to be processed ");
            while (tries++ <= 12 && !updated)
            {
                request.RequestPage("siteoptions?skin=purexml");
                if (request.GetLastResponseAsXML().SelectSingleNode("H2G2/SITEOPTIONS[@SITEID='16']/SITEOPTION[NAME='GenerateHotlist']/VALUE") != null)
                {
                    updated = request.GetLastResponseAsXML().SelectSingleNode("H2G2/SITEOPTIONS[@SITEID='16']/SITEOPTION[NAME='GenerateHotlist']/VALUE").InnerXml.CompareTo("1") == 0;

                    if (!updated)
                    {
                        // Goto sleep for 5 secs
                        System.Threading.Thread.Sleep(5000);
                        Console.Write(".");
                    }
                }
            }
            tries *= 5;
            Console.WriteLine(" waited " + tries.ToString() + " seconds.");
        }
        public void Test70ArticleSearchSortByBookmarkCountWhereSiteOptionIncludeBookmarkCountIs0()
        {
            Console.WriteLine("Test70ArticleSearchSortByBookmarkCountWhereSiteOptionIncludeBookmarkCountIs0");

            //Changed the database so try a new request object to make sure we get the correct siteoption
            DnaTestURLRequest newRequest = new DnaTestURLRequest("actionnetwork");
            newRequest.RequestAspxPage("ArticleSearchPage.aspx", @"contenttype=-1&showphrases=20&articlesortby=BookmarkCount&skin=purexml");
            Console.WriteLine("After Test70ArticleSearchSortByBookmarkCountWhereSiteOptionIncludeBookmarkCountIs0");

            XmlDocument xml = newRequest.GetLastResponseAsXML();

            Assert.IsTrue(xml.SelectSingleNode("/H2G2/ARTICLESEARCH[@SORTBY='BookmarkCount']") != null, "The @SORTBY element is not BookmarkCount!!!");

            Assert.IsTrue(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE/BOOKMARKCOUNT") == null, "Element BOOKMARKCOUNT should not be outputted on a site where SiteOption BookmarkCount = 0.");

            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri);
            validator.Validate();
        }
        public void Test69ArticleSearchSortByBookmarkCountWhereSiteOptionIncludeBookmarkCountIs1()
        {
            Console.WriteLine("Test69ArticleSearchSortByBookmarkCountWhereSiteOptionIncludeBookmarkCountIs1");

            //Changed the database so try a new request object to make sure we get the correct siteoption
            DnaTestURLRequest newRequest = new DnaTestURLRequest("h2g2"); // SiteOption IncludeBookmarkCount = 1 for h2g2 on SmallGuide
            newRequest.RequestAspxPage("ArticleSearchPage.aspx", @"contenttype=-1&showphrases=20&articlesortby=BookmarkCount&skin=purexml");
            Console.WriteLine("After Test69ArticleSearchSortByBookmarkCountWhereSiteOptionIncludeBookmarkCountIs1");

            XmlDocument xml = newRequest.GetLastResponseAsXML();

            Assert.IsTrue(xml.SelectSingleNode("/H2G2/ARTICLESEARCH[@SORTBY='BookmarkCount']") != null, "The @SORTBY element is not BookmarkCount!!!");

            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=1]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=2]/BOOKMARKCOUNT").FirstChild.Value), "Articles 1-2 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=2]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=3]/BOOKMARKCOUNT").FirstChild.Value), "Articles 2-3 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=3]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=4]/BOOKMARKCOUNT").FirstChild.Value), "Articles 3-4 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=4]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=5]/BOOKMARKCOUNT").FirstChild.Value), "Articles 4-5 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=5]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=6]/BOOKMARKCOUNT").FirstChild.Value), "Articles 5-6 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=6]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=7]/BOOKMARKCOUNT").FirstChild.Value), "Articles 6-7 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=7]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=8]/BOOKMARKCOUNT").FirstChild.Value), "Articles 7-8 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=8]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=9]/BOOKMARKCOUNT").FirstChild.Value), "Articles 8-9 are not in Bookmark count order.");
            Assert.IsTrue(Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=9]/BOOKMARKCOUNT").FirstChild.Value) > Int32.Parse(xml.SelectSingleNode("/H2G2/ARTICLESEARCH/ARTICLES/ARTICLE[position()=10]/BOOKMARKCOUNT").FirstChild.Value), "Articles 9-10 are not in Bookmark count order.");

            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri);
            validator.Validate();
        }
        public void Test68ArticleHotlistShowPhrasesTest()
        {
            Console.WriteLine("Test68ArticleHotlistShowPhrasesTest");

            SignalAndWaitforSiteOptionToBeSet(16, "ArticleSearch", "GenerateHotlist", 1);

            //Changed the database so try a new request object to make sure we get the correct siteoption
            DnaTestURLRequest newRequest = new DnaTestURLRequest("actionnetwork");
            newRequest.RequestAspxPage("ArticleSearchPage.aspx", @"contenttype=-1&showphrases=150&skin=purexml");
            Console.WriteLine("After Test68ArticleHotlistShowPhrasesTest");

            XmlDocument xml = newRequest.GetLastResponseAsXML();

            XmlNode siteoptionset = xml.SelectSingleNode("H2G2/SITE/SITEOPTIONS/SITEOPTION[@GLOBAL='0'][NAME='GenerateHotlist'][VALUE='1']");
            if (siteoptionset == null)
            {
                Console.WriteLine("siteoption not set");
            }

            XmlNode globaloptionset = xml.SelectSingleNode("H2G2/SITE/SITEOPTIONS/SITEOPTION[@GLOBAL='1'][NAME='GenerateHotList'][VALUE='1']");
            if (globaloptionset == null)
            {
                Console.WriteLine("globaloptionset not set");
            }

            Console.WriteLine("HotPhrases");
            XmlNode hotphrases = xml.SelectSingleNode("H2G2/ARTICLEHOT-PHRASES");
            if (hotphrases == null)
            {
                Console.WriteLine("No hotlist");
            }
            else
            {
                Console.WriteLine(hotphrases.InnerXml);
            }

            XmlNode showphrases = xml.SelectSingleNode("H2G2/ARTICLEHOT-PHRASES/@SHOW");
            if (showphrases == null)
            {
                Console.WriteLine("No show");
            }
            else
            {
                Console.WriteLine(showphrases.InnerXml);
            }

            Assert.IsTrue(xml.SelectSingleNode("H2G2/ARTICLEHOT-PHRASES[@SHOW=150]") != null, "The Hotlist show phrases doesn't match the entered value!!!");

            DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri);
            validator.Validate();
        }
        public void Test66FreeTextSearchOnH2G2()
        {
            Console.WriteLine("Test66FreeTextSearchOnH2G2");
            if (CheckFullTextCatalogueExists(@"h2g2"))
            {
                DnaTestURLRequest _h2g2Request = new DnaTestURLRequest("h2g2");

                _h2g2Request.RequestAspxPage("ArticleSearchPage.aspx", @"skip=10&show=10&contenttype=-1&freetextsearch=Test&skin=purexml");

                XmlDocument xml = _h2g2Request.GetLastResponseAsXML();

                Assert.IsTrue(xml.SelectSingleNode("H2G2/ARTICLESEARCH[FREETEXTSEARCH='Test']") != null, "Article Search XML not generated completed - Free Text Search Term!!!");

                DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri);
                validator.Validate();
            }
            else
            {
                Console.WriteLine("WARNING!! Test not run as full text indexes are not present!");
            }
            Console.WriteLine("After Test66FreeTextSearchOnH2G2");
        }