Modify TagHelper tests to abide by new content mode design.
- React to aspnet/Razor#221 - Modified existing TagHelper tests to no longer rely on ContentBehavior. - Updated signatures of TagHelperExecutionContext and TagHelperContext pieces.
This commit is contained in:
parent
7b52559366
commit
eb1eca9e1a
|
|
@ -45,7 +45,9 @@ namespace Asp
|
||||||
BeginContext(120, 2, true);
|
BeginContext(120, 2, true);
|
||||||
WriteLiteral("\r\n");
|
WriteLiteral("\r\n");
|
||||||
EndContext();
|
EndContext();
|
||||||
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", "test");
|
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", "test", async() => {
|
||||||
|
}
|
||||||
|
, StartWritingScope, EndWritingScope);
|
||||||
__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper<Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>();
|
__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper<Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>();
|
||||||
__tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper);
|
__tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper);
|
||||||
#line 5 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
|
#line 5 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
|
||||||
|
|
@ -56,12 +58,28 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
|
||||||
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
|
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
|
||||||
__tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result;
|
__tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result;
|
||||||
WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag());
|
WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag());
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.Output.GeneratePreContent());
|
||||||
|
if (__tagHelperExecutionContext.Output.ContentSet)
|
||||||
|
{
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.Output.GenerateContent());
|
||||||
|
}
|
||||||
|
else if (__tagHelperExecutionContext.ChildContentRetrieved)
|
||||||
|
{
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.GetChildContentAsync().Result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__tagHelperExecutionContext.ExecuteChildContentAsync().Wait();
|
||||||
|
}
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.Output.GeneratePostContent());
|
||||||
WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag());
|
WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag());
|
||||||
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
||||||
BeginContext(146, 2, true);
|
BeginContext(146, 2, true);
|
||||||
WriteLiteral("\r\n");
|
WriteLiteral("\r\n");
|
||||||
EndContext();
|
EndContext();
|
||||||
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", "test");
|
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", "test", async() => {
|
||||||
|
}
|
||||||
|
, StartWritingScope, EndWritingScope);
|
||||||
__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper<Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>();
|
__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper<Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>();
|
||||||
__tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper);
|
__tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper);
|
||||||
#line 6 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
|
#line 6 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
|
||||||
|
|
@ -72,6 +90,20 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
|
||||||
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
|
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For);
|
||||||
__tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result;
|
__tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result;
|
||||||
WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag());
|
WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag());
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.Output.GeneratePreContent());
|
||||||
|
if (__tagHelperExecutionContext.Output.ContentSet)
|
||||||
|
{
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.Output.GenerateContent());
|
||||||
|
}
|
||||||
|
else if (__tagHelperExecutionContext.ChildContentRetrieved)
|
||||||
|
{
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.GetChildContentAsync().Result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__tagHelperExecutionContext.ExecuteChildContentAsync().Wait();
|
||||||
|
}
|
||||||
|
WriteLiteral(__tagHelperExecutionContext.Output.GeneratePostContent());
|
||||||
WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag());
|
WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag());
|
||||||
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,18 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "asp-host", "contoso.com" },
|
{ "asp-host", "contoso.com" },
|
||||||
{ "asp-protocol", "http" }
|
{ "asp-protocol", "http" }
|
||||||
},
|
},
|
||||||
uniqueId: "test");
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something Else"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
expectedTagName,
|
expectedTagName,
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "id", "myanchor" },
|
{ "id", "myanchor" },
|
||||||
{ "asp-route-foo", "bar" },
|
{ "asp-route-foo", "bar" },
|
||||||
},
|
})
|
||||||
content: "Something");
|
{
|
||||||
|
Content = "Something"
|
||||||
|
};
|
||||||
|
|
||||||
var urlHelper = new Mock<IUrlHelper>();
|
var urlHelper = new Mock<IUrlHelper>();
|
||||||
urlHelper
|
urlHelper
|
||||||
|
|
@ -85,11 +88,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"a",
|
"a",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: string.Empty);
|
{
|
||||||
|
Content = string.Empty
|
||||||
|
};
|
||||||
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
generator
|
generator
|
||||||
|
|
@ -119,11 +126,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"a",
|
"a",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: string.Empty);
|
{
|
||||||
|
Content = string.Empty
|
||||||
|
};
|
||||||
|
|
||||||
var generator = new Mock<IHtmlGenerator>();
|
var generator = new Mock<IHtmlGenerator>();
|
||||||
generator
|
generator
|
||||||
|
|
@ -166,8 +177,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>()
|
attributes: new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ "href", "http://www.contoso.com" }
|
{ "href", "http://www.contoso.com" }
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
|
||||||
if (propertyName == "asp-route-")
|
if (propertyName == "asp-route-")
|
||||||
{
|
{
|
||||||
output.Attributes.Add("asp-route-foo", "bar");
|
output.Attributes.Add("asp-route-foo", "bar");
|
||||||
|
|
@ -202,8 +212,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
typeof(AnchorTagHelper).GetProperty(propertyName).SetValue(anchorTagHelper, "Home");
|
typeof(AnchorTagHelper).GetProperty(propertyName).SetValue(anchorTagHelper, "Home");
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"a",
|
"a",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
var expectedErrorMessage = "Cannot determine an 'href' attribute for <a>. An <a> with a specified " +
|
var expectedErrorMessage = "Cannot determine an 'href' attribute for <a>. An <a> with a specified " +
|
||||||
"'asp-route' must not have an 'asp-action' or 'asp-controller' attribute.";
|
"'asp-route' must not have an 'asp-action' or 'asp-controller' attribute.";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,15 +33,18 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "method", "post" },
|
{ "method", "post" },
|
||||||
{ "asp-anti-forgery", true }
|
{ "asp-anti-forgery", true }
|
||||||
},
|
},
|
||||||
uniqueId: "test");
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something Else"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
expectedTagName,
|
expectedTagName,
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "id", "myform" },
|
{ "id", "myform" },
|
||||||
{ "asp-route-foo", "bar" },
|
{ "asp-route-foo", "bar" },
|
||||||
},
|
})
|
||||||
content: "Something");
|
{
|
||||||
|
PostContent = "Something"
|
||||||
|
};
|
||||||
var urlHelper = new Mock<IUrlHelper>();
|
var urlHelper = new Mock<IUrlHelper>();
|
||||||
urlHelper
|
urlHelper
|
||||||
.Setup(mock => mock.Action(It.IsAny<string>(),
|
.Setup(mock => mock.Action(It.IsAny<string>(),
|
||||||
|
|
@ -56,8 +59,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var viewContext = TestableHtmlGenerator.GetViewContext(model: null,
|
var viewContext = TestableHtmlGenerator.GetViewContext(model: null,
|
||||||
htmlGenerator: htmlGenerator,
|
htmlGenerator: htmlGenerator,
|
||||||
metadataProvider: metadataProvider);
|
metadataProvider: metadataProvider);
|
||||||
var expectedContent = "Something" + htmlGenerator.GenerateAntiForgery(viewContext)
|
var expectedPostContent = "Something" + htmlGenerator.GenerateAntiForgery(viewContext)
|
||||||
.ToString(TagRenderMode.SelfClosing);
|
.ToString(TagRenderMode.SelfClosing);
|
||||||
var formTagHelper = new FormTagHelper
|
var formTagHelper = new FormTagHelper
|
||||||
{
|
{
|
||||||
Action = "index",
|
Action = "index",
|
||||||
|
|
@ -79,7 +82,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal("post", attribute.Value);
|
Assert.Equal("post", attribute.Value);
|
||||||
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("action"));
|
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("action"));
|
||||||
Assert.Equal("home/index", attribute.Value);
|
Assert.Equal("home/index", attribute.Value);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Empty(output.PreContent);
|
||||||
|
Assert.Empty(output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,16 +92,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
[InlineData(true, "<input />")]
|
[InlineData(true, "<input />")]
|
||||||
[InlineData(false, "")]
|
[InlineData(false, "")]
|
||||||
[InlineData(null, "<input />")]
|
[InlineData(null, "<input />")]
|
||||||
public async Task ProcessAsync_GeneratesAntiForgeryCorrectly(bool? antiForgery, string expectedContent)
|
public async Task ProcessAsync_GeneratesAntiForgeryCorrectly(bool? antiForgery, string expectedPostContent)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var viewContext = CreateViewContext();
|
var viewContext = CreateViewContext();
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"form",
|
"form",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
generator
|
generator
|
||||||
.Setup(mock => mock.GenerateForm(
|
.Setup(mock => mock.GenerateForm(
|
||||||
|
|
@ -124,7 +130,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("form", output.TagName);
|
Assert.Equal("form", output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Empty(output.PreContent);
|
||||||
|
Assert.Empty(output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -133,7 +141,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var testViewContext = CreateViewContext();
|
var testViewContext = CreateViewContext();
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("asp-ROUTEE-NotRoute", "something");
|
var expectedAttribute = new KeyValuePair<string, string>("asp-ROUTEE-NotRoute", "something");
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"form",
|
"form",
|
||||||
|
|
@ -141,8 +151,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "asp-route-val", "hello" },
|
{ "asp-route-val", "hello" },
|
||||||
{ "asp-roUte--Foo", "bar" }
|
{ "asp-roUte--Foo", "bar" }
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
|
||||||
output.Attributes.Add(expectedAttribute);
|
output.Attributes.Add(expectedAttribute);
|
||||||
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
|
|
@ -184,7 +193,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal("form", output.TagName);
|
Assert.Equal("form", output.TagName);
|
||||||
var attribute = Assert.Single(output.Attributes);
|
var attribute = Assert.Single(output.Attributes);
|
||||||
Assert.Equal(expectedAttribute, attribute);
|
Assert.Equal(expectedAttribute, attribute);
|
||||||
|
Assert.Empty(output.PreContent);
|
||||||
Assert.Empty(output.Content);
|
Assert.Empty(output.Content);
|
||||||
|
Assert.Empty(output.PostContent);
|
||||||
generator.Verify();
|
generator.Verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,11 +205,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var viewContext = CreateViewContext();
|
var viewContext = CreateViewContext();
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"form",
|
"form",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
generator
|
generator
|
||||||
.Setup(mock => mock.GenerateForm(viewContext, "Index", "Home", null, "POST", null))
|
.Setup(mock => mock.GenerateForm(viewContext, "Index", "Home", null, "POST", null))
|
||||||
|
|
@ -220,7 +232,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
Assert.Equal("form", output.TagName);
|
Assert.Equal("form", output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
|
Assert.Empty(output.PreContent);
|
||||||
Assert.Empty(output.Content);
|
Assert.Empty(output.Content);
|
||||||
|
Assert.Empty(output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -238,14 +252,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "aCTiON", htmlAction },
|
{ "aCTiON", htmlAction },
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>()
|
allAttributes: new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
{ "METhod", "POST" }
|
{ "METhod", "POST" }
|
||||||
},
|
},
|
||||||
uniqueId: "test");
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await formTagHelper.ProcessAsync(context, output);
|
await formTagHelper.ProcessAsync(context, output);
|
||||||
|
|
@ -257,7 +272,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal(htmlAction, attribute.Value);
|
Assert.Equal(htmlAction, attribute.Value);
|
||||||
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("METhod"));
|
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("METhod"));
|
||||||
Assert.Equal("POST", attribute.Value);
|
Assert.Equal("POST", attribute.Value);
|
||||||
|
Assert.Empty(output.PreContent);
|
||||||
Assert.Empty(output.Content);
|
Assert.Empty(output.Content);
|
||||||
|
Assert.Empty(output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -266,11 +283,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
[InlineData(null, "")]
|
[InlineData(null, "")]
|
||||||
public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified(
|
public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified(
|
||||||
bool? antiForgery,
|
bool? antiForgery,
|
||||||
string expectedContent)
|
string expectedPostContent)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var viewContext = CreateViewContext();
|
var viewContext = CreateViewContext();
|
||||||
var generator = new Mock<IHtmlGenerator>();
|
var generator = new Mock<IHtmlGenerator>();
|
||||||
|
|
||||||
generator.Setup(mock => mock.GenerateAntiForgery(It.IsAny<ViewContext>()))
|
generator.Setup(mock => mock.GenerateAntiForgery(It.IsAny<ViewContext>()))
|
||||||
.Returns(new TagBuilder("input"));
|
.Returns(new TagBuilder("input"));
|
||||||
var formTagHelper = new FormTagHelper
|
var formTagHelper = new FormTagHelper
|
||||||
|
|
@ -284,9 +302,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "aCTiON", "my-action" },
|
{ "aCTiON", "my-action" },
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
var context = new TagHelperContext(
|
||||||
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await formTagHelper.ProcessAsync(context, output);
|
await formTagHelper.ProcessAsync(context, output);
|
||||||
|
|
@ -295,7 +316,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal("form", output.TagName);
|
Assert.Equal("form", output.TagName);
|
||||||
var attribute = Assert.Single(output.Attributes);
|
var attribute = Assert.Single(output.Attributes);
|
||||||
Assert.Equal(new KeyValuePair<string, string>("aCTiON", "my-action"), attribute);
|
Assert.Equal(new KeyValuePair<string, string>("aCTiON", "my-action"), attribute);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Empty(output.PreContent);
|
||||||
|
Assert.Empty(output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -314,8 +337,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "action", "my-action" },
|
{ "action", "my-action" },
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
|
||||||
if (propertyName == "asp-route-")
|
if (propertyName == "asp-route-")
|
||||||
{
|
{
|
||||||
tagHelperOutput.Attributes.Add("asp-route-foo", "bar");
|
tagHelperOutput.Attributes.Add("asp-route-foo", "bar");
|
||||||
|
|
|
||||||
|
|
@ -89,16 +89,23 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "valid", "from validation attributes" },
|
{ "valid", "from validation attributes" },
|
||||||
{ "value", expectedValue },
|
{ "value", expectedValue },
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
var expectedContent = "original content";
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "not-input";
|
var expectedTagName = "not-input";
|
||||||
|
|
||||||
var context = new TagHelperContext(new Dictionary<string, object>(), uniqueId: "test");
|
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, expectedContent)
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -124,7 +131,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.True(output.SelfClosing);
|
Assert.True(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -133,17 +142,24 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
public async Task ProcessAsync_CallsGenerateCheckBox_WithExpectedParameters()
|
public async Task ProcessAsync_CallsGenerateCheckBox_WithExpectedParameters()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var originalContent = "something";
|
var originalContent = "original content";
|
||||||
var originalTagName = "not-input";
|
var originalTagName = "not-input";
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
var expectedContent = originalContent + "<input class=\"form-control\" /><hidden />";
|
var expectedContent = originalContent + "<input class=\"form-control\" /><hidden />";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
|
|
||||||
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(originalTagName, originalAttributes, content: originalContent)
|
var output = new TagHelperOutput(originalTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = originalContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -180,9 +196,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
htmlGenerator.Verify();
|
htmlGenerator.Verify();
|
||||||
|
|
||||||
Assert.Empty(output.Attributes); // Moved to Content and cleared
|
Assert.Empty(output.Attributes); // Moved to Content and cleared
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.False(output.SelfClosing);
|
Assert.False(output.SelfClosing);
|
||||||
Assert.Empty(output.TagName); // Cleared
|
Assert.Null(output.TagName); // Cleared
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -214,16 +232,23 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "class", "form-control hidden-control" },
|
{ "class", "form-control hidden-control" },
|
||||||
{ "type", inputTypeName ?? "hidden" }, // Generator restores type attribute; adds "hidden" if none.
|
{ "type", inputTypeName ?? "hidden" }, // Generator restores type attribute; adds "hidden" if none.
|
||||||
};
|
};
|
||||||
var expectedContent = "something";
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "not-input";
|
var expectedTagName = "not-input";
|
||||||
|
|
||||||
var context = new TagHelperContext(allAttributes: contextAttributes, uniqueId: "test");
|
var context = new TagHelperContext(allAttributes: contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content: expectedContent)
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -257,7 +282,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
htmlGenerator.Verify();
|
htmlGenerator.Verify();
|
||||||
|
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.True(output.SelfClosing);
|
Assert.True(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -291,16 +318,23 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "class", "form-control password-control" },
|
{ "class", "form-control password-control" },
|
||||||
{ "type", inputTypeName ?? "password" }, // Generator restores type attribute; adds "password" if none.
|
{ "type", inputTypeName ?? "password" }, // Generator restores type attribute; adds "password" if none.
|
||||||
};
|
};
|
||||||
var expectedContent = "something";
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "not-input";
|
var expectedTagName = "not-input";
|
||||||
|
|
||||||
var context = new TagHelperContext(allAttributes: contextAttributes, uniqueId: "test");
|
var context = new TagHelperContext(allAttributes: contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content: expectedContent)
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -333,7 +367,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
htmlGenerator.Verify();
|
htmlGenerator.Verify();
|
||||||
|
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.True(output.SelfClosing);
|
Assert.True(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -365,16 +401,23 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "type", inputTypeName ?? "radio" }, // Generator restores type attribute; adds "radio" if none.
|
{ "type", inputTypeName ?? "radio" }, // Generator restores type attribute; adds "radio" if none.
|
||||||
{ "value", value },
|
{ "value", value },
|
||||||
};
|
};
|
||||||
var expectedContent = "something";
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "not-input";
|
var expectedTagName = "not-input";
|
||||||
|
|
||||||
var context = new TagHelperContext(allAttributes: contextAttributes, uniqueId: "test");
|
var context = new TagHelperContext(allAttributes: contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content: expectedContent)
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -408,7 +451,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
htmlGenerator.Verify();
|
htmlGenerator.Verify();
|
||||||
|
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.True(output.SelfClosing);
|
Assert.True(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -454,16 +499,23 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "class", "form-control text-control" },
|
{ "class", "form-control text-control" },
|
||||||
{ "type", inputTypeName ?? "text" }, // Generator restores type attribute; adds "text" if none.
|
{ "type", inputTypeName ?? "text" }, // Generator restores type attribute; adds "text" if none.
|
||||||
};
|
};
|
||||||
var expectedContent = "something";
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "not-input";
|
var expectedTagName = "not-input";
|
||||||
|
|
||||||
var context = new TagHelperContext(allAttributes: contextAttributes, uniqueId: "test");
|
var context = new TagHelperContext(allAttributes: contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content: expectedContent)
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -497,7 +549,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
htmlGenerator.Verify();
|
htmlGenerator.Verify();
|
||||||
|
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.True(output.SelfClosing);
|
Assert.True(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -512,12 +566,20 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "type", "datetime" },
|
{ "type", "datetime" },
|
||||||
{ "value", "2014-10-15T23:24:19.000-7:00" },
|
{ "value", "2014-10-15T23:24:19.000-7:00" },
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
var expectedContent = "original content";
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "input";
|
var expectedTagName = "input";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(new Dictionary<string, object>(), uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, expectedAttributes, expectedContent)
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -536,7 +598,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.False(output.SelfClosing);
|
Assert.False(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -558,13 +622,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var contextAttributes = new Dictionary<string, object>();
|
var contextAttributes = new Dictionary<string, object>();
|
||||||
var originalAttributes = new Dictionary<string, string>();
|
var originalAttributes = new Dictionary<string, string>();
|
||||||
var content = "original content";
|
|
||||||
var expectedTagName = "select";
|
var expectedTagName = "select";
|
||||||
var expectedMessage = "Unable to format without a 'asp-for' expression for <input>. 'asp-format' must " +
|
var expectedMessage = "Unable to format without a 'asp-for' expression for <input>. 'asp-format' must " +
|
||||||
"be null if 'asp-for' is null.";
|
"be null if 'asp-for' is null.";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content);
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes);
|
||||||
var tagHelper = new InputTagHelper
|
var tagHelper = new InputTagHelper
|
||||||
{
|
{
|
||||||
Format = "{0}",
|
Format = "{0}",
|
||||||
|
|
|
||||||
|
|
@ -44,45 +44,111 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
return new TheoryData<object, Type, Func<object>, string, TagHelperOutputContent>
|
return new TheoryData<object, Type, Func<object>, string, TagHelperOutputContent>
|
||||||
{
|
{
|
||||||
{ null, typeof(Model), () => null, "Text",
|
{ null, typeof(Model), () => null, "Text",
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "Text") },
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "Text") },
|
||||||
|
{ null, typeof(Model), () => null, "Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "Text") },
|
||||||
|
|
||||||
{ modelWithNull, typeof(Model), () => modelWithNull.Text, "Text",
|
{ modelWithNull, typeof(Model), () => modelWithNull.Text, "Text",
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "Text") },
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "Text") },
|
||||||
|
{ modelWithNull, typeof(Model), () => modelWithNull.Text, "Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "Text") },
|
||||||
|
{ modelWithNull, typeof(Model), () => modelWithNull.Text, "Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "Text") },
|
||||||
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "Text") },
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "Text") },
|
||||||
|
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "Text") },
|
||||||
|
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "Text") },
|
||||||
{ modelWithText, typeof(Model), () => modelWithNull.Text, "Text",
|
{ modelWithText, typeof(Model), () => modelWithNull.Text, "Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "Text") },
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "Text") },
|
||||||
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "Text") },
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "Text") },
|
||||||
|
{ modelWithText, typeof(Model), () => modelWithNull.Text, "Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "Text") },
|
||||||
|
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "Text") },
|
||||||
|
{ modelWithText, typeof(Model), () => modelWithNull.Text, "Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "Text") },
|
||||||
|
{ modelWithText, typeof(Model), () => modelWithText.Text, "Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "Text") },
|
||||||
|
|
||||||
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "NestedModel_Text") },
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "NestedModel_Text") },
|
||||||
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "NestedModel_Text") },
|
|
||||||
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "NestedModel_Text") },
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "NestedModel_Text") },
|
||||||
|
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "NestedModel_Text") },
|
||||||
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "NestedModel_Text") },
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "NestedModel_Text") },
|
||||||
|
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "NestedModel_Text") },
|
||||||
|
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "NestedModel_Text") },
|
||||||
|
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "NestedModel_Text") },
|
||||||
|
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "NestedModel_Text") },
|
||||||
|
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "NestedModel_Text") },
|
||||||
|
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "NestedModel_Text") },
|
||||||
|
{ modelWithNull, typeof(NestedModel), () => modelWithNull.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "NestedModel_Text") },
|
||||||
|
{ modelWithText, typeof(NestedModel), () => modelWithText.NestedModel.Text, "NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "NestedModel_Text") },
|
||||||
|
|
||||||
// Note: Tests cases below here will not work in practice due to current limitations on indexing
|
// Note: Tests cases below here will not work in practice due to current limitations on indexing
|
||||||
// into ModelExpressions. Will be fixed in https://github.com/aspnet/Mvc/issues/1345.
|
// into ModelExpressions. Will be fixed in https://github.com/aspnet/Mvc/issues/1345.
|
||||||
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "z0__Text") },
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "z0__Text") },
|
||||||
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "z1__Text") },
|
|
||||||
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "z0__Text") },
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "z0__Text") },
|
||||||
|
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "z0__Text") },
|
||||||
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "z1__Text") },
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "z1__Text") },
|
||||||
|
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "z1__Text") },
|
||||||
|
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "z1__Text") },
|
||||||
|
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "z0__Text") },
|
||||||
|
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "z1__Text") },
|
||||||
|
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "z0__Text") },
|
||||||
|
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "z1__Text") },
|
||||||
|
{ models, typeof(Model), () => models[0].Text, "[0].Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "z0__Text") },
|
||||||
|
{ models, typeof(Model), () => models[1].Text, "[1].Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "z1__Text") },
|
||||||
|
|
||||||
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "z0__NestedModel_Text") },
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "z0__NestedModel_Text") },
|
||||||
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
|
||||||
new TagHelperOutputContent(Environment.NewLine, "Text", "z1__NestedModel_Text") },
|
|
||||||
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "z0__NestedModel_Text") },
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "z0__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "z0__NestedModel_Text") },
|
||||||
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
||||||
new TagHelperOutputContent("Hello World", "Hello World", "z1__NestedModel_Text") },
|
new TagHelperOutputContent(Environment.NewLine, string.Empty, "Text", "z1__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(Environment.NewLine, "Hello World", "Hello World", "z1__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, Environment.NewLine, Environment.NewLine, "z1__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "z0__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent(string.Empty, "Hello World", "Hello World", "z1__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "z0__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World", string.Empty, "Hello World", "z1__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[0].NestedModel.Text, "[0].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "z0__NestedModel_Text") },
|
||||||
|
{ models, typeof(NestedModel), () => models[1].NestedModel.Text, "[1].NestedModel.Text",
|
||||||
|
new TagHelperOutputContent("Hello World1", "Hello World2", "Hello World2", "z1__NestedModel_Text") },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,13 +178,30 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
For = modelExpression,
|
For = modelExpression,
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult(tagHelperOutputContent.OriginalChildContent));
|
||||||
var htmlAttributes = new Dictionary<string, string>
|
var htmlAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, htmlAttributes, tagHelperOutputContent.OriginalContent);
|
var output = new TagHelperOutput(expectedTagName, htmlAttributes)
|
||||||
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
|
};
|
||||||
|
|
||||||
|
// LabelTagHelper checks ContentSet so we don't want to forcibly set it if
|
||||||
|
// tagHelperOutputContent.OriginalContent is going to be null or empty.
|
||||||
|
if (!string.IsNullOrEmpty(tagHelperOutputContent.OriginalContent))
|
||||||
|
{
|
||||||
|
output.Content = tagHelperOutputContent.OriginalContent;
|
||||||
|
}
|
||||||
|
|
||||||
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
||||||
var viewContext = TestableHtmlGenerator.GetViewContext(model, htmlGenerator, metadataProvider);
|
var viewContext = TestableHtmlGenerator.GetViewContext(model, htmlGenerator, metadataProvider);
|
||||||
tagHelper.ViewContext = viewContext;
|
tagHelper.ViewContext = viewContext;
|
||||||
|
|
@ -129,7 +212,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(tagHelperOutputContent.ExpectedContent, output.Content);
|
Assert.Equal(tagHelperOutputContent.ExpectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.False(output.SelfClosing);
|
Assert.False(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +227,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
var expectedContent = "original content";
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "label";
|
var expectedTagName = "label";
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
|
|
@ -153,8 +240,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var modelExpression = new ModelExpression(nameof(Model.Text), metadata);
|
var modelExpression = new ModelExpression(nameof(Model.Text), metadata);
|
||||||
var tagHelper = new LabelTagHelper();
|
var tagHelper = new LabelTagHelper();
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(allAttributes: new Dictionary<string, object>(), uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, expectedAttributes, expectedContent);
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
|
||||||
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
|
};
|
||||||
|
|
||||||
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
||||||
Model model = null;
|
Model model = null;
|
||||||
|
|
@ -167,19 +262,27 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TagHelperOutputContent
|
public class TagHelperOutputContent
|
||||||
{
|
{
|
||||||
public TagHelperOutputContent(string outputContent, string expectedContent, string expectedId)
|
public TagHelperOutputContent(string originalChildContent,
|
||||||
|
string outputContent,
|
||||||
|
string expectedContent,
|
||||||
|
string expectedId)
|
||||||
{
|
{
|
||||||
|
OriginalChildContent = originalChildContent;
|
||||||
OriginalContent = outputContent;
|
OriginalContent = outputContent;
|
||||||
ExpectedContent = expectedContent;
|
ExpectedContent = expectedContent;
|
||||||
ExpectedId = expectedId;
|
ExpectedId = expectedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string OriginalChildContent { get; set; }
|
||||||
|
|
||||||
public string OriginalContent { get; set; }
|
public string OriginalContent { get; set; }
|
||||||
|
|
||||||
public string ExpectedContent { get; set; }
|
public string ExpectedContent { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "selected", selected },
|
{ "selected", selected },
|
||||||
{ "value", value },
|
{ "value", value },
|
||||||
};
|
};
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, originalContent)
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult(originalContent));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
Content = originalContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -188,9 +192,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "selected", selected },
|
{ "selected", selected },
|
||||||
{ "value", value },
|
{ "value", value },
|
||||||
};
|
};
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var originalPreContent = "original pre-content";
|
||||||
var output = new TagHelperOutput(originalTagName, originalAttributes, originalContent)
|
var originalPostContent = "original post-content";
|
||||||
|
var tagHelperContext = new TagHelperContext(
|
||||||
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult(originalContent));
|
||||||
|
var output = new TagHelperOutput(originalTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = originalPreContent,
|
||||||
|
Content = originalContent,
|
||||||
|
PostContent = originalPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -235,9 +247,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "selected", selected },
|
{ "selected", selected },
|
||||||
{ "value", value },
|
{ "value", value },
|
||||||
};
|
};
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var originalPreContent = "original pre-content";
|
||||||
var output = new TagHelperOutput(originalTagName, originalAttributes, originalContent)
|
var originalPostContent = "original post-content";
|
||||||
|
var tagHelperContext = new TagHelperContext(
|
||||||
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult(originalContent));
|
||||||
|
var output = new TagHelperOutput(originalTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = originalPreContent,
|
||||||
|
Content = originalContent,
|
||||||
|
PostContent = originalPostContent,
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var originalContent = "original content";
|
var originalPostContent = "original content";
|
||||||
|
|
||||||
var expectedAttributes = new Dictionary<string, string>(originalAttributes)
|
var expectedAttributes = new Dictionary<string, string>(originalAttributes)
|
||||||
{
|
{
|
||||||
|
|
@ -173,7 +173,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "name", nameAndId.Name },
|
{ "name", nameAndId.Name },
|
||||||
{ "valid", "from validation attributes" },
|
{ "valid", "from validation attributes" },
|
||||||
};
|
};
|
||||||
var expectedContent = originalContent;
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = originalPostContent;
|
||||||
var expectedTagName = "not-select";
|
var expectedTagName = "not-select";
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
|
|
@ -182,9 +184,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var metadata = metadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName: "Text");
|
var metadata = metadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName: "Text");
|
||||||
var modelExpression = new ModelExpression(nameAndId.Name, metadata);
|
var modelExpression = new ModelExpression(nameAndId.Name, metadata);
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(new Dictionary<string, object>(), uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, expectedContent)
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = originalPostContent,
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -208,7 +216,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.False(output.SelfClosing);
|
Assert.False(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
|
|
||||||
|
|
@ -235,7 +245,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var originalContent = "original content";
|
var originalPostContent = "original content";
|
||||||
|
|
||||||
var expectedAttributes = new Dictionary<string, string>(originalAttributes)
|
var expectedAttributes = new Dictionary<string, string>(originalAttributes)
|
||||||
{
|
{
|
||||||
|
|
@ -243,7 +253,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "name", nameAndId.Name },
|
{ "name", nameAndId.Name },
|
||||||
{ "valid", "from validation attributes" },
|
{ "valid", "from validation attributes" },
|
||||||
};
|
};
|
||||||
var expectedContent = originalContent + expectedOptions;
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = originalPostContent + expectedOptions;
|
||||||
var expectedTagName = "select";
|
var expectedTagName = "select";
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
|
|
@ -252,9 +264,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var metadata = metadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName: "Text");
|
var metadata = metadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName: "Text");
|
||||||
var modelExpression = new ModelExpression(nameAndId.Name, metadata);
|
var modelExpression = new ModelExpression(nameAndId.Name, metadata);
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(new Dictionary<string, object>(), uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, originalContent)
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = originalPostContent,
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -280,7 +298,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.False(output.SelfClosing);
|
Assert.False(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
|
|
||||||
|
|
@ -308,12 +328,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{ "multiple", multiple },
|
{ "multiple", multiple },
|
||||||
};
|
};
|
||||||
var originalAttributes = new Dictionary<string, string>();
|
var originalAttributes = new Dictionary<string, string>();
|
||||||
var content = "original content";
|
|
||||||
var propertyName = "Property1";
|
var propertyName = "Property1";
|
||||||
var expectedTagName = "select";
|
var expectedTagName = "select";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content);
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes);
|
||||||
|
|
||||||
var metadataProvider = new EmptyModelMetadataProvider();
|
var metadataProvider = new EmptyModelMetadataProvider();
|
||||||
string model = null;
|
string model = null;
|
||||||
|
|
@ -372,12 +394,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var contextAttributes = new Dictionary<string, object>();
|
var contextAttributes = new Dictionary<string, object>();
|
||||||
var originalAttributes = new Dictionary<string, string>();
|
var originalAttributes = new Dictionary<string, string>();
|
||||||
var content = "original content";
|
|
||||||
var propertyName = "Property1";
|
var propertyName = "Property1";
|
||||||
var tagName = "select";
|
var tagName = "select";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(tagName, originalAttributes, content);
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(tagName, originalAttributes);
|
||||||
|
|
||||||
var metadataProvider = new EmptyModelMetadataProvider();
|
var metadataProvider = new EmptyModelMetadataProvider();
|
||||||
var metadata = metadataProvider.GetMetadataForType(() => model, modelType);
|
var metadata = metadataProvider.GetMetadataForType(() => model, modelType);
|
||||||
|
|
@ -437,12 +461,20 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
};
|
};
|
||||||
var expectedAttributes = new Dictionary<string, string>(originalAttributes);
|
var expectedAttributes = new Dictionary<string, string>(originalAttributes);
|
||||||
expectedAttributes[attributeName] = (string)contextAttributes[attributeName];
|
expectedAttributes[attributeName] = (string)contextAttributes[attributeName];
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
var expectedContent = "original content";
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "select";
|
var expectedTagName = "select";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, expectedContent)
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -456,7 +488,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedAttributes, output.Attributes);
|
Assert.Equal(expectedAttributes, output.Attributes);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
Assert.Equal(expectedContent, output.Content);
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.True(output.SelfClosing);
|
Assert.True(output.SelfClosing);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
@ -467,12 +501,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var contextAttributes = new Dictionary<string, object>();
|
var contextAttributes = new Dictionary<string, object>();
|
||||||
var originalAttributes = new Dictionary<string, string>();
|
var originalAttributes = new Dictionary<string, string>();
|
||||||
var content = "original content";
|
|
||||||
var expectedTagName = "select";
|
var expectedTagName = "select";
|
||||||
var expectedMessage = "Cannot determine body for <select>. 'asp-items' must be null if 'asp-for' is null.";
|
var expectedMessage = "Cannot determine body for <select>. 'asp-items' must be null if 'asp-for' is null.";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content);
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes);
|
||||||
var tagHelper = new SelectTagHelper
|
var tagHelper = new SelectTagHelper
|
||||||
{
|
{
|
||||||
Items = Enumerable.Empty<SelectListItem>(),
|
Items = Enumerable.Empty<SelectListItem>(),
|
||||||
|
|
@ -497,13 +533,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var contextAttributes = new Dictionary<string, object>();
|
var contextAttributes = new Dictionary<string, object>();
|
||||||
var originalAttributes = new Dictionary<string, string>();
|
var originalAttributes = new Dictionary<string, string>();
|
||||||
var content = "original content";
|
|
||||||
var expectedTagName = "select";
|
var expectedTagName = "select";
|
||||||
var expectedMessage = "Cannot parse 'multiple' value '" + multiple +
|
var expectedMessage = "Cannot parse 'multiple' value '" + multiple +
|
||||||
"' for <select>. Acceptable values are 'false', 'true' and 'multiple'.";
|
"' for <select>. Acceptable values are 'false', 'true' and 'multiple'.";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(contextAttributes, uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, content);
|
contextAttributes,
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, originalAttributes);
|
||||||
|
|
||||||
var metadataProvider = new EmptyModelMetadataProvider();
|
var metadataProvider = new EmptyModelMetadataProvider();
|
||||||
string model = null;
|
string model = null;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Mvc.Rendering;
|
using Microsoft.AspNet.Mvc.Rendering;
|
||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -19,14 +20,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
var tagHelperContext = new TagHelperContext(
|
var tagHelperContext = new TagHelperContext(
|
||||||
new Dictionary<string, object>(StringComparer.Ordinal)
|
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
|
||||||
{
|
{
|
||||||
{ attributeName, attributeValue }
|
{ attributeName, attributeValue }
|
||||||
},
|
},
|
||||||
uniqueId: "test");
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var expectedAttribute = new KeyValuePair<string, string>(attributeName, attributeValue);
|
var expectedAttribute = new KeyValuePair<string, string>(attributeName, attributeValue);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -47,15 +48,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>()
|
attributes: new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ attributeName, "world2" }
|
{ attributeName, "world2" }
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
|
||||||
var expectedAttribute = new KeyValuePair<string, string>(attributeName, "world2");
|
var expectedAttribute = new KeyValuePair<string, string>(attributeName, "world2");
|
||||||
var tagHelperContext = new TagHelperContext(
|
var tagHelperContext = new TagHelperContext(
|
||||||
new Dictionary<string, object>(StringComparer.Ordinal)
|
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
|
||||||
{
|
{
|
||||||
{ attributeName, "world" }
|
{ attributeName, "world" }
|
||||||
}
|
},
|
||||||
, uniqueId: "test");
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
tagHelperOutput.CopyHtmlAttribute(attributeName, tagHelperContext);
|
tagHelperOutput.CopyHtmlAttribute(attributeName, tagHelperContext);
|
||||||
|
|
@ -75,8 +76,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "route-Hello", "World" },
|
{ "route-Hello", "World" },
|
||||||
{ "Route-I", "Am" }
|
{ "Route-I", "Am" }
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("type", "btn");
|
var expectedAttribute = new KeyValuePair<string, string>("type", "btn");
|
||||||
tagHelperOutput.Attributes.Add(expectedAttribute);
|
tagHelperOutput.Attributes.Add(expectedAttribute);
|
||||||
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
|
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
|
||||||
|
|
@ -99,8 +99,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "routeHello", "World" },
|
{ "routeHello", "World" },
|
||||||
{ "Routee-I", "Am" }
|
{ "Routee-I", "Am" }
|
||||||
},
|
});
|
||||||
content: string.Empty);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
|
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
|
||||||
|
|
@ -119,8 +118,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("type", "btn");
|
var expectedAttribute = new KeyValuePair<string, string>("type", "btn");
|
||||||
tagHelperOutput.Attributes.Add(expectedAttribute);
|
tagHelperOutput.Attributes.Add(expectedAttribute);
|
||||||
|
|
||||||
|
|
@ -141,8 +139,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
tagHelperOutput.Attributes.Add("class", "Hello");
|
tagHelperOutput.Attributes.Add("class", "Hello");
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p");
|
var tagBuilder = new TagBuilder("p");
|
||||||
|
|
@ -168,8 +165,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
tagHelperOutput.Attributes.Add(originalName, "Hello");
|
tagHelperOutput.Attributes.Add(originalName, "Hello");
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p");
|
var tagBuilder = new TagBuilder("p");
|
||||||
|
|
@ -189,8 +185,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p");
|
var tagBuilder = new TagBuilder("p");
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("visible", "val < 3");
|
var expectedAttribute = new KeyValuePair<string, string>("visible", "val < 3");
|
||||||
|
|
@ -210,8 +205,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p");
|
var tagBuilder = new TagBuilder("p");
|
||||||
var expectedAttribute1 = new KeyValuePair<string, string>("class", "btn");
|
var expectedAttribute1 = new KeyValuePair<string, string>("class", "btn");
|
||||||
|
|
@ -236,8 +230,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("class", "btn");
|
var expectedAttribute = new KeyValuePair<string, string>("class", "btn");
|
||||||
tagHelperOutput.Attributes.Add(expectedAttribute);
|
tagHelperOutput.Attributes.Add(expectedAttribute);
|
||||||
|
|
||||||
|
|
@ -257,8 +250,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
"p",
|
"p",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
content: string.Empty);
|
|
||||||
var expectedOutputAttribute = new KeyValuePair<string, string>("class", "btn");
|
var expectedOutputAttribute = new KeyValuePair<string, string>("class", "btn");
|
||||||
tagHelperOutput.Attributes.Add(expectedOutputAttribute);
|
tagHelperOutput.Attributes.Add(expectedOutputAttribute);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,13 +107,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
For = modelExpression,
|
For = modelExpression,
|
||||||
};
|
};
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(new Dictionary<string, object>(), uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var htmlAttributes = new Dictionary<string, string>
|
var htmlAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, htmlAttributes, "original content")
|
var output = new TagHelperOutput(expectedTagName, htmlAttributes)
|
||||||
{
|
{
|
||||||
|
Content = "original content",
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -146,7 +150,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
var expectedContent = "original content";
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var expectedTagName = "textarea";
|
var expectedTagName = "textarea";
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
|
|
@ -157,9 +163,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var modelExpression = new ModelExpression(nameof(Model.Text), metadata);
|
var modelExpression = new ModelExpression(nameof(Model.Text), metadata);
|
||||||
var tagHelper = new TextAreaTagHelper();
|
var tagHelper = new TextAreaTagHelper();
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(new Dictionary<string, object>(), uniqueId: "test");
|
var tagHelperContext = new TagHelperContext(
|
||||||
var output = new TagHelperOutput(expectedTagName, expectedAttributes, expectedContent)
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
|
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
|
||||||
{
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,20 +28,29 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
For = modelExpression
|
For = modelExpression
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(
|
var tagHelperContext = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>
|
allAttributes: new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "id", "myvalidationmessage" },
|
{ "id", "myvalidationmessage" },
|
||||||
{ "for", modelExpression },
|
{ "for", modelExpression },
|
||||||
},
|
},
|
||||||
uniqueId: "test");
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
expectedTagName,
|
expectedTagName,
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "id", "myvalidationmessage" }
|
{ "id", "myvalidationmessage" }
|
||||||
},
|
})
|
||||||
content: "Something");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
|
};
|
||||||
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
||||||
var viewContext = TestableHtmlGenerator.GetViewContext(model: null,
|
var viewContext = TestableHtmlGenerator.GetViewContext(model: null,
|
||||||
htmlGenerator: htmlGenerator,
|
htmlGenerator: htmlGenerator,
|
||||||
|
|
@ -62,7 +71,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal("Name", attribute.Value);
|
Assert.Equal("Name", attribute.Value);
|
||||||
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("data-valmsg-replace"));
|
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("data-valmsg-replace"));
|
||||||
Assert.Equal("true", attribute.Value);
|
Assert.Equal("true", attribute.Value);
|
||||||
Assert.Equal("Something", output.Content);
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,10 +85,21 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
For = CreateModelExpression("Hello")
|
For = CreateModelExpression("Hello")
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
|
var context = new TagHelperContext(
|
||||||
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"span",
|
"span",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: "Content of validation message");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
|
};
|
||||||
var expectedViewContext = CreateViewContext();
|
var expectedViewContext = CreateViewContext();
|
||||||
var generator = new Mock<IHtmlGenerator>();
|
var generator = new Mock<IHtmlGenerator>();
|
||||||
generator
|
generator
|
||||||
|
|
@ -89,19 +111,22 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
validationMessageTagHelper.ViewContext = expectedViewContext;
|
validationMessageTagHelper.ViewContext = expectedViewContext;
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
await validationMessageTagHelper.ProcessAsync(context: null, output: output);
|
await validationMessageTagHelper.ProcessAsync(context, output: output);
|
||||||
|
|
||||||
generator.Verify();
|
generator.Verify();
|
||||||
Assert.Equal("span", output.TagName);
|
Assert.Equal("span", output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.Equal("Content of validation message", output.Content);
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Content of validation message", "Content of validation message")]
|
[InlineData("Content of validation message", "Some Content", "Some Content")]
|
||||||
[InlineData("\r\n \r\n", "New HTML")]
|
[InlineData("\r\n \r\n", "\r\n Something Else \r\n", "\r\n Something Else \r\n")]
|
||||||
public async Task ProcessAsync_MergesTagBuilderFromGenerateValidationMessage(
|
[InlineData("\r\n \r\n", "Some Content", "Some Content")]
|
||||||
string outputContent, string expectedOutputContent)
|
public async Task ProcessAsync_DoesNotOverrideOutputContent(
|
||||||
|
string childContent, string outputContent, string expectedOutputContent)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var validationMessageTagHelper = new ValidationMessageTagHelper
|
var validationMessageTagHelper = new ValidationMessageTagHelper
|
||||||
|
|
@ -110,8 +135,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"span",
|
"span",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: outputContent);
|
{
|
||||||
|
Content = outputContent
|
||||||
|
};
|
||||||
|
|
||||||
|
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult(childContent));
|
||||||
var tagBuilder = new TagBuilder("span2")
|
var tagBuilder = new TagBuilder("span2")
|
||||||
{
|
{
|
||||||
InnerHtml = "New HTML"
|
InnerHtml = "New HTML"
|
||||||
|
|
@ -133,7 +164,58 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
validationMessageTagHelper.Generator = generator.Object;
|
validationMessageTagHelper.Generator = generator.Object;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await validationMessageTagHelper.ProcessAsync(context: null, output: output);
|
await validationMessageTagHelper.ProcessAsync(context, output: output);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal("span", output.TagName);
|
||||||
|
Assert.Equal(2, output.Attributes.Count);
|
||||||
|
var attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("data-foo"));
|
||||||
|
Assert.Equal("bar", attribute.Value);
|
||||||
|
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("data-hello"));
|
||||||
|
Assert.Equal("world", attribute.Value);
|
||||||
|
Assert.Equal(expectedOutputContent, output.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Content of validation message", "Content of validation message")]
|
||||||
|
[InlineData("\r\n \r\n", "New HTML")]
|
||||||
|
public async Task ProcessAsync_MergesTagBuilderFromGenerateValidationMessage(
|
||||||
|
string childContent, string expectedOutputContent)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var validationMessageTagHelper = new ValidationMessageTagHelper
|
||||||
|
{
|
||||||
|
For = CreateModelExpression("Hello")
|
||||||
|
};
|
||||||
|
var output = new TagHelperOutput(
|
||||||
|
"span",
|
||||||
|
attributes: new Dictionary<string, string>());
|
||||||
|
|
||||||
|
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult(childContent));
|
||||||
|
var tagBuilder = new TagBuilder("span2")
|
||||||
|
{
|
||||||
|
InnerHtml = "New HTML"
|
||||||
|
};
|
||||||
|
tagBuilder.Attributes.Add("data-foo", "bar");
|
||||||
|
tagBuilder.Attributes.Add("data-hello", "world");
|
||||||
|
|
||||||
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
|
var setup = generator
|
||||||
|
.Setup(mock => mock.GenerateValidationMessage(
|
||||||
|
It.IsAny<ViewContext>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<object>()))
|
||||||
|
.Returns(tagBuilder);
|
||||||
|
var viewContext = CreateViewContext();
|
||||||
|
validationMessageTagHelper.ViewContext = viewContext;
|
||||||
|
validationMessageTagHelper.Generator = generator.Object;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await validationMessageTagHelper.ProcessAsync(context, output: output);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("span", output.TagName);
|
Assert.Equal("span", output.TagName);
|
||||||
|
|
@ -150,10 +232,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var validationMessageTagHelper = new ValidationMessageTagHelper();
|
var validationMessageTagHelper = new ValidationMessageTagHelper();
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"span",
|
"span",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: "Content of validation message");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
|
};
|
||||||
var viewContext = CreateViewContext();
|
var viewContext = CreateViewContext();
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
validationMessageTagHelper.ViewContext = viewContext;
|
validationMessageTagHelper.ViewContext = viewContext;
|
||||||
|
|
@ -165,7 +254,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("span", output.TagName);
|
Assert.Equal("span", output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.Equal("Content of validation message", output.Content);
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ModelExpression CreateModelExpression(string name)
|
private static ModelExpression CreateModelExpression(string name)
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,23 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
ValidationSummary = ValidationSummary.All,
|
ValidationSummary = ValidationSummary.All,
|
||||||
};
|
};
|
||||||
|
|
||||||
var tagHelperContext = new TagHelperContext(new Dictionary<string, object>(), uniqueId: "test");
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var tagHelperContext = new TagHelperContext(
|
||||||
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
uniqueId: "test",
|
||||||
|
getChildContentAsync: () => Task.FromResult("Something"));
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
expectedTagName,
|
expectedTagName,
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" }
|
{ "class", "form-control" }
|
||||||
},
|
})
|
||||||
content: "Custom Content");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = "Custom Content",
|
||||||
|
};
|
||||||
|
|
||||||
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
var htmlGenerator = new TestableHtmlGenerator(metadataProvider);
|
||||||
Model model = null;
|
Model model = null;
|
||||||
|
|
@ -64,8 +73,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal("form-control validation-summary-valid", attribute.Value);
|
Assert.Equal("form-control validation-summary-valid", attribute.Value);
|
||||||
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("data-valmsg-summary"));
|
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("data-valmsg-summary"));
|
||||||
Assert.Equal("true", attribute.Value);
|
Assert.Equal("true", attribute.Value);
|
||||||
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
Assert.Equal("Custom Content<ul><li style=\"display:none\"></li>" + Environment.NewLine + "</ul>",
|
Assert.Equal("Custom Content<ul><li style=\"display:none\"></li>" + Environment.NewLine + "</ul>",
|
||||||
output.Content);
|
output.PostContent);
|
||||||
Assert.Equal(expectedTagName, output.TagName);
|
Assert.Equal(expectedTagName, output.TagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,10 +92,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
ValidationSummary = validationSummary,
|
ValidationSummary = validationSummary,
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"div",
|
"div",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: "Content of validation summary");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
|
};
|
||||||
var expectedViewContext = CreateViewContext();
|
var expectedViewContext = CreateViewContext();
|
||||||
var generator = new Mock<IHtmlGenerator>();
|
var generator = new Mock<IHtmlGenerator>();
|
||||||
generator
|
generator
|
||||||
|
|
@ -105,7 +123,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
generator.Verify();
|
generator.Verify();
|
||||||
Assert.Equal("div", output.TagName);
|
Assert.Equal("div", output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.Equal("Content of validation summary", output.Content);
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -116,10 +136,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
ValidationSummary = ValidationSummary.ModelOnly,
|
ValidationSummary = ValidationSummary.ModelOnly,
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"div",
|
"div",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: "Content of validation summary");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = "Content of validation summary"
|
||||||
|
};
|
||||||
var tagBuilder = new TagBuilder("span2")
|
var tagBuilder = new TagBuilder("span2")
|
||||||
{
|
{
|
||||||
InnerHtml = "New HTML"
|
InnerHtml = "New HTML"
|
||||||
|
|
@ -154,7 +180,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal("world", attribute.Value);
|
Assert.Equal("world", attribute.Value);
|
||||||
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("anything"));
|
attribute = Assert.Single(output.Attributes, kvp => kvp.Key.Equals("anything"));
|
||||||
Assert.Equal("something", attribute.Value);
|
Assert.Equal("something", attribute.Value);
|
||||||
Assert.Equal("Content of validation summaryNew HTML", output.Content);
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal("Content of validation summaryNew HTML", output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -165,10 +193,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
ValidationSummary = ValidationSummary.None,
|
ValidationSummary = ValidationSummary.None,
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
|
var expectedPostContent = "original post-content";
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"div",
|
"div",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: "Content of validation message");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = expectedPostContent,
|
||||||
|
};
|
||||||
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
var viewContext = CreateViewContext();
|
var viewContext = CreateViewContext();
|
||||||
|
|
@ -181,7 +216,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("div", output.TagName);
|
Assert.Equal("div", output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.Equal("Content of validation message", output.Content);
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal(expectedPostContent, output.PostContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -194,10 +231,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
ValidationSummary = validationSummary,
|
ValidationSummary = validationSummary,
|
||||||
};
|
};
|
||||||
|
var expectedPreContent = "original pre-content";
|
||||||
|
var expectedContent = "original content";
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"div",
|
"div",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>())
|
||||||
content: "Content of validation message");
|
{
|
||||||
|
PreContent = expectedPreContent,
|
||||||
|
Content = expectedContent,
|
||||||
|
PostContent = "Content of validation message",
|
||||||
|
};
|
||||||
var tagBuilder = new TagBuilder("span2")
|
var tagBuilder = new TagBuilder("span2")
|
||||||
{
|
{
|
||||||
InnerHtml = "New HTML"
|
InnerHtml = "New HTML"
|
||||||
|
|
@ -223,7 +266,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("div", output.TagName);
|
Assert.Equal("div", output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.Equal("Content of validation messageNew HTML", output.Content);
|
Assert.Equal(expectedPreContent, output.PreContent);
|
||||||
|
Assert.Equal(expectedContent, output.Content);
|
||||||
|
Assert.Equal("Content of validation messageNew HTML", output.PostContent);
|
||||||
generator.Verify();
|
generator.Verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using Microsoft.AspNet.Mvc.Rendering;
|
using Microsoft.AspNet.Mvc.Rendering;
|
||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ActivatorWebSite.TagHelpers
|
namespace ActivatorWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using Microsoft.AspNet.Mvc.Rendering;
|
using Microsoft.AspNet.Mvc.Rendering;
|
||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ActivatorWebSite.TagHelpers
|
namespace ActivatorWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
|
|
||||||
namespace RequestServicesWebSite
|
namespace RequestServicesWebSite
|
||||||
{
|
{
|
||||||
[ContentBehavior(ContentBehavior.Replace)]
|
|
||||||
public class RequestScopedTagHelper : TagHelper
|
public class RequestScopedTagHelper : TagHelper
|
||||||
{
|
{
|
||||||
[Activate]
|
[Activate]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
|
|
||||||
namespace TagHelpersWebSite.TagHelpers
|
namespace TagHelpersWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
[ContentBehavior(ContentBehavior.Prepend)]
|
|
||||||
public class ATagHelper : TagHelper
|
public class ATagHelper : TagHelper
|
||||||
{
|
{
|
||||||
[Activate]
|
[Activate]
|
||||||
|
|
@ -31,7 +30,7 @@ namespace TagHelpersWebSite.TagHelpers
|
||||||
|
|
||||||
output.Attributes["href"] = UrlHelper.Action(Action, Controller, methodParameters);
|
output.Attributes["href"] = UrlHelper.Action(Action, Controller, methodParameters);
|
||||||
|
|
||||||
output.Content = "My ";
|
output.PreContent = "My ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,22 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using Microsoft.AspNet.Razor.TagHelpers;
|
using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
|
|
||||||
namespace TagHelpersWebSite.TagHelpers
|
namespace TagHelpersWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
[HtmlElementName("p")]
|
[HtmlElementName("p")]
|
||||||
[ContentBehavior(ContentBehavior.Modify)]
|
|
||||||
public class AutoLinkerTagHelper : TagHelper
|
public class AutoLinkerTagHelper : TagHelper
|
||||||
{
|
{
|
||||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
|
||||||
{
|
{
|
||||||
|
var childContent = await context.GetChildContentAsync();
|
||||||
|
|
||||||
// Find Urls in the content and replace them with their anchor tag equivalent.
|
// Find Urls in the content and replace them with their anchor tag equivalent.
|
||||||
output.Content = Regex.Replace(
|
output.Content = Regex.Replace(
|
||||||
output.Content,
|
childContent,
|
||||||
@"\b(?:https?://|www\.)(\S+)\b",
|
@"\b(?:https?://|www\.)(\S+)\b",
|
||||||
"<strong><a target=\"_blank\" href=\"http://$0\">$0</a></strong>");
|
"<strong><a target=\"_blank\" href=\"http://$0\">$0</a></strong>");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
namespace TagHelpersWebSite.TagHelpers
|
namespace TagHelpersWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
[HtmlElementName("div", "style", "p")]
|
[HtmlElementName("div", "style", "p")]
|
||||||
[ContentBehavior(ContentBehavior.Modify)]
|
|
||||||
public class ConditionTagHelper : TagHelper
|
public class ConditionTagHelper : TagHelper
|
||||||
{
|
{
|
||||||
public bool? Condition { get; set; }
|
public bool? Condition { get; set; }
|
||||||
|
|
@ -17,8 +16,7 @@ namespace TagHelpersWebSite.TagHelpers
|
||||||
// If a condition is set and evaluates to false, don't render the tag.
|
// If a condition is set and evaluates to false, don't render the tag.
|
||||||
if (Condition.HasValue && !Condition.Value)
|
if (Condition.HasValue && !Condition.Value)
|
||||||
{
|
{
|
||||||
output.TagName = null;
|
output.SuppressOutput();
|
||||||
output.Content = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
namespace TagHelpersWebSite.TagHelpers
|
namespace TagHelpersWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
[HtmlElementName("nested")]
|
[HtmlElementName("nested")]
|
||||||
[ContentBehavior(ContentBehavior.Modify)]
|
|
||||||
public class NestedViewStartTagHelper : TagHelper
|
public class NestedViewStartTagHelper : TagHelper
|
||||||
{
|
{
|
||||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,10 @@ namespace TagHelpersWebSite.TagHelpers
|
||||||
|
|
||||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||||
{
|
{
|
||||||
if (MakePretty.HasValue && !MakePretty.Value)
|
// Need to check if output.TagName == null in-case the ConditionTagHelper calls into SuppressOutput and
|
||||||
|
// therefore sets the TagName to null.
|
||||||
|
if (MakePretty.HasValue && !MakePretty.Value ||
|
||||||
|
output.TagName == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ using Microsoft.AspNet.Razor.TagHelpers;
|
||||||
namespace TagHelpersWebSite.TagHelpers
|
namespace TagHelpersWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
[HtmlElementName("root")]
|
[HtmlElementName("root")]
|
||||||
[ContentBehavior(ContentBehavior.Replace)]
|
|
||||||
public class RootViewStartTagHelper : TagHelper
|
public class RootViewStartTagHelper : TagHelper
|
||||||
{
|
{
|
||||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ namespace MvcSample.Web.Components
|
||||||
{
|
{
|
||||||
[HtmlElementName("tag-cloud")]
|
[HtmlElementName("tag-cloud")]
|
||||||
[ViewComponent(Name = "Tags")]
|
[ViewComponent(Name = "Tags")]
|
||||||
[ContentBehavior(ContentBehavior.Replace)]
|
|
||||||
public class TagCloudViewComponentTagHelper : ITagHelper
|
public class TagCloudViewComponentTagHelper : ITagHelper
|
||||||
{
|
{
|
||||||
private static readonly string[] Tags =
|
private static readonly string[] Tags =
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,10 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using Microsoft.AspNet.Razor.TagHelpers;
|
|
||||||
using TagHelpersWebSite.Models;
|
using TagHelpersWebSite.Models;
|
||||||
|
|
||||||
namespace TagHelpersWebSite.TagHelpers
|
namespace TagHelpersWebSite.TagHelpers
|
||||||
{
|
{
|
||||||
[ContentBehavior(ContentBehavior.Append)]
|
|
||||||
public class WebsiteInformationTagHelper : TagHelper
|
public class WebsiteInformationTagHelper : TagHelper
|
||||||
{
|
{
|
||||||
public WebsiteContext Info { get; set; }
|
public WebsiteContext Info { get; set; }
|
||||||
|
|
@ -16,7 +14,7 @@ namespace TagHelpersWebSite.TagHelpers
|
||||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||||
{
|
{
|
||||||
output.TagName = "section";
|
output.TagName = "section";
|
||||||
output.Content = string.Format(
|
output.PostContent = string.Format(
|
||||||
"<p><strong>Version:</strong> {0}</p>" + Environment.NewLine +
|
"<p><strong>Version:</strong> {0}</p>" + Environment.NewLine +
|
||||||
"<p><strong>Copyright Year:</strong> {1}</p>" + Environment.NewLine +
|
"<p><strong>Copyright Year:</strong> {1}</p>" + Environment.NewLine +
|
||||||
"<p><strong>Approved:</strong> {2}</p>" + Environment.NewLine +
|
"<p><strong>Approved:</strong> {2}</p>" + Environment.NewLine +
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue