Fixing tests

This commit is contained in:
Pranav K 2015-10-30 18:47:20 -07:00
parent 52f4a83139
commit a9d5876cd9
7 changed files with 38 additions and 27 deletions

View File

@ -206,7 +206,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
writer.Write(" "); writer.Write(" ");
writer.Write(key); writer.Write(key);
writer.Write("=\""); writer.Write("=\"");
encoder.Encode(writer, attribute.Value); if (!string.IsNullOrEmpty(attribute.Value))
{
encoder.Encode(writer, attribute.Value);
}
writer.Write("\""); writer.Write("\"");
} }
} }

View File

@ -39,7 +39,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
throw new ArgumentNullException(nameof(encoder)); throw new ArgumentNullException(nameof(encoder));
} }
encoder.Encode(writer, _input); if (!string.IsNullOrEmpty(_input))
{
encoder.Encode(writer, _input);
}
} }
private string DebuggerToString() private string DebuggerToString()

View File

@ -1,4 +1,4 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
@ -62,10 +62,10 @@
</script> </script>
<!-- Globbed script tag with existing file --> <!-- Globbed script tag with existing file -->
<script src="HtmlEncode[[/styles/site.js]]"></script> HtmlEncode[[]]<script src="HtmlEncode[[/styles/site.js]]"></script>
<!-- Globbed script tag with existing file and exclude --> <!-- Globbed script tag with existing file and exclude -->
<script src="HtmlEncode[[/styles/site.js]]"></script><script src="HtmlEncode[[/styles/sub/site2.js]]"></script> HtmlEncode[[]]<script src="HtmlEncode[[/styles/site.js]]"></script><script src="HtmlEncode[[/styles/sub/site2.js]]"></script>
<script> <script>
// Globbed script tag missing include // Globbed script tag missing include
@ -76,16 +76,16 @@
</script> </script>
<!-- Globbed script tag with comma separated include pattern --> <!-- Globbed script tag with comma separated include pattern -->
<script src="HtmlEncode[[/styles/site.js]]"></script><script src="HtmlEncode[[/styles/sub/site2.js]]"></script><script src="HtmlEncode[[/styles/sub/site3.js]]"></script> HtmlEncode[[]]<script src="HtmlEncode[[/styles/site.js]]"></script><script src="HtmlEncode[[/styles/sub/site2.js]]"></script><script src="HtmlEncode[[/styles/sub/site3.js]]"></script>
<!-- Globbed script tag with missing file --> <!-- Globbed script tag with missing file -->
HtmlEncode[[]]
<!-- Globbed script tag with file outside of webroot --> <!-- Globbed script tag with file outside of webroot -->
HtmlEncode[[]]
<!-- Globbed script tag with file outside of webroot --> <!-- Globbed script tag with file outside of webroot -->
HtmlEncode[[]]
<script src="HtmlEncode[[/styles/site.js]]"> <script src="HtmlEncode[[/styles/site.js]]">
// Globbed script tag with existing file and static src // Globbed script tag with existing file and static src
@ -110,9 +110,9 @@
</script> </script>
<!-- Globbed script tag with existing files and version --> <!-- Globbed script tag with existing files and version -->
<script src="HtmlEncode[[/styles/site.js?v=jx1PJjLX32-xgQQx2BxnckU9QH9DVKkm4-M5bSK869I]]"></script><script src="HtmlEncode[[/styles/sub/site2.js?v=pwJaxaQxnb-rPAdF2JlAp4xiPNq1XuJFd6TyOOfNF-0]]"></script><script src="HtmlEncode[[/styles/sub/site3.js?v=lmeAMiqm76lnGyqHhu6PIBHAC0Vt46mgVB_KaG_gGdA]]"></script> HtmlEncode[[]]<script src="HtmlEncode[[/styles/site.js?v=jx1PJjLX32-xgQQx2BxnckU9QH9DVKkm4-M5bSK869I]]"></script><script src="HtmlEncode[[/styles/sub/site2.js?v=pwJaxaQxnb-rPAdF2JlAp4xiPNq1XuJFd6TyOOfNF-0]]"></script><script src="HtmlEncode[[/styles/sub/site3.js?v=lmeAMiqm76lnGyqHhu6PIBHAC0Vt46mgVB_KaG_gGdA]]"></script>
<!-- Globbed script tag with existing file, exclude and version --> <!-- Globbed script tag with existing file, exclude and version -->
<script src="HtmlEncode[[/styles/site.js?v=jx1PJjLX32-xgQQx2BxnckU9QH9DVKkm4-M5bSK869I]]"></script><script src="HtmlEncode[[/styles/sub/site2.js?v=pwJaxaQxnb-rPAdF2JlAp4xiPNq1XuJFd6TyOOfNF-0]]"></script> HtmlEncode[[]]<script src="HtmlEncode[[/styles/site.js?v=jx1PJjLX32-xgQQx2BxnckU9QH9DVKkm4-M5bSK869I]]"></script><script src="HtmlEncode[[/styles/sub/site2.js?v=pwJaxaQxnb-rPAdF2JlAp4xiPNq1XuJFd6TyOOfNF-0]]"></script>
</body> </body>
</html> </html>

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.Encodings.Web;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
@ -16,7 +17,6 @@ using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Extensions.WebEncoders.Testing;
using Moq; using Moq;
using Xunit; using Xunit;
@ -60,13 +60,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
.Setup(mock => mock.Action(It.IsAny<UrlActionContext>())).Returns("home/index"); .Setup(mock => mock.Action(It.IsAny<UrlActionContext>())).Returns("home/index");
var htmlGenerator = new TestableHtmlGenerator(metadataProvider, urlHelper.Object); var htmlGenerator = new TestableHtmlGenerator(metadataProvider, urlHelper.Object);
var viewContext = TestableHtmlGenerator.GetViewContext(model: null, var viewContext = TestableHtmlGenerator.GetViewContext(
htmlGenerator: htmlGenerator, model: null,
metadataProvider: metadataProvider); htmlGenerator: htmlGenerator,
metadataProvider: metadataProvider);
var expectedPostContent = "Something" + var expectedPostContent = "Something" +
HtmlContentUtilities.HtmlContentToString( HtmlContentUtilities.HtmlContentToString(
htmlGenerator.GenerateAntiforgery(viewContext), htmlGenerator.GenerateAntiforgery(viewContext),
new HtmlTestEncoder()); HtmlEncoder.Default);
var formTagHelper = new FormTagHelper(htmlGenerator) var formTagHelper = new FormTagHelper(htmlGenerator)
{ {
Action = "index", Action = "index",

View File

@ -45,15 +45,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
modelWithNull, modelWithNull,
modelWithText, modelWithText,
}; };
var noneSelected = "<option></option>" + Environment.NewLine + var noneSelected = "<option>HtmlEncode[[]]</option>" + Environment.NewLine +
"<option>HtmlEncode[[outer text]]</option>" + Environment.NewLine + "<option>HtmlEncode[[outer text]]</option>" + Environment.NewLine +
"<option>HtmlEncode[[inner text]]</option>" + Environment.NewLine + "<option>HtmlEncode[[inner text]]</option>" + Environment.NewLine +
"<option>HtmlEncode[[other text]]</option>" + Environment.NewLine; "<option>HtmlEncode[[other text]]</option>" + Environment.NewLine;
var innerSelected = "<option></option>" + Environment.NewLine + var innerSelected = "<option>HtmlEncode[[]]</option>" + Environment.NewLine +
"<option>HtmlEncode[[outer text]]</option>" + Environment.NewLine + "<option>HtmlEncode[[outer text]]</option>" + Environment.NewLine +
"<option selected=\"HtmlEncode[[selected]]\">HtmlEncode[[inner text]]</option>" + Environment.NewLine + "<option selected=\"HtmlEncode[[selected]]\">HtmlEncode[[inner text]]</option>" + Environment.NewLine +
"<option>HtmlEncode[[other text]]</option>" + Environment.NewLine; "<option>HtmlEncode[[other text]]</option>" + Environment.NewLine;
var outerSelected = "<option></option>" + Environment.NewLine + var outerSelected = "<option>HtmlEncode[[]]</option>" + Environment.NewLine +
"<option selected=\"HtmlEncode[[selected]]\">HtmlEncode[[outer text]]</option>" + Environment.NewLine + "<option selected=\"HtmlEncode[[selected]]\">HtmlEncode[[outer text]]</option>" + Environment.NewLine +
"<option>HtmlEncode[[inner text]]</option>" + Environment.NewLine + "<option>HtmlEncode[[inner text]]</option>" + Environment.NewLine +
"<option>HtmlEncode[[other text]]</option>" + Environment.NewLine; "<option>HtmlEncode[[other text]]</option>" + Environment.NewLine;

