Add tests to account for aspnet/Razor#220.

- Added unit and functional test.
This commit is contained in:
N. Taylor Mullen 2015-05-13 12:24:11 -07:00
parent 247625dcab
commit 12e4307f3a
4 changed files with 113 additions and 4 deletions

View File

@ -35,7 +35,7 @@
<h3 style="font-family: cursive;">Current Tag Cloud from Tag Helper</h3>
<div>["Lorem","ipsum","dolor","sit","amet","consectetur","adipisicing","elit","sed","do","eiusmod","tempor","incididunt","ut","labore","et","dolore","magna","aliquaUt","enim"]</div>
<h3 style="font-family: cursive;">Current Tag Cloud from ViewComponentHelper:</h3>
<section>["Lorem","ipsum","dolor","sit","amet","consectetur","adipisicing","elit","sed","do","eiusmod","tempor","incididunt","ut","labore"]</section>
<section><b>["Lorem","ipsum","dolor","sit","amet","consectetur","adipisicing","elit","sed","do","eiusmod","tempor","incididunt","ut","labore"]</b></section>
</div>

View File

@ -272,7 +272,7 @@ namespace Microsoft.AspNet.Mvc.Razor
public void IsSectionDefined_ThrowsIfPreviousSectionWritersIsNotRegistered()
{
// Arrange
var page = CreatePage(v =>
var page = CreatePage(v =>
{
v.Path = "/Views/TestPath/Test.cshtml";
});
@ -804,6 +804,89 @@ namespace Microsoft.AspNet.Mvc.Razor
postElement: null),
"<p test=\"HtmlEncode[[testVal]]\" something=\"HtmlEncode[[ spaced ]]\">Hello World!</p>"
},
{
GetTagHelperOutput(
tagName: "p",
attributes: new TagHelperAttributeList()
{
["test"] = new TagHelperAttribute
{
Name = "test",
Minimized = true
},
},
selfClosing: false,
preElement: null,
preContent: null,
content: "Hello World!",
postContent: null,
postElement: null),
"<p test>Hello World!</p>"
},
{
GetTagHelperOutput(
tagName: "p",
attributes: new TagHelperAttributeList()
{
["test"] = new TagHelperAttribute
{
Name = "test",
Minimized = true
},
["test2"] = new TagHelperAttribute
{
Name = "test2",
Minimized = true
},
},
selfClosing: false,
preElement: null,
preContent: null,
content: "Hello World!",
postContent: null,
postElement: null),
"<p test test2>Hello World!</p>"
},
{
GetTagHelperOutput(
tagName: "p",
attributes: new TagHelperAttributeList()
{
["first"] = "unminimized",
["test"] = new TagHelperAttribute
{
Name = "test",
Minimized = true
},
},
selfClosing: false,
preElement: null,
preContent: null,
content: "Hello World!",
postContent: null,
postElement: null),
"<p first=\"HtmlEncode[[unminimized]]\" test>Hello World!</p>"
},
{
GetTagHelperOutput(
tagName: "p",
attributes: new TagHelperAttributeList()
{
["test"] = new TagHelperAttribute
{
Name = "test",
Minimized = true
},
["last"] = "unminimized",
},
selfClosing: false,
preElement: null,
preContent: null,
content: "Hello World!",
postContent: null,
postElement: null),
"<p test last=\"HtmlEncode[[unminimized]]\">Hello World!</p>"
},
{
GetTagHelperOutput(
tagName: "p",

View File

@ -0,0 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
namespace TagHelpersWebSite.TagHelpers
{
[TargetElement(Attributes = "bold")]
public class BoldTagHelper : TagHelper
{
public override int Order
{
get
{
return int.MinValue;
}
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.Attributes.RemoveAll("bold");
output.PreContent.SetContent("<b>");
output.PostContent.SetContent("</b>");
}
}
}

View File

@ -24,9 +24,9 @@
<h3>Current Tag Cloud from Tag Helper</h3>
<tag-cloud count="Model.TagsToShow" surround="div" />
<h3>Current Tag Cloud from ViewComponentHelper:</h3>
<section>@await Component.InvokeAsync("Tags", 15)</section>
<section bold>@await Component.InvokeAsync("Tags", 15)</section>
</div>
@section footerContent {
<p condition="Model.Approved" surround="section">&copy; @Model.CopyrightYear - My ASP.NET Application</p>
<p condition="Model.Approved" bold surround="section">&copy; @Model.CopyrightYear - My ASP.NET Application</p>
}