public void TestListTagMustNotNestInInlineElements()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ListTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render("[i][list][*]Bullet[/list][/i]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<em>[list][*]Bullet[/list]</em>", renderResults.RenderedString);
        }
        public void TestEmptyListTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ListTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render("[list][/list] [list] \t\r\n[/list]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[list][/list] [list] \t<br/>[/list]", renderResults.RenderedString);
        }
        public void TestListTagNesting()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ListTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render("[list]\r\n[*][i]1[/i]\r\n[list]\r\n[*]1.1\r\n[/list]\r\n[/list]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<ul><li><em>1</em><ul><li>1.1</li></ul></li></ul>", renderResults.RenderedString);
        }
        public void TestNoNestingInsideFlashTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new FlashTagDefinition(), new StrikethroughTagDefinition() });
            RenderResults  renderResults = renderer.Render("[flash=480,360]http://www.collegehumor.com/[s]moogaloop/moogaloop.swf?clip_id=1931004&fullscreen=1[/s][/flash]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[flash=480,360]http://www.collegehumor.com/[s]moogaloop/moogaloop.swf?clip_id=1931004&amp;fullscreen=1[/s][/flash]", renderResults.RenderedString);
        }
        public void TestOrderedListTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ListTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render("[list=o] \r\n\t[*]First[*]Second[/list] [list=o][*]First[*]Second[/list] [list=ordered]First[/list]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<ol><li>First</li><li>Second</li></ol> <ol><li>First</li><li>Second</li></ol> <ol><li>First</li></ol>", renderResults.RenderedString);
        }
        public void TestAlignTagsMustNotNestInInlineElements()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new LeftAlignTagDefinition(), new CentreAlignTagDefinition(), new RightAlignTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render("[i][left]left[/left] [centre]centre[/centre] [right]right[/right][/i]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<em>[left]left[/left] [centre]centre[/centre] [right]right[/right]</em>", renderResults.RenderedString);
        }
        public void TestSizeTagMustNotSelfNest()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new SizeTagDefinition(), new StrikethroughTagDefinition() });
            RenderResults  renderResults = renderer.Render("[size=10]I did [size=50]say[/size] [s]this[/s][/size] now I'm saying [size=200]this[/size]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<span style=\"font-size:10%\">I did [size=50]say</span> <span style=\"text-decoration:line-through\">this</span>[/size] now I&#39;m saying <span style=\"font-size:200%\">this</span>", renderResults.RenderedString);
        }
        public void TestCloseTagsWithoutOpenTags()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new BoldTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render(@"Wow[/b], this is really[/i] awesome!");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual(@"Wow[/b], this is really[/i] awesome!", renderResults.RenderedString);
        }
        public void TestFlashTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new FlashTagDefinition() });
            RenderResults  renderResults = renderer.Render("[flash=480,360]http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1931004&fullscreen=1[/flash]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<object type=\"application/x-shockwave-flash\" style=\"width:480px; height:360px;\" data=\"http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1931004&fullscreen=1\"><param name=\"movie\" value=\"http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1931004&fullscreen=1\" /><param name=\"allowfullscreen\" value=\"true\" /></object>", renderResults.RenderedString);
        }
        public void TestInvalidSizesInImageTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ImageTagDefinition(), new StrikethroughTagDefinition() });
            RenderResults  renderResults = renderer.Render("[img=10,b]http://www.digitallycreated.net/Content/Images/OpenID-Small.png[/img] [img=a,10]http://www.digitallycreated.net/Content/Images/OpenID-Small.png[/img]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[img=10,b]http://www.digitallycreated.net/Content/Images/OpenID-Small.png[/img] [img=a,10]http://www.digitallycreated.net/Content/Images/OpenID-Small.png[/img]", renderResults.RenderedString);
        }
        public void TestNoNestingInsideImageTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ImageTagDefinition(), new StrikethroughTagDefinition() });
            RenderResults  renderResults = renderer.Render("[img]http://www.digitallycreated.net/[s]Content/Images/OpenID-Small.png[/s][/img]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[img]http://www.digitallycreated.net/[s]Content/Images/OpenID-Small.png[/s][/img]", renderResults.RenderedString);
        }
        public void TestMustHaveValidUrlInImageTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ImageTagDefinition(), new StrikethroughTagDefinition() });
            RenderResults  renderResults = renderer.Render("[img]javascript:alert('hax!')[/img] [img=20,10]javascript:alert('hax!')[/img]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[img]javascript:alert(&#39;hax!&#39;)[/img] [img=20,10]javascript:alert(&#39;hax!&#39;)[/img]", renderResults.RenderedString);
        }
        public void TestImageTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ImageTagDefinition(), new StrikethroughTagDefinition() });
            RenderResults  renderResults = renderer.Render("[img]http://www.digitallycreated.net/Content/Images/OpenID-Small.png[/img] [img=20,10]http://www.digitallycreated.net/Content/Images/OpenID-Small.png[/img]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<img src=\"http://www.digitallycreated.net/Content/Images/OpenID-Small.png\" alt=\"\" /> <img src=\"http://www.digitallycreated.net/Content/Images/OpenID-Small.png\" width=\"20\" height=\"10\" alt=\"\" />", renderResults.RenderedString);
        }
        public void TestSizeTagWithInvalidSizes()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new SizeTagDefinition(), new StrikethroughTagDefinition() });
            RenderResults  renderResults = renderer.Render("[size=0]I did say [s]this[/s][/size] [size=-1]now[/size] [size=a]I'm[/size] saying [size=201]this[/size]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[size=0]I did say <span style=\"text-decoration:line-through\">this</span>[/size] [size=-1]now[/size] [size=a]I&#39;m[/size] saying [size=201]this[/size]", renderResults.RenderedString);
        }
        public void TestUnopenedCloseTagsInsideOpenTags()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new BoldTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render(@"[b]Wow[/b], this is [b]really[/i] awesome[/b]!");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual(@"<strong>Wow</strong>, this is <strong>really[/i] awesome</strong>!", renderResults.RenderedString);
        }
        public void TestMustHaveValidUrlInFlashTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new FlashTagDefinition() });
            RenderResults  renderResults = renderer.Render("[flash=480,360]javascript:alert('hax!')[/flash]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[flash=480,360]javascript:alert(&#39;hax!&#39;)[/flash]", renderResults.RenderedString);
        }
        public void TestSensibleBrHandlingAroundListTagsWithExtraWhitespace()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new ListTagDefinition() });
            RenderResults  renderResults = renderer.Render("Before list1 \r\n \r\n [list] \r\n [*] list1 \r\n [/list] \r\n \r\n After list1\r\nBefore list2 \r\n [list] \r\n \r\n [*]list2 \r\n \r\n [/list] \r\n After list2\r\nBefore list3 [list] list3 [/list] After list3\r\nBefore list4 \r\n \r\n \r\n [list]list4[/list] \r\n \r\n \r\n After list4");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual(@"Before list1 <br/> <ul><li> list1 </li></ul> After list1<br/>Before list2 <ul><li>list2 <br/> </li></ul> After list2<br/>Before list3 <ul><li> list3 </li></ul> After list3<br/>Before list4 <br/> <br/> <ul><li>list4</li></ul> <br/> After list4", renderResults.RenderedString);
        }
        public void TestInvalidSizesInFlashTag()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new FlashTagDefinition() });
            RenderResults  renderResults = renderer.Render("[flash=a,360]http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1931004&fullscreen=1[/flash] [flash=480,b]http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1931004&fullscreen=1[/flash]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("[flash=a,360]http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1931004&amp;fullscreen=1[/flash] [flash=480,b]http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1931004&amp;fullscreen=1[/flash]", renderResults.RenderedString);
        }
        public void TestAlignTagsMustNotNestInEachOther()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new LeftAlignTagDefinition(), new CentreAlignTagDefinition(), new RightAlignTagDefinition(), new ItalicsTagDefinition() });
            RenderResults  renderResults = renderer.Render("[left][centre]centre[/centre] [right]right[/right] [left]left[/left][/left] [centre][left]left[/left] [right]right[/right] [centre]centre[/centre][/centre] [right][left]left[/left] [centre]centre[/centre] [right]right[/right][/right]");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual("<div style=\"text-align:left\">[centre]centre[/centre] [right]right[/right] [left]left</div>[/left] <div style=\"text-align:center\">[left]left[/left] [right]right[/right] [centre]centre</div>[/centre] <div style=\"text-align:right\">[left]left[/left] [centre]centre[/centre] [right]right</div>[/right]", renderResults.RenderedString);
        }
        public void TestSensibleBrHandlingAroundCodeTagsWithExtraWhitespace()
        {
            BbCodeRenderer renderer      = new BbCodeRenderer(new ITagDefinition[] { new CodeTagDefinition() });
            RenderResults  renderResults = renderer.Render("Before code1 \r\n \r\n [code] \r\n code1 \r\n [/code] \r\n \r\n After code1\r\nBefore code2 \r\n [code] \r\n \r\n code2 \r\n \r\n [/code] \r\n After code2\r\nBefore code3 [code] code3 [/code] After code3\r\nBefore code4 \r\n \r\n \r\n [code]code4[/code] \r\n \r\n \r\n After code4");

            Assert.IsTrue(renderResults.IsCacheable);
            Assert.AreEqual(@"Before code1 <br/> <pre> code1 </pre> After code1<br/>Before code2 <pre> <br/> code2 <br/> </pre> After code2<br/>Before code3 <pre> code3 </pre> After code3<br/>Before code4 <br/> <br/> <pre>code4</pre> <br/> After code4", renderResults.RenderedString);
        }