Reacting to Razor changes for removing Generate*() method.
This commit is contained in:
parent
489fc52df8
commit
c1338a0542
|
|
@ -92,15 +92,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin),
|
ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin),
|
||||||
ScopeManagerEndMethodName = nameof(TagHelperScopeManager.End),
|
ScopeManagerEndMethodName = nameof(TagHelperScopeManager.End),
|
||||||
|
|
||||||
OutputGenerateStartTagMethodName = nameof(TagHelperOutput.GenerateStartTag),
|
|
||||||
OutputGenerateContentMethodName = nameof(TagHelperOutput.GenerateContent),
|
|
||||||
OutputGenerateEndTagMethodName = nameof(TagHelperOutput.GenerateEndTag),
|
|
||||||
|
|
||||||
// Can't use nameof because RazorPage is not accessible here.
|
// Can't use nameof because RazorPage is not accessible here.
|
||||||
CreateTagHelperMethodName = "CreateTagHelper",
|
CreateTagHelperMethodName = "CreateTagHelper",
|
||||||
StartTagHelperWritingScopeMethodName = "StartTagHelperWritingScope",
|
StartTagHelperWritingScopeMethodName = "StartTagHelperWritingScope",
|
||||||
EndTagHelperWritingScopeMethodName = "EndTagHelperWritingScope",
|
EndTagHelperWritingScopeMethodName = "EndTagHelperWritingScope",
|
||||||
HtmlEncoderPropertyName = "HtmlEncoder",
|
|
||||||
|
WriteTagHelperAsyncMethodName = "WriteTagHelperAsync",
|
||||||
|
WriteTagHelperToAsyncMethodName = "WriteTagHelperToAsync",
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
ResolveUrlMethodName = "Href",
|
ResolveUrlMethodName = "Href",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
@ -250,25 +251,88 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an <see cref="ITextWriterCopyable"/> to the <see cref="Output"/>.
|
/// Writes the content of a specified <paramref name="tagHelperExecutionContext"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="copyableTextWriter">Contains the data to be written.</param>
|
/// <param name="tagHelperExecutionContext">The execution context containing the content.</param>
|
||||||
public void Write(ITextWriterCopyable copyableTextWriter)
|
/// <returns>
|
||||||
|
/// A <see cref="Task"/> that on completion writes the <paramref name="tagHelperExecutionContext"/> content.
|
||||||
|
/// </returns>
|
||||||
|
public async Task WriteTagHelperAsync([NotNull] TagHelperExecutionContext tagHelperExecutionContext)
|
||||||
{
|
{
|
||||||
WriteTo(Output, copyableTextWriter);
|
await WriteTagHelperToAsync(Output, tagHelperExecutionContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes an <see cref="ITextWriterCopyable"/> to the <paramref name="writer"/>.
|
/// Writes the content of a specified <paramref name="tagHelperExecutionContext"/> to the specified
|
||||||
|
/// <paramref name="writer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="writer">The <see cref="TextWriter"/> to which the
|
/// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param>
|
||||||
/// <paramref name="copyableTextWriter"/> is written.</param>
|
/// <param name="tagHelperExecutionContext">The execution context containing the content.</param>
|
||||||
/// <param name="copyableTextWriter">Contains the data to be written.</param>
|
/// <returns>
|
||||||
public void WriteTo([NotNull] TextWriter writer, ITextWriterCopyable copyableTextWriter)
|
/// A <see cref="Task"/> that on completion writes the <paramref name="tagHelperExecutionContext"/> content
|
||||||
|
/// to the <paramref name="writer"/>.
|
||||||
|
/// </returns>
|
||||||
|
public async Task WriteTagHelperToAsync(
|
||||||
|
[NotNull] TextWriter writer,
|
||||||
|
[NotNull] TagHelperExecutionContext tagHelperExecutionContext)
|
||||||
{
|
{
|
||||||
if (copyableTextWriter != null)
|
var tagHelperOutput = tagHelperExecutionContext.Output;
|
||||||
|
var isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(tagHelperOutput.TagName);
|
||||||
|
|
||||||
|
if (!isTagNameNullOrWhitespace)
|
||||||
{
|
{
|
||||||
copyableTextWriter.CopyTo(writer);
|
writer.Write('<');
|
||||||
|
writer.Write(tagHelperOutput.TagName);
|
||||||
|
|
||||||
|
foreach (var attribute in tagHelperOutput.Attributes)
|
||||||
|
{
|
||||||
|
var value = HtmlEncoder.HtmlEncode(attribute.Value);
|
||||||
|
writer.Write(' ');
|
||||||
|
writer.Write(attribute.Key);
|
||||||
|
writer.Write("=\"");
|
||||||
|
writer.Write(value);
|
||||||
|
writer.Write('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tagHelperOutput.SelfClosing)
|
||||||
|
{
|
||||||
|
writer.Write(" /");
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Write('>');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTagNameNullOrWhitespace || !tagHelperOutput.SelfClosing)
|
||||||
|
{
|
||||||
|
WriteTagHelperContentTo(writer, tagHelperOutput.PreContent);
|
||||||
|
if (tagHelperOutput.IsContentModified)
|
||||||
|
{
|
||||||
|
WriteTagHelperContentTo(writer, tagHelperOutput.Content);
|
||||||
|
}
|
||||||
|
else if (tagHelperExecutionContext.ChildContentRetrieved)
|
||||||
|
{
|
||||||
|
var childContent = await tagHelperExecutionContext.GetChildContentAsync();
|
||||||
|
WriteTagHelperContentTo(writer, childContent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await tagHelperExecutionContext.ExecuteChildContentAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteTagHelperContentTo(writer, tagHelperOutput.PostContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isTagNameNullOrWhitespace && !tagHelperOutput.SelfClosing)
|
||||||
|
{
|
||||||
|
writer.Write(string.Format(CultureInfo.InvariantCulture, "</{0}>", tagHelperOutput.TagName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteTagHelperContentTo(TextWriter writer, TagHelperContent content)
|
||||||
|
{
|
||||||
|
foreach (var entry in content)
|
||||||
|
{
|
||||||
|
writer.Write(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,20 +374,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This path is called when GetChildContentAsync() is called in tag helper
|
WriteTo(writer, value.ToString());
|
||||||
// and content is not set.
|
|
||||||
var tagHelperContent = value as TagHelperContent;
|
|
||||||
if (tagHelperContent != null)
|
|
||||||
{
|
|
||||||
foreach (var entry in tagHelperContent)
|
|
||||||
{
|
|
||||||
writer.Write(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WriteTo(writer, value.ToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Select this <option/> element if value attribute or content matches a selected value. Callers
|
// Select this <option/> element if value attribute or content matches a selected value. Callers
|
||||||
// encode values as-needed while executing child content. But TagHelperOutput itself
|
// encode values as-needed while executing child content. But TagHelperOutput itself
|
||||||
// encodes attribute values later, when GenerateStartTag() is called.
|
// encodes attribute values later, when start tag is generated.
|
||||||
bool selected;
|
bool selected;
|
||||||
if (Value != null)
|
if (Value != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Asp
|
||||||
#pragma warning disable 1998
|
#pragma warning disable 1998
|
||||||
public override async Task ExecuteAsync()
|
public override async Task ExecuteAsync()
|
||||||
{
|
{
|
||||||
__tagHelperRunner = __tagHelperRunner ?? new Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperRunner(HtmlEncoder);
|
__tagHelperRunner = __tagHelperRunner ?? new Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperRunner();
|
||||||
BeginContext(120, 2, true);
|
BeginContext(120, 2, true);
|
||||||
WriteLiteral("\r\n");
|
WriteLiteral("\r\n");
|
||||||
EndContext();
|
EndContext();
|
||||||
|
|
@ -58,22 +58,7 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
|
||||||
#line hidden
|
#line hidden
|
||||||
__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());
|
WriteTagHelperAsync(__tagHelperExecutionContext).Wait();
|
||||||
Write(__tagHelperExecutionContext.Output.GeneratePreContent());
|
|
||||||
if (__tagHelperExecutionContext.Output.IsContentModified)
|
|
||||||
{
|
|
||||||
Write(__tagHelperExecutionContext.Output.GenerateContent());
|
|
||||||
}
|
|
||||||
else if (__tagHelperExecutionContext.ChildContentRetrieved)
|
|
||||||
{
|
|
||||||
Write(__tagHelperExecutionContext.GetChildContentAsync().Result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
__tagHelperExecutionContext.ExecuteChildContentAsync().Wait();
|
|
||||||
}
|
|
||||||
Write(__tagHelperExecutionContext.Output.GeneratePostContent());
|
|
||||||
WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag());
|
|
||||||
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
||||||
BeginContext(146, 2, true);
|
BeginContext(146, 2, true);
|
||||||
WriteLiteral("\r\n");
|
WriteLiteral("\r\n");
|
||||||
|
|
@ -90,22 +75,7 @@ __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__mo
|
||||||
#line hidden
|
#line hidden
|
||||||
__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());
|
WriteTagHelperAsync(__tagHelperExecutionContext).Wait();
|
||||||
Write(__tagHelperExecutionContext.Output.GeneratePreContent());
|
|
||||||
if (__tagHelperExecutionContext.Output.IsContentModified)
|
|
||||||
{
|
|
||||||
Write(__tagHelperExecutionContext.Output.GenerateContent());
|
|
||||||
}
|
|
||||||
else if (__tagHelperExecutionContext.ChildContentRetrieved)
|
|
||||||
{
|
|
||||||
Write(__tagHelperExecutionContext.GetChildContentAsync().Result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
__tagHelperExecutionContext.ExecuteChildContentAsync().Wait();
|
|
||||||
}
|
|
||||||
Write(__tagHelperExecutionContext.Output.GeneratePostContent());
|
|
||||||
WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag());
|
|
||||||
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
||||||
}
|
}
|
||||||
#pragma warning restore 1998
|
#pragma warning restore 1998
|
||||||
|
|
|
||||||
|
|
@ -687,96 +687,245 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Assert.Same(stringCollectionWriter.Buffer.BufferEntries, buffer.BufferEntries[1]);
|
Assert.Same(stringCollectionWriter.Buffer.BufferEntries, buffer.BufferEntries[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
public static TheoryData<TagHelperOutput, string> WriteTagHelper_InputData
|
||||||
public async Task Write_ITextWriterCopyable_WritesContent()
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// parameters: TagHelperOutput, expectedOutput
|
||||||
|
return new TheoryData<TagHelperOutput, string>
|
||||||
|
{
|
||||||
|
{
|
||||||
|
// parameters: TagName, Attributes, SelfClosing, PreContent, Content, PostContent
|
||||||
|
GetTagHelperOutput("div", new Dictionary<string, string>(), false, null, "Hello World!", null),
|
||||||
|
"<div>Hello World!</div>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput(null, new Dictionary<string, string>(), false, null, "Hello World!", null),
|
||||||
|
"Hello World!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput(" ", new Dictionary<string, string>(), false, null, "Hello World!", null),
|
||||||
|
"Hello World!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"p",
|
||||||
|
new Dictionary<string, string>() { { "test", "testVal" } },
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
"Hello World!",
|
||||||
|
null),
|
||||||
|
"<p test=\"testVal\">Hello World!</p>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"p",
|
||||||
|
new Dictionary<string, string>() { { "test", "testVal" }, { "something", " spaced " } },
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
"Hello World!",
|
||||||
|
null),
|
||||||
|
"<p test=\"testVal\" something=\" spaced \">Hello World!</p>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"p",
|
||||||
|
new Dictionary<string, string>() { { "test", "testVal" } },
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
"Hello World!",
|
||||||
|
null),
|
||||||
|
"<p test=\"testVal\" />"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"p",
|
||||||
|
new Dictionary<string, string>() { { "test", "testVal" }, { "something", " spaced " } },
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
"Hello World!",
|
||||||
|
null),
|
||||||
|
"<p test=\"testVal\" something=\" spaced \" />"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput("p", new Dictionary<string, string>(), false, "Hello World!", null, null),
|
||||||
|
"<p>Hello World!</p>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput("p", new Dictionary<string, string>(), false, null, "Hello World!", null),
|
||||||
|
"<p>Hello World!</p>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput("p", new Dictionary<string, string>(), false, null, null, "Hello World!"),
|
||||||
|
"<p>Hello World!</p>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput("p", new Dictionary<string, string>(), false, "Hello", "Test", "World!"),
|
||||||
|
"<p>HelloTestWorld!</p>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput("p", new Dictionary<string, string>(), true, "Hello", "Test", "World!"),
|
||||||
|
"<p />"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput("custom", new Dictionary<string, string>(), false, "Hello", "Test", "World!"),
|
||||||
|
"<custom>HelloTestWorld!</custom>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
GetTagHelperOutput("random", new Dictionary<string, string>(), true, "Hello", "Test", "World!"),
|
||||||
|
"<random />"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(WriteTagHelper_InputData))]
|
||||||
|
public async Task WriteTagHelperAsync_WritesFormattedTagHelper(TagHelperOutput output, string expected)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// This writer uses BufferEntryCollection underneath and so can copy the buffer.
|
|
||||||
var writer = new StringCollectionTextWriter(Encoding.UTF8);
|
var writer = new StringCollectionTextWriter(Encoding.UTF8);
|
||||||
var context = CreateViewContext(writer);
|
var context = CreateViewContext(writer);
|
||||||
var expectedContent = "Hello World!";
|
var tagHelperExecutionContext = new TagHelperExecutionContext(
|
||||||
var contentToBeCopied = new DefaultTagHelperContent().SetContent("Hello ").Append("World!");
|
tagName: output.TagName,
|
||||||
|
selfClosing: output.SelfClosing,
|
||||||
|
items: new Dictionary<object, object>(),
|
||||||
|
uniqueId: string.Empty,
|
||||||
|
executeChildContentAsync: () => Task.FromResult(result: true),
|
||||||
|
startTagHelperWritingScope: () => { },
|
||||||
|
endTagHelperWritingScope: () => new DefaultTagHelperContent());
|
||||||
|
tagHelperExecutionContext.Output = output;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var page = CreatePage(p =>
|
var page = CreatePage(p =>
|
||||||
{
|
{
|
||||||
p.Write((ITextWriterCopyable)contentToBeCopied);
|
p.HtmlEncoder = new HtmlEncoder();
|
||||||
|
p.WriteTagHelperAsync(tagHelperExecutionContext).Wait();
|
||||||
}, context);
|
}, context);
|
||||||
await page.ExecuteAsync();
|
await page.ExecuteAsync();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedContent, writer.ToString());
|
Assert.Equal(expected, writer.ToString());
|
||||||
Assert.Equal(2, writer.Buffer.BufferEntries.Count);
|
|
||||||
var expectedList = new List<object>();
|
|
||||||
expectedList.Add("Hello ");
|
|
||||||
expectedList.Add("World!");
|
|
||||||
Assert.Equal(expectedList, writer.Buffer.BufferEntries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public async Task Write_ITextWriterCopyable_WritesContent_AsString()
|
// This is a scenario where GetChildContentAsync is called.
|
||||||
|
[InlineData(true, "HelloWorld!", "<p>HelloWorld!</p>")]
|
||||||
|
// This is a scenario where ExecuteChildContentAsync is called.
|
||||||
|
[InlineData(false, "HelloWorld!", "<p></p>")]
|
||||||
|
public async Task WriteTagHelperAsync_WritesContentAppropriately(
|
||||||
|
bool childContentRetrieved, string input, string expected)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// This writer stores the data as a string.
|
var defaultTagHelperContent = new DefaultTagHelperContent();
|
||||||
var writer = new StringWriter();
|
|
||||||
var context = CreateViewContext(writer);
|
|
||||||
var expectedContent = "Hello World!";
|
|
||||||
var contentToBeCopied = new DefaultTagHelperContent().SetContent("Hello ").Append("World!");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var page = CreatePage(p =>
|
|
||||||
{
|
|
||||||
p.Write((ITextWriterCopyable)contentToBeCopied);
|
|
||||||
}, context);
|
|
||||||
await page.ExecuteAsync();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(expectedContent, writer.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WriteTo_ITextWriterCopyable_WritesContent_ToSpecifiedWriter()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var writer = new StringWriter();
|
|
||||||
var expectedContent = "Hello World!";
|
|
||||||
var contentToBeCopied = new DefaultTagHelperContent().SetContent("Hello ").Append("World!");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var page = CreatePage(p =>
|
|
||||||
{
|
|
||||||
p.WriteTo(writer, (ITextWriterCopyable)contentToBeCopied);
|
|
||||||
});
|
|
||||||
await page.ExecuteAsync();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(expectedContent, writer.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task Write_TagHelperContent_WritesContent()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
// This writer uses BufferEntryCollection underneath and so can copy the buffer.
|
|
||||||
var writer = new StringCollectionTextWriter(Encoding.UTF8);
|
var writer = new StringCollectionTextWriter(Encoding.UTF8);
|
||||||
var context = CreateViewContext(writer);
|
var context = CreateViewContext(writer);
|
||||||
var expectedContent = "Hello World!";
|
var tagHelperExecutionContext = new TagHelperExecutionContext(
|
||||||
var contentToBeCopied = new DefaultTagHelperContent().SetContent("Hello ").Append("World!");
|
tagName: "p",
|
||||||
|
selfClosing: false,
|
||||||
|
items: new Dictionary<object, object>(),
|
||||||
|
uniqueId: string.Empty,
|
||||||
|
executeChildContentAsync: () => {
|
||||||
|
defaultTagHelperContent.SetContent(input);
|
||||||
|
return Task.FromResult(result: true);
|
||||||
|
},
|
||||||
|
startTagHelperWritingScope: () => { },
|
||||||
|
endTagHelperWritingScope: () => defaultTagHelperContent);
|
||||||
|
tagHelperExecutionContext.Output =
|
||||||
|
new TagHelperOutput("p", new Dictionary<string, string>());
|
||||||
|
if (childContentRetrieved)
|
||||||
|
{
|
||||||
|
await tagHelperExecutionContext.GetChildContentAsync();
|
||||||
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var page = CreatePage(p =>
|
var page = CreatePage(p =>
|
||||||
{
|
{
|
||||||
p.Write(contentToBeCopied);
|
p.HtmlEncoder = new HtmlEncoder();
|
||||||
|
p.WriteTagHelperAsync(tagHelperExecutionContext).Wait();
|
||||||
}, context);
|
}, context);
|
||||||
await page.ExecuteAsync();
|
await page.ExecuteAsync();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedContent, writer.ToString());
|
Assert.Equal(expected, writer.ToString());
|
||||||
Assert.Equal(2, writer.Buffer.BufferEntries.Count);
|
}
|
||||||
var expectedList = new List<object>();
|
|
||||||
expectedList.Add("Hello ");
|
[Fact]
|
||||||
expectedList.Add("World!");
|
public async Task WriteTagHelperToAsync_WritesToSpecifiedWriter()
|
||||||
Assert.Equal(expectedList, writer.Buffer.BufferEntries);
|
{
|
||||||
|
// Arrange
|
||||||
|
var writer = new StringCollectionTextWriter(Encoding.UTF8);
|
||||||
|
var context = CreateViewContext(new StringWriter());
|
||||||
|
var tagHelperExecutionContext = new TagHelperExecutionContext(
|
||||||
|
tagName: "p",
|
||||||
|
selfClosing: false,
|
||||||
|
items: new Dictionary<object, object>(),
|
||||||
|
uniqueId: string.Empty,
|
||||||
|
executeChildContentAsync: () => { return Task.FromResult(result: true); },
|
||||||
|
startTagHelperWritingScope: () => { },
|
||||||
|
endTagHelperWritingScope: () => new DefaultTagHelperContent());
|
||||||
|
tagHelperExecutionContext.Output =
|
||||||
|
new TagHelperOutput("p", new Dictionary<string, string>());
|
||||||
|
tagHelperExecutionContext.Output.Content.SetContent("Hello World!");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var page = CreatePage(p =>
|
||||||
|
{
|
||||||
|
p.WriteTagHelperToAsync(writer, tagHelperExecutionContext).Wait();
|
||||||
|
}, context);
|
||||||
|
await page.ExecuteAsync();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal("<p>Hello World!</p>", writer.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(WriteTagHelper_InputData))]
|
||||||
|
public async Task WriteTagHelperToAsync_WritesFormattedTagHelper(TagHelperOutput output, string expected)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var writer = new StringCollectionTextWriter(Encoding.UTF8);
|
||||||
|
var context = CreateViewContext(new StringWriter());
|
||||||
|
var tagHelperExecutionContext = new TagHelperExecutionContext(
|
||||||
|
tagName: output.TagName,
|
||||||
|
selfClosing: output.SelfClosing,
|
||||||
|
items: new Dictionary<object, object>(),
|
||||||
|
uniqueId: string.Empty,
|
||||||
|
executeChildContentAsync: () => Task.FromResult(result: true),
|
||||||
|
startTagHelperWritingScope: () => { },
|
||||||
|
endTagHelperWritingScope: () => new DefaultTagHelperContent());
|
||||||
|
tagHelperExecutionContext.Output = output;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var page = CreatePage(p =>
|
||||||
|
{
|
||||||
|
p.HtmlEncoder = new HtmlEncoder();
|
||||||
|
p.WriteTagHelperToAsync(writer, tagHelperExecutionContext).Wait();
|
||||||
|
}, context);
|
||||||
|
await page.ExecuteAsync();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(expected, writer.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TagHelperOutput GetTagHelperOutput(
|
||||||
|
string tagName,
|
||||||
|
IDictionary<string, string> attributes,
|
||||||
|
bool selfClosing,
|
||||||
|
string preContent,
|
||||||
|
string content,
|
||||||
|
string postContent)
|
||||||
|
{
|
||||||
|
var output = new TagHelperOutput(tagName, attributes)
|
||||||
|
{
|
||||||
|
SelfClosing = selfClosing
|
||||||
|
};
|
||||||
|
|
||||||
|
output.PreContent.SetContent(preContent);
|
||||||
|
output.Content.SetContent(content);
|
||||||
|
output.PostContent.SetContent(postContent);
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TestableRazorPage CreatePage(Action<TestableRazorPage> executeAction,
|
private static TestableRazorPage CreatePage(Action<TestableRazorPage> executeAction,
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "id", "myanchor" },
|
{ "id", "myanchor" },
|
||||||
{ "asp-route-foo", "bar" },
|
{ "asp-route-foo", "bar" },
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.Content.SetContent("Something");
|
output.Content.SetContent("Something");
|
||||||
|
|
||||||
var urlHelper = new Mock<IUrlHelper>();
|
var urlHelper = new Mock<IUrlHelper>();
|
||||||
|
|
@ -98,8 +97,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"a",
|
"a",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.Content.SetContent(string.Empty);
|
output.Content.SetContent(string.Empty);
|
||||||
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
|
|
@ -141,8 +139,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"a",
|
"a",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.Content.SetContent(string.Empty);
|
output.Content.SetContent(string.Empty);
|
||||||
|
|
||||||
var generator = new Mock<IHtmlGenerator>();
|
var generator = new Mock<IHtmlGenerator>();
|
||||||
|
|
@ -186,8 +183,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" }
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
if (propertyName == "asp-route-")
|
if (propertyName == "asp-route-")
|
||||||
{
|
{
|
||||||
output.Attributes.Add("asp-route-foo", "bar");
|
output.Attributes.Add("asp-route-foo", "bar");
|
||||||
|
|
@ -222,8 +218,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
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.";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var childContent = "original-child-content";
|
var childContent = "original-child-content";
|
||||||
var cache = new MemoryCache(new MemoryCacheOptions());
|
var cache = new MemoryCache(new MemoryCacheOptions());
|
||||||
var tagHelperContext1 = GetTagHelperContext(id, childContent);
|
var tagHelperContext1 = GetTagHelperContext(id, childContent);
|
||||||
var tagHelperOutput1 = new TagHelperOutput("cache", new Dictionary<string, string>(), new HtmlEncoder());
|
var tagHelperOutput1 = new TagHelperOutput("cache", new Dictionary<string, string>());
|
||||||
var cacheTagHelper1 = new CacheTagHelper
|
var cacheTagHelper1 = new CacheTagHelper
|
||||||
{
|
{
|
||||||
VaryByQuery = "key1,key2",
|
VaryByQuery = "key1,key2",
|
||||||
|
|
@ -266,7 +266,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
||||||
// Arrange - 2
|
// Arrange - 2
|
||||||
var tagHelperContext2 = GetTagHelperContext(id, "different-content");
|
var tagHelperContext2 = GetTagHelperContext(id, "different-content");
|
||||||
var tagHelperOutput2 = new TagHelperOutput("cache", new Dictionary<string, string>(), new HtmlEncoder());
|
var tagHelperOutput2 = new TagHelperOutput("cache", new Dictionary<string, string>());
|
||||||
var cacheTagHelper2 = new CacheTagHelper
|
var cacheTagHelper2 = new CacheTagHelper
|
||||||
{
|
{
|
||||||
VaryByQuery = "key1,key2",
|
VaryByQuery = "key1,key2",
|
||||||
|
|
@ -295,8 +295,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var cache = new MemoryCache(new MemoryCacheOptions());
|
var cache = new MemoryCache(new MemoryCacheOptions());
|
||||||
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
||||||
var tagHelperOutput1 = new TagHelperOutput("cache",
|
var tagHelperOutput1 = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput1.PreContent.Append("<cache>");
|
tagHelperOutput1.PreContent.Append("<cache>");
|
||||||
tagHelperOutput1.PostContent.SetContent("</cache>");
|
tagHelperOutput1.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper1 = new CacheTagHelper
|
var cacheTagHelper1 = new CacheTagHelper
|
||||||
|
|
@ -321,8 +320,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
||||||
var tagHelperOutput2 = new TagHelperOutput(
|
var tagHelperOutput2 = new TagHelperOutput(
|
||||||
"cache",
|
"cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput2.PreContent.SetContent("<cache>");
|
tagHelperOutput2.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput2.PostContent.SetContent("</cache>");
|
tagHelperOutput2.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper2 = new CacheTagHelper
|
var cacheTagHelper2 = new CacheTagHelper
|
||||||
|
|
@ -532,8 +530,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var cache = new MemoryCache(new MemoryCacheOptions { Clock = clock.Object });
|
var cache = new MemoryCache(new MemoryCacheOptions { Clock = clock.Object });
|
||||||
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
||||||
var tagHelperOutput1 = new TagHelperOutput("cache",
|
var tagHelperOutput1 = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput1.PreContent.SetContent("<cache>");
|
tagHelperOutput1.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput1.PostContent.SetContent("</cache>");
|
tagHelperOutput1.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper1 = new CacheTagHelper
|
var cacheTagHelper1 = new CacheTagHelper
|
||||||
|
|
@ -556,8 +553,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var childContent2 = "different-content";
|
var childContent2 = "different-content";
|
||||||
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
||||||
var tagHelperOutput2 = new TagHelperOutput("cache",
|
var tagHelperOutput2 = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput2.PreContent.SetContent("<cache>");
|
tagHelperOutput2.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput2.PostContent.SetContent("</cache>");
|
tagHelperOutput2.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper2 = new CacheTagHelper
|
var cacheTagHelper2 = new CacheTagHelper
|
||||||
|
|
@ -591,8 +587,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var cache = new MemoryCache(new MemoryCacheOptions { Clock = clock.Object });
|
var cache = new MemoryCache(new MemoryCacheOptions { Clock = clock.Object });
|
||||||
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
||||||
var tagHelperOutput1 = new TagHelperOutput("cache",
|
var tagHelperOutput1 = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput1.PreContent.SetContent("<cache>");
|
tagHelperOutput1.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput1.PostContent.SetContent("</cache>");
|
tagHelperOutput1.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper1 = new CacheTagHelper
|
var cacheTagHelper1 = new CacheTagHelper
|
||||||
|
|
@ -616,8 +611,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var childContent2 = "different-content";
|
var childContent2 = "different-content";
|
||||||
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
||||||
var tagHelperOutput2 = new TagHelperOutput("cache",
|
var tagHelperOutput2 = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput2.PreContent.SetContent("<cache>");
|
tagHelperOutput2.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput2.PostContent.SetContent("</cache>");
|
tagHelperOutput2.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper2 = new CacheTagHelper
|
var cacheTagHelper2 = new CacheTagHelper
|
||||||
|
|
@ -650,8 +644,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var cache = new MemoryCache(new MemoryCacheOptions { Clock = clock.Object });
|
var cache = new MemoryCache(new MemoryCacheOptions { Clock = clock.Object });
|
||||||
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
|
||||||
var tagHelperOutput1 = new TagHelperOutput("cache",
|
var tagHelperOutput1 = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput1.PreContent.SetContent("<cache>");
|
tagHelperOutput1.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput1.PostContent.SetContent("</cache>");
|
tagHelperOutput1.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper1 = new CacheTagHelper
|
var cacheTagHelper1 = new CacheTagHelper
|
||||||
|
|
@ -675,8 +668,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var childContent2 = "different-content";
|
var childContent2 = "different-content";
|
||||||
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
|
||||||
var tagHelperOutput2 = new TagHelperOutput("cache",
|
var tagHelperOutput2 = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput2.PreContent.SetContent("<cache>");
|
tagHelperOutput2.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput2.PostContent.SetContent("</cache>");
|
tagHelperOutput2.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper2 = new CacheTagHelper
|
var cacheTagHelper2 = new CacheTagHelper
|
||||||
|
|
@ -720,8 +712,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
return Task.FromResult<TagHelperContent>(expectedContent);
|
return Task.FromResult<TagHelperContent>(expectedContent);
|
||||||
});
|
});
|
||||||
var tagHelperOutput = new TagHelperOutput("cache",
|
var tagHelperOutput = new TagHelperOutput("cache",
|
||||||
new Dictionary<string, string> { { "attr", "value" } },
|
new Dictionary<string, string> { { "attr", "value" } });
|
||||||
new HtmlEncoder());
|
|
||||||
tagHelperOutput.PreContent.SetContent("<cache>");
|
tagHelperOutput.PreContent.SetContent("<cache>");
|
||||||
tagHelperOutput.PostContent.SetContent("</cache>");
|
tagHelperOutput.PostContent.SetContent("</cache>");
|
||||||
var cacheTagHelper = new CacheTagHelper
|
var cacheTagHelper = new CacheTagHelper
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Test
|
||||||
{
|
{
|
||||||
attributes = attributes ?? new Dictionary<string, string>();
|
attributes = attributes ?? new Dictionary<string, string>();
|
||||||
|
|
||||||
return new TagHelperOutput(tagName, attributes, new HtmlEncoder());
|
return new TagHelperOutput(tagName, attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -49,8 +49,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "id", "myform" },
|
{ "id", "myform" },
|
||||||
{ "asp-route-foo", "bar" },
|
{ "asp-route-foo", "bar" },
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PostContent.SetContent("Something");
|
output.PostContent.SetContent("Something");
|
||||||
var urlHelper = new Mock<IUrlHelper>();
|
var urlHelper = new Mock<IUrlHelper>();
|
||||||
urlHelper
|
urlHelper
|
||||||
|
|
@ -111,8 +110,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"form",
|
"form",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
generator
|
generator
|
||||||
.Setup(mock => mock.GenerateForm(
|
.Setup(mock => mock.GenerateForm(
|
||||||
|
|
@ -168,8 +166,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "asp-route-val", "hello" },
|
{ "asp-route-val", "hello" },
|
||||||
{ "asp-roUte--Foo", "bar" }
|
{ "asp-roUte--Foo", "bar" }
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.Attributes.Add(expectedAttribute);
|
output.Attributes.Add(expectedAttribute);
|
||||||
|
|
||||||
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||||
|
|
@ -235,8 +232,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(
|
var output = new TagHelperOutput(
|
||||||
"form",
|
"form",
|
||||||
attributes: new Dictionary<string, string>(),
|
attributes: new Dictionary<string, string>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
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))
|
||||||
|
|
@ -279,8 +275,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "aCTiON", htmlAction },
|
{ "aCTiON", htmlAction },
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
|
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>()
|
allAttributes: new Dictionary<string, object>()
|
||||||
|
|
@ -336,8 +331,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "aCTiON", "my-action" },
|
{ "aCTiON", "my-action" },
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(),
|
allAttributes: new Dictionary<string, object>(),
|
||||||
items: new Dictionary<object, object>(),
|
items: new Dictionary<object, object>(),
|
||||||
|
|
@ -379,8 +373,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "action", "my-action" },
|
{ "action", "my-action" },
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
if (propertyName == "asp-route-")
|
if (propertyName == "asp-route-")
|
||||||
{
|
{
|
||||||
tagHelperOutput.Attributes.Add("asp-route-foo", "bar");
|
tagHelperOutput.Attributes.Add("asp-route-foo", "bar");
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -170,7 +170,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(originalTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(originalTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
@ -266,7 +266,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -365,7 +365,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -461,7 +461,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -566,7 +566,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -643,7 +643,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
var output = new TagHelperOutput(expectedTagName, expectedAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -709,7 +709,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder());
|
var output = new TagHelperOutput(expectedTagName, originalAttributes);
|
||||||
var tagHelper = new InputTagHelper
|
var tagHelper = new InputTagHelper
|
||||||
{
|
{
|
||||||
Format = "{0}",
|
Format = "{0}",
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, htmlAttributes, new HtmlEncoder());
|
var output = new TagHelperOutput(expectedTagName, htmlAttributes);
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.PostContent.SetContent(expectedPostContent);
|
output.PostContent.SetContent(expectedPostContent);
|
||||||
|
|
||||||
|
|
@ -259,7 +259,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, expectedAttributes, new HtmlEncoder());
|
var output = new TagHelperOutput(expectedTagName, expectedAttributes);
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent(expectedPostContent);
|
output.PostContent.SetContent(expectedPostContent);
|
||||||
|
|
|
||||||
|
|
@ -403,7 +403,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
attributes = attributes ?? new Dictionary<string, string>();
|
attributes = attributes ?? new Dictionary<string, string>();
|
||||||
|
|
||||||
return new TagHelperOutput(tagName, attributes, new HtmlEncoder());
|
return new TagHelperOutput(tagName, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IHostingEnvironment MakeHostingEnvironment()
|
private static IHostingEnvironment MakeHostingEnvironment()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using Microsoft.Framework.WebEncoders;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.TagHelpers
|
namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
|
|
@ -14,80 +13,337 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
public class OptionTagHelperTest
|
public class OptionTagHelperTest
|
||||||
{
|
{
|
||||||
// Original content, selected attribute, value attribute, selected values (to place in FormContext.FormData)
|
// Original content, selected attribute, value attribute, selected values (to place in FormContext.FormData)
|
||||||
// and expected output (concatenation of TagHelperOutput generations).
|
// and expected tag helper output.
|
||||||
public static TheoryData<string, string, string, ICollection<string>, string> GeneratesExpectedDataSet
|
public static TheoryData<string, string, string, IEnumerable<string>, TagHelperOutput> GeneratesExpectedDataSet
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new TheoryData<string, string, string, ICollection<string>, string>
|
return new TheoryData<string, string, string, IEnumerable<string>, TagHelperOutput>
|
||||||
{
|
{
|
||||||
{ null, null, null, null,
|
// original content, selected, value, selected values,
|
||||||
"<not-option label=\"my-label\"></not-option>" },
|
// expected tag helper output - attributes, content
|
||||||
{ null, string.Empty, "value", null,
|
{
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"\"></not-option>" },
|
null, null, null, null,
|
||||||
{ null, "selected", "value", null,
|
GetTagHelperOutput(
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"selected\"></not-option>" },
|
"not-option",
|
||||||
{ null, null, "value", new string[0],
|
new Dictionary<string, string>
|
||||||
"<not-option label=\"my-label\" value=\"value\"></not-option>" },
|
{
|
||||||
{ null, null, "value", new [] { string.Empty, },
|
{ "label", "my-label" }
|
||||||
"<not-option label=\"my-label\" value=\"value\"></not-option>" },
|
},
|
||||||
{ null, string.Empty, "value", new [] { string.Empty, },
|
"")
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"\"></not-option>" },
|
},
|
||||||
{ null, null, "value", new [] { "value", },
|
{
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"selected\"></not-option>" },
|
null, string.Empty, "value", null,
|
||||||
{ null, null, "value", new [] { string.Empty, "value", },
|
GetTagHelperOutput(
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"selected\"></not-option>" },
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
null, "selected", "value", null,
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
null, null, "value", Enumerable.Empty<string>(),
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
null, null, "value", new [] { string.Empty, },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
null, string.Empty, "value", new [] { string.Empty, },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
null, null, "value", new [] { "value", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
null, null, "value", new [] { string.Empty, "value", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, null, null, null,
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, string.Empty, null, null,
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, "selected", null, null,
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, null, null, Enumerable.Empty<string>(),
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, null, null, new [] { string.Empty, },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, string.Empty, null, new [] { string.Empty, },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, null, null, new [] { "text", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string.Empty, null, null, new [] { string.Empty, "text", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"")
|
||||||
|
},
|
||||||
|
|
||||||
{ string.Empty, null, null, null,
|
{
|
||||||
"<not-option label=\"my-label\"></not-option>" },
|
"text", null, null, null,
|
||||||
{ string.Empty, string.Empty, null, null,
|
GetTagHelperOutput(
|
||||||
"<not-option label=\"my-label\" selected=\"\"></not-option>" },
|
"not-option",
|
||||||
{ string.Empty, "selected", null, null,
|
new Dictionary<string, string>
|
||||||
"<not-option label=\"my-label\" selected=\"selected\"></not-option>" },
|
{
|
||||||
{ string.Empty, null, null, new string[0],
|
{ "label", "my-label" }
|
||||||
"<not-option label=\"my-label\"></not-option>" },
|
},
|
||||||
{ string.Empty, null, null, new [] { string.Empty, },
|
"text")
|
||||||
"<not-option label=\"my-label\" selected=\"selected\"></not-option>" },
|
},
|
||||||
{ string.Empty, string.Empty, null, new [] { string.Empty, },
|
{
|
||||||
"<not-option label=\"my-label\" selected=\"\"></not-option>" },
|
"text", string.Empty, null, null,
|
||||||
{ string.Empty, null, null, new [] { "text", },
|
GetTagHelperOutput(
|
||||||
"<not-option label=\"my-label\"></not-option>" },
|
"not-option",
|
||||||
{ string.Empty, null, null, new [] { string.Empty, "text", },
|
new Dictionary<string, string>
|
||||||
"<not-option label=\"my-label\" selected=\"selected\"></not-option>" },
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", "selected", null, null,
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", null, null, Enumerable.Empty<string>(),
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", null, null, new [] { string.Empty, },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", null, null, new [] { "text", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", string.Empty, null, new [] { "text", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", null, null, new [] { string.Empty, "text", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
|
||||||
{ "text", null, null, null,
|
{
|
||||||
"<not-option label=\"my-label\">text</not-option>" },
|
"text", string.Empty, "value", null,
|
||||||
{ "text", string.Empty, null, null,
|
GetTagHelperOutput(
|
||||||
"<not-option label=\"my-label\" selected=\"\">text</not-option>" },
|
"not-option",
|
||||||
{ "text", "selected", null, null,
|
new Dictionary<string, string>
|
||||||
"<not-option label=\"my-label\" selected=\"selected\">text</not-option>" },
|
{
|
||||||
{ "text", null, null, new string[0],
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "" }
|
||||||
"<not-option label=\"my-label\">text</not-option>" },
|
},
|
||||||
{ "text", null, null, new [] { string.Empty, },
|
"text")
|
||||||
"<not-option label=\"my-label\">text</not-option>" },
|
},
|
||||||
{ "text", null, null, new [] { "text", },
|
{
|
||||||
"<not-option label=\"my-label\" selected=\"selected\">text</not-option>" },
|
"text", "selected", "value", null,
|
||||||
{ "text", string.Empty, null, new [] { "text", },
|
GetTagHelperOutput(
|
||||||
"<not-option label=\"my-label\" selected=\"\">text</not-option>" },
|
"not-option",
|
||||||
{ "text", null, null, new [] { string.Empty, "text", },
|
new Dictionary<string, string>
|
||||||
"<not-option label=\"my-label\" selected=\"selected\">text</not-option>" },
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "selected" }
|
||||||
{ "text", string.Empty, "value", null,
|
},
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"\">text</not-option>" },
|
"text")
|
||||||
{ "text", "selected", "value", null,
|
},
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"selected\">text</not-option>" },
|
{
|
||||||
{ "text", null, "value", new string[0],
|
"text", null, "value", Enumerable.Empty<string>(),
|
||||||
"<not-option label=\"my-label\" value=\"value\">text</not-option>" },
|
GetTagHelperOutput(
|
||||||
{ "text", null, "value", new [] { string.Empty, },
|
"not-option",
|
||||||
"<not-option label=\"my-label\" value=\"value\">text</not-option>" },
|
new Dictionary<string, string>
|
||||||
{ "text", string.Empty, "value", new [] { string.Empty, },
|
{
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"\">text</not-option>" },
|
{ "label", "my-label" }, { "value", "value" }
|
||||||
{ "text", null, "value", new [] { "text", },
|
},
|
||||||
"<not-option label=\"my-label\" value=\"value\">text</not-option>" },
|
"text")
|
||||||
{ "text", null, "value", new [] { "value", },
|
},
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"selected\">text</not-option>" },
|
{
|
||||||
{ "text", null, "value", new [] { string.Empty, "value", },
|
"text", null, "value", new [] { string.Empty, },
|
||||||
"<not-option label=\"my-label\" value=\"value\" selected=\"selected\">text</not-option>" },
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", string.Empty, "value", new [] { string.Empty, },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", null, "value", new [] { "text", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", null, "value", new [] { "value", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text", null, "value", new [] { string.Empty, "value", },
|
||||||
|
GetTagHelperOutput(
|
||||||
|
"not-option",
|
||||||
|
new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "label", "my-label" }, { "value", "value" }, { "selected", "selected" }
|
||||||
|
},
|
||||||
|
"text")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,15 +377,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
string originalContent,
|
string originalContent,
|
||||||
string selected,
|
string selected,
|
||||||
string value,
|
string value,
|
||||||
ICollection<string> selectedValues,
|
IEnumerable<string> selectedValues,
|
||||||
string expectedOutput)
|
TagHelperOutput expectedTagHelperOutput)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "label", "my-label" },
|
{ "label", "my-label" },
|
||||||
};
|
};
|
||||||
var expectedTagName = "not-option";
|
|
||||||
|
|
||||||
var contextAttributes = new Dictionary<string, object>
|
var contextAttributes = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +402,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent(originalContent);
|
tagHelperContent.SetContent(originalContent);
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagHelperOutput.TagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -172,11 +427,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
await tagHelper.ProcessAsync(tagHelperContext, output);
|
await tagHelper.ProcessAsync(tagHelperContext, output);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(
|
Assert.Equal(expectedTagHelperOutput.TagName, output.TagName);
|
||||||
expectedOutput,
|
Assert.Equal(expectedTagHelperOutput.Content.GetContent(), output.Content.GetContent());
|
||||||
output.GenerateStartTag() +
|
Assert.Equal(expectedTagHelperOutput.Attributes.Count, output.Attributes.Count);
|
||||||
(output.GenerateContent() as TagHelperContent).GetContent() +
|
foreach (var attribute in output.Attributes)
|
||||||
output.GenerateEndTag());
|
{
|
||||||
|
Assert.Contains(attribute, expectedTagHelperOutput.Attributes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -185,8 +442,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
string originalContent,
|
string originalContent,
|
||||||
string selected,
|
string selected,
|
||||||
string value,
|
string value,
|
||||||
ICollection<string> selectedValues,
|
IEnumerable<string> selectedValues,
|
||||||
string ignored)
|
TagHelperOutput ignored)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
|
|
@ -213,7 +470,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent(originalContent);
|
tagHelperContent.SetContent(originalContent);
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(originalTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(originalTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -246,8 +503,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
string originalContent,
|
string originalContent,
|
||||||
string selected,
|
string selected,
|
||||||
string value,
|
string value,
|
||||||
ICollection<string> ignoredValues,
|
IEnumerable<string> ignoredValues,
|
||||||
string ignoredOutput)
|
TagHelperOutput ignoredOutput)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var originalAttributes = new Dictionary<string, string>
|
var originalAttributes = new Dictionary<string, string>
|
||||||
|
|
@ -274,7 +531,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent(originalContent);
|
tagHelperContent.SetContent(originalContent);
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(originalTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(originalTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = false,
|
SelfClosing = false,
|
||||||
};
|
};
|
||||||
|
|
@ -292,5 +549,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
// Tag helper would throw an NRE if it used ViewContext or Generator values.
|
// Tag helper would throw an NRE if it used ViewContext or Generator values.
|
||||||
await tagHelper.ProcessAsync(tagHelperContext, output);
|
await tagHelper.ProcessAsync(tagHelperContext, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static TagHelperOutput GetTagHelperOutput(
|
||||||
|
string tagName, IDictionary<string, string> attributes, string content)
|
||||||
|
{
|
||||||
|
var tagHelperOutput = new TagHelperOutput(tagName, attributes);
|
||||||
|
tagHelperOutput.Content.SetContent(content);
|
||||||
|
|
||||||
|
return tagHelperOutput;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,7 +476,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
attributes = attributes ?? new Dictionary<string, string>();
|
attributes = attributes ?? new Dictionary<string, string>();
|
||||||
|
|
||||||
return new TagHelperOutput(tagName, attributes, new HtmlEncoder());
|
return new TagHelperOutput(tagName, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TagHelperLogger<ScriptTagHelper> CreateLogger()
|
private TagHelperLogger<ScriptTagHelper> CreateLogger()
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
@ -298,7 +298,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
@ -402,7 +402,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = true
|
SelfClosing = true
|
||||||
};
|
};
|
||||||
|
|
@ -492,7 +492,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder());
|
var output = new TagHelperOutput(expectedTagName, originalAttributes);
|
||||||
var metadataProvider = new EmptyModelMetadataProvider();
|
var metadataProvider = new EmptyModelMetadataProvider();
|
||||||
string model = null;
|
string model = null;
|
||||||
var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(string), model);
|
var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(string), model);
|
||||||
|
|
@ -562,7 +562,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(tagName, originalAttributes, new HtmlEncoder());
|
var output = new TagHelperOutput(tagName, originalAttributes);
|
||||||
var metadataProvider = new EmptyModelMetadataProvider();
|
var metadataProvider = new EmptyModelMetadataProvider();
|
||||||
var modelExplorer = metadataProvider.GetModelExplorerForType(modelType, model);
|
var modelExplorer = metadataProvider.GetModelExplorerForType(modelType, model);
|
||||||
var modelExpression = new ModelExpression(propertyName, modelExplorer);
|
var modelExpression = new ModelExpression(propertyName, modelExplorer);
|
||||||
|
|
@ -622,7 +622,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, originalAttributes, new HtmlEncoder());
|
var output = new TagHelperOutput(expectedTagName, originalAttributes);
|
||||||
var tagHelper = new SelectTagHelper
|
var tagHelper = new SelectTagHelper
|
||||||
{
|
{
|
||||||
Items = Enumerable.Empty<SelectListItem>(),
|
Items = Enumerable.Empty<SelectListItem>(),
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
var tagHelperContext = new TagHelperContext(
|
var tagHelperContext = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
|
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
|
||||||
{
|
{
|
||||||
|
|
@ -56,8 +55,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>()
|
attributes: new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ attributeName, "world2" }
|
{ attributeName, "world2" }
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
var expectedAttribute = new KeyValuePair<string, string>(attributeName, "world2");
|
var expectedAttribute = new KeyValuePair<string, string>(attributeName, "world2");
|
||||||
var tagHelperContext = new TagHelperContext(
|
var tagHelperContext = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
|
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
|
||||||
|
|
@ -91,8 +89,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "route-Hello", "World" },
|
{ "route-Hello", "World" },
|
||||||
{ "Route-I", "Am" }
|
{ "Route-I", "Am" }
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
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-");
|
||||||
|
|
@ -115,8 +112,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "routeHello", "World" },
|
{ "routeHello", "World" },
|
||||||
{ "Routee-I", "Am" }
|
{ "Routee-I", "Am" }
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
|
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
|
||||||
|
|
@ -135,8 +131,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("type", "btn");
|
var expectedAttribute = new KeyValuePair<string, string>("type", "btn");
|
||||||
tagHelperOutput.Attributes.Add(expectedAttribute);
|
tagHelperOutput.Attributes.Add(expectedAttribute);
|
||||||
|
|
||||||
|
|
@ -157,8 +152,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
tagHelperOutput.Attributes.Add("class", "Hello");
|
tagHelperOutput.Attributes.Add("class", "Hello");
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
||||||
|
|
@ -184,8 +178,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
tagHelperOutput.Attributes.Add(originalName, "Hello");
|
tagHelperOutput.Attributes.Add(originalName, "Hello");
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
||||||
|
|
@ -205,8 +198,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("visible", "val < 3");
|
var expectedAttribute = new KeyValuePair<string, string>("visible", "val < 3");
|
||||||
|
|
@ -226,8 +218,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
|
|
||||||
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
var tagBuilder = new TagBuilder("p", new HtmlEncoder());
|
||||||
var expectedAttribute1 = new KeyValuePair<string, string>("class", "btn");
|
var expectedAttribute1 = new KeyValuePair<string, string>("class", "btn");
|
||||||
|
|
@ -252,8 +243,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
var expectedAttribute = new KeyValuePair<string, string>("class", "btn");
|
var expectedAttribute = new KeyValuePair<string, string>("class", "btn");
|
||||||
tagHelperOutput.Attributes.Add(expectedAttribute);
|
tagHelperOutput.Attributes.Add(expectedAttribute);
|
||||||
|
|
||||||
|
|
@ -273,8 +263,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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
var expectedOutputAttribute = new KeyValuePair<string, string>("class", "btn");
|
var expectedOutputAttribute = new KeyValuePair<string, string>("class", "btn");
|
||||||
tagHelperOutput.Attributes.Add(expectedOutputAttribute);
|
tagHelperOutput.Attributes.Add(expectedOutputAttribute);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
{
|
{
|
||||||
{ "class", "form-control" },
|
{ "class", "form-control" },
|
||||||
};
|
};
|
||||||
var output = new TagHelperOutput(expectedTagName, htmlAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, htmlAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
@ -185,7 +185,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
tagHelperContent.SetContent("Something");
|
tagHelperContent.SetContent("Something");
|
||||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||||
});
|
});
|
||||||
var output = new TagHelperOutput(expectedTagName, expectedAttributes, new HtmlEncoder())
|
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
|
||||||
{
|
{
|
||||||
SelfClosing = true,
|
SelfClosing = true,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "id", "myvalidationmessage" }
|
{ "id", "myvalidationmessage" }
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent(expectedPostContent);
|
output.PostContent.SetContent(expectedPostContent);
|
||||||
|
|
@ -106,8 +105,7 @@ 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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent(expectedPostContent);
|
output.PostContent.SetContent(expectedPostContent);
|
||||||
|
|
@ -147,8 +145,7 @@ 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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.Content.SetContent(outputContent);
|
output.Content.SetContent(outputContent);
|
||||||
|
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
|
|
@ -207,8 +204,7 @@ 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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
|
|
||||||
var context = new TagHelperContext(
|
var context = new TagHelperContext(
|
||||||
allAttributes: new Dictionary<string, object>(),
|
allAttributes: new Dictionary<string, object>(),
|
||||||
|
|
@ -263,8 +259,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var expectedPostContent = "original post-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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent(expectedPostContent);
|
output.PostContent.SetContent(expectedPostContent);
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
attributes: new Dictionary<string, string>
|
attributes: new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "class", "form-control" }
|
{ "class", "form-control" }
|
||||||
},
|
});
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent("Custom Content");
|
output.PostContent.SetContent("Custom Content");
|
||||||
|
|
@ -103,8 +102,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var expectedPostContent = "original post-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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent(expectedPostContent);
|
output.PostContent.SetContent(expectedPostContent);
|
||||||
|
|
@ -146,8 +144,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var expectedContent = "original 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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent("Content of validation summary");
|
output.PostContent.SetContent("Content of validation summary");
|
||||||
|
|
@ -204,8 +201,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var expectedPostContent = "original post-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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent(expectedPostContent);
|
output.PostContent.SetContent(expectedPostContent);
|
||||||
|
|
@ -240,8 +236,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
var expectedContent = "original 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>());
|
||||||
htmlEncoder: new HtmlEncoder());
|
|
||||||
output.PreContent.SetContent(expectedPreContent);
|
output.PreContent.SetContent(expectedPreContent);
|
||||||
output.Content.SetContent(expectedContent);
|
output.Content.SetContent(expectedContent);
|
||||||
output.PostContent.SetContent("Content of validation message");
|
output.PostContent.SetContent("Content of validation message");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue