public void CreateForLink_HrefOnly()
        {
            var commandInfo = CommandInfo.CreateForLink(null, null, "Url", null, null);

            Assert.That(commandInfo.Title, Is.Null);

            Assert.That(commandInfo.OnClick, Is.Null);
            Assert.That(commandInfo.Href, Is.EqualTo("Url"));
            Assert.That(commandInfo.Target, Is.Null);
        }
        public void CreateForLink()
        {
            var commandInfo = CommandInfo.CreateForLink("TheTitle", "A", "Url", "TheTarget", "ClickHandler");

            Assert.That(commandInfo.Title, Is.EqualTo("TheTitle"));
            Assert.That(commandInfo.AccessKey, Is.EqualTo("A"));
            Assert.That(commandInfo.OnClick, Is.EqualTo("ClickHandler"));
            Assert.That(commandInfo.Href, Is.EqualTo("Url"));
            Assert.That(commandInfo.Target, Is.EqualTo("TheTarget"));
        }
        public void AddAttributesToRender_DoesNotEncodeTarget()
        {
            var commandInfo = CommandInfo.CreateForLink("TheTitle", null, "Url", "TheTarget\"Space'", "ClickHandler");

            var stringWriter   = new StringWriter();
            var htmlTextWriter = new HtmlTextWriter(stringWriter);

            commandInfo.AddAttributesToRender(htmlTextWriter, RenderingFeatures.Default);

            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.A);
            htmlTextWriter.RenderEndTag();

            var result = stringWriter.ToString();

            Assert.That(result, Is.StringContaining("target=\"TheTarget\"Space'\""));
        }
        public void AddAttributesToRender_EncodesAccesskey()
        {
            var commandInfo = CommandInfo.CreateForLink("TheTitle\"Space'", "\'", "Url", "TheTarget", "ClickHandler");

            var stringWriter   = new StringWriter();
            var htmlTextWriter = new HtmlTextWriter(stringWriter);

            commandInfo.AddAttributesToRender(htmlTextWriter, RenderingFeatures.Default);

            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.A);
            htmlTextWriter.RenderEndTag();

            var result = stringWriter.ToString();

            Assert.That(result, Is.StringContaining("accesskey=\"'"));
        }
        public void AddDiagnosticMetadataAttributes_PureJavaScript()
        {
            var commandInfo = CommandInfo.CreateForLink("TheTitle", null, "#", "TheTarget", "javascript:Foo();");

            var stringWriter   = new StringWriter();
            var htmlTextWriter = new HtmlTextWriter(stringWriter);

            commandInfo.AddAttributesToRender(htmlTextWriter, RenderingFeatures.WithDiagnosticMetadata);

            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.A);
            htmlTextWriter.RenderEndTag();

            var result = stringWriter.ToString();

            Assert.That(result, Is.StringContaining(DiagnosticMetadataAttributes.ControlType + "=\"Command\""));
            Assert.That(result, Is.StringContaining(DiagnosticMetadataAttributes.TriggersPostBack + "=\"false\""));
            Assert.That(result, Is.StringContaining(DiagnosticMetadataAttributes.TriggersNavigation + "=\"false\""));
        }
        public void AddAttributesToRender()
        {
            var commandInfo = CommandInfo.CreateForLink("TheTitle", "A", "Url", "TheTarget", "ClickHandler");

            var stringWriter   = new StringWriter();
            var htmlTextWriter = new HtmlTextWriter(stringWriter);

            commandInfo.AddAttributesToRender(htmlTextWriter, RenderingFeatures.Default);

            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.A);
            htmlTextWriter.RenderEndTag();

            var result = stringWriter.ToString();

            Assert.That(result, Is.StringContaining("title=\"TheTitle\""));
            Assert.That(result, Is.StringContaining("accesskey=\"A\""));
            Assert.That(result, Is.StringContaining("onclick=\"ClickHandler\""));
            Assert.That(result, Is.StringContaining("href=\"Url\""));
            Assert.That(result, Is.StringContaining("target=\"TheTarget\""));
        }
        public void AddAttributesToRender_HrefOnly()
        {
            var commandInfo = CommandInfo.CreateForLink(null, null, "Url", null, null);

            var stringWriter   = new StringWriter();
            var htmlTextWriter = new HtmlTextWriter(stringWriter);

            commandInfo.AddAttributesToRender(htmlTextWriter, RenderingFeatures.Default);

            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.A);
            htmlTextWriter.RenderEndTag();

            var result = stringWriter.ToString();

            Assert.That(result, Is.Not.StringContaining("title="));
            Assert.That(result, Is.Not.StringContaining("accesskey="));
            Assert.That(result, Is.Not.StringContaining("onclick="));
            Assert.That(result, Is.StringContaining("href=\"Url\""));
            Assert.That(result, Is.Not.StringContaining("target="));
        }