View File

@ -48,32 +48,35 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
{ null, typeof(Model), null, { null, typeof(Model), null,
new NameAndId("Text", "Text"), new NameAndId("Text", "Text"),
Environment.NewLine }, Environment.NewLine + "HtmlEncode[[]]" },
{ modelWithNull, typeof(Model), modelWithNull.Text, { modelWithNull, typeof(Model), modelWithNull.Text,
new NameAndId("Text", "Text"), new NameAndId("Text", "Text"),
Environment.NewLine }, Environment.NewLine + "HtmlEncode[[]]"},
{ modelWithText, typeof(Model), modelWithText.Text, { modelWithText, typeof(Model), modelWithText.Text,
new NameAndId("Text", "Text"), new NameAndId("Text", "Text"),
Environment.NewLine + "HtmlEncode[[outer text]]" }, Environment.NewLine + "HtmlEncode[[outer text]]" },
{ modelWithNull, typeof(NestedModel), modelWithNull.NestedModel.Text, { modelWithNull, typeof(NestedModel), modelWithNull.NestedModel.Text,
new NameAndId("NestedModel.Text", "NestedModel_Text"), new NameAndId("NestedModel.Text", "NestedModel_Text"),
Environment.NewLine }, Environment.NewLine + "HtmlEncode[[]]" },
{ modelWithText, typeof(NestedModel), modelWithText.NestedModel.Text, { modelWithText, typeof(NestedModel), modelWithText.NestedModel.Text,
new NameAndId("NestedModel.Text", "NestedModel_Text"), new NameAndId("NestedModel.Text", "NestedModel_Text"),
Environment.NewLine + "HtmlEncode[[inner text]]" }, Environment.NewLine + "HtmlEncode[[inner text]]" },
{ models, typeof(Model), models[0].Text, { models, typeof(Model), models[0].Text,
new NameAndId("[0].Text", "z0__Text"), new NameAndId("[0].Text", "z0__Text"),
Environment.NewLine }, Environment.NewLine + "HtmlEncode[[]]" },
{ models, typeof(Model), models[1].Text, { models, typeof(Model), models[1].Text,
new NameAndId("[1].Text", "z1__Text"), new NameAndId("[1].Text", "z1__Text"),
Environment.NewLine + "HtmlEncode[[outer text]]" }, Environment.NewLine + "HtmlEncode[[outer text]]" },
{ models, typeof(NestedModel), models[0].NestedModel.Text, { models, typeof(NestedModel), models[0].NestedModel.Text,
new NameAndId("[0].NestedModel.Text", "z0__NestedModel_Text"), new NameAndId("[0].NestedModel.Text", "z0__NestedModel_Text"),
Environment.NewLine }, Environment.NewLine + "HtmlEncode[[]]" },
{ models, typeof(NestedModel), models[1].NestedModel.Text, { models, typeof(NestedModel), models[1].NestedModel.Text,
new NameAndId("[1].NestedModel.Text", "z1__NestedModel_Text"), new NameAndId("[1].NestedModel.Text", "z1__NestedModel_Text"),
Environment.NewLine + "HtmlEncode[[inner text]]" }, Environment.NewLine + "HtmlEncode[[inner text]]" },

View File

@ -63,9 +63,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
output.Content.SetContent(expectedContent); output.Content.SetContent(expectedContent);
output.PostContent.SetContent(expectedPostContent); output.PostContent.SetContent(expectedPostContent);
var viewContext = TestableHtmlGenerator.GetViewContext(model: null, var viewContext = TestableHtmlGenerator.GetViewContext(
htmlGenerator: htmlGenerator, model: null,
metadataProvider: metadataProvider); htmlGenerator: htmlGenerator,
metadataProvider: metadataProvider);
validationMessageTagHelper.ViewContext = viewContext; validationMessageTagHelper.ViewContext = viewContext;
// Act // Act