public void Scan()
        {
            CreateParser("<A HREF=\"mytest.html\"><IMG SRC=\"abcd.jpg\">Hello World</A>", "http://www.yahoo.com");
            // Register the image scanner
            LinkScanner linkScanner = new LinkScanner("-l");

            parser.AddScanner(linkScanner);
            parser.AddScanner(linkScanner.CreateImageScanner("-i"));

            ParseAndAssertNodeCount(1);
            Assert.IsTrue(node[0] is LinkTag, "Node should be a link node");

            LinkTag linkTag = (LinkTag)node[0];

            // Get the link data and cross-check
            Node[] dataNode = new AbstractNode[10];
            int    i        = 0;

            foreach (Node nestedNode in linkTag)
            {
                dataNode[i++] = nestedNode;
            }
            Assert.AreEqual(2, i, "Number of data nodes");
            Assert.IsTrue(dataNode[0] is ImageTag, "First data node should be an Image Node");
            Assert.IsTrue(dataNode[1] is StringNode, "Second data node shouls be a String Node");

            // Check the contents of each data node
            ImageTag imageTag = (ImageTag)dataNode[0];

            Assert.AreEqual("http://www.yahoo.com/abcd.jpg", imageTag.ImageURL, "Image URL");
            StringNode stringNode = (StringNode)dataNode[1];

            Assert.AreEqual("Hello World", stringNode.Text, "String Contents");
        }
        public void Evaluate()
        {
            LinkScanner scanner = new LinkScanner("-l");
            bool        retVal  = scanner.Evaluate("   a href ", null);

            Assert.IsTrue(retVal, "Evaluation of the Link tag");
        }
        public void InsertEndTagBeforeTag()
        {
            string      currentLine = "<a href=s/7509><b>Yahoo! Movies</b></a>";
            Tag         tag         = new Tag(new TagData(0, 14, "a href=s/7509", currentLine));
            LinkScanner linkScanner = new LinkScanner();
            string      newLine     = linkScanner.InsertEndTagBeforeNode(tag, currentLine);

            Assert.AreEqual("</A><a href=s/7509><b>Yahoo! Movies</b></a>", newLine, "Expected insertion");
        }
        public void ExtractLinkInvertedCommasBug()
        {
            string      tagContents = "a href=r/anorth/top.html";
            Tag         tag         = new Tag(new TagData(0, 0, tagContents, ""));
            string      url         = "c:\\cvs\\html\\binaries\\yahoo.htm";
            LinkScanner scanner     = new LinkScanner("-l");

            Assert.AreEqual("r/anorth/top.html", scanner.ExtractLink(tag, url), "Extracted Link");
        }
        public void LinkDataContents()
        {
            CreateParser(
                "<a href=\"http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689\" target=\"_new\"><img src=\"http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif\" width=468 height=60 border=\"0\" alt=\"See Signs in Theaters 8-2 - Starring Mel Gibson\" align=><font face=\"verdana,arial,helvetica\" SIZE=\"1\"><b></b></font></a>",
                "http://transfer.go.com");
            // Register the image scanner
            LinkScanner linkScanner = new LinkScanner("-l");

            parser.AddScanner(linkScanner);
            parser.AddScanner(linkScanner.CreateImageScanner("-i"));

            ParseAndAssertNodeCount(1);
            Assert.IsTrue(node[0] is LinkTag, "Node 0 should be a link tag");
            LinkTag linkTag = (LinkTag)node[0];

            Assert.AreEqual(
                "http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689",
                linkTag.Link, "Link URL");
            Assert.AreEqual("", linkTag.LinkText, "Link Text");
            Node[] containedNodes = new AbstractNode[10];
            int    i = 0;

            foreach (Node nestedNode in linkTag)
            {
                containedNodes[i++] = nestedNode;
            }
            Assert.AreEqual(5, i, "There should be 5 contained nodes in the link tag");
            Assert.IsTrue(containedNodes[0] is ImageTag, "First contained node should be an image tag");
            ImageTag imageTag = (ImageTag)containedNodes[0];

            Assert.AreEqual("http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif", imageTag.ImageURL,
                            "Image Location");
            Assert.AreEqual("60", imageTag["HEIGHT"], "Image Height");
            Assert.AreEqual("468", imageTag["WIDTH"], "Image Width");
            Assert.AreEqual("0", imageTag["BORDER"], "Image Border");
            Assert.AreEqual("See Signs in Theaters 8-2 - Starring Mel Gibson", imageTag["ALT"], "Image Alt");
            Assert.IsTrue(containedNodes[1] is Tag, "Second contained node should be Tag");
            Tag tag1 = (Tag)containedNodes[1];

            Assert.AreEqual("font face=\"verdana,arial,helvetica\" SIZE=\"1\"", tag1.Text, "Tag Contents");
            Assert.IsTrue(containedNodes[2] is Tag, "Third contained node should be Tag");
            Tag tag2 = (Tag)containedNodes[2];

            Assert.AreEqual("b", tag2.Text, "Tag Contents");
            Assert.IsTrue(containedNodes[3] is EndTag, "Fourth contained node should be HTMLEndTag");
            EndTag endTag1 = (EndTag)containedNodes[3];

            Assert.AreEqual("b", endTag1.Text, "Fourth Tag contents");
            Assert.IsTrue(containedNodes[4] is EndTag, "Fifth contained node should be HTMLEndTag");
            EndTag endTag2 = (EndTag)containedNodes[4];

            Assert.AreEqual("font", endTag2.Text, "Fifth Tag contents");
        }
        public void ReplaceFaultyTagWithEndTag()
        {
            string currentLine =
                "<p>Site Comments?<br><a href=\"mailto:[email protected]?subject=Site Comments\">Mail Us<a></p>";
            Tag         tag         = new Tag(new TagData(85, 87, "a", currentLine));
            LinkScanner linkScanner = new LinkScanner();
            string      newLine     = linkScanner.ReplaceFaultyTagWithEndTag(tag, currentLine);

            Assert.AreEqual(
                "<p>Site Comments?<br><a href=\"mailto:[email protected]?subject=Site Comments\">Mail Us</A></p>",
                newLine, "Expected replacement");
        }
        public void LinkScannerFilter()
        {
            LinkScanner linkScanner = new LinkScanner(LinkTag.LINK_TAG_FILTER);

            Assert.AreEqual(LinkTag.LINK_TAG_FILTER, linkScanner.Filter, "linkscanner filter");
        }