- Updated tests to create TagHelperContext correctly.
This commit is contained in:
N. Taylor Mullen 2015-02-22 20:29:25 -08:00
parent df4b92b1c1
commit 1cc9be5df7
15 changed files with 112 additions and 48 deletions

View File

@ -32,6 +32,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ "asp-host", "contoso.com" },
{ "asp-protocol", "http" }
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something Else"));
var output = new TagHelperOutput(
@ -82,6 +83,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Arrange
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(
@ -120,14 +122,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Arrange
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(
"a",
attributes: new Dictionary<string, string>())
{
Content = string.Empty
};
{
Content = string.Empty
};
var generator = new Mock<IHtmlGenerator>();
generator

View File

@ -702,18 +702,20 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedContent = "some-content";
var tokenSource = new CancellationTokenSource();
var cache = new MemoryCache(new MemoryCacheOptions());
var tagHelperContext = new TagHelperContext(new Dictionary<string, object>(),
id,
() =>
{
var entryLink = EntryLinkHelpers.ContextLink;
Assert.NotNull(entryLink);
entryLink.AddExpirationTriggers(new[]
{
new CancellationTokenTrigger(tokenSource.Token)
});
return Task.FromResult(expectedContent);
});
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: id,
getChildContentAsync: () =>
{
var entryLink = EntryLinkHelpers.ContextLink;
Assert.NotNull(entryLink);
entryLink.AddExpirationTriggers(new[]
{
new CancellationTokenTrigger(tokenSource.Token)
});
return Task.FromResult(expectedContent);
});
var tagHelperOutput = new TagHelperOutput("cache", new Dictionary<string, string>())
{
PreContent = "<cache>",
@ -757,9 +759,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
private static TagHelperContext GetTagHelperContext(string id = "testid",
string childContent = "some child content")
{
return new TagHelperContext(new Dictionary<string, object>(),
id,
() => Task.FromResult(childContent));
return new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: id,
getChildContentAsync: () => Task.FromResult(childContent));
}
private static string GetHashedBytes(string input)

View File

@ -134,13 +134,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Test
{
attributes = attributes ?? new Dictionary<string, object>();
return new TagHelperContext(attributes, Guid.NewGuid().ToString("N"), () => Task.FromResult(content));
return new TagHelperContext(
attributes,
items: new Dictionary<object, object>(),
uniqueId: Guid.NewGuid().ToString("N"),
getChildContentAsync: () => Task.FromResult(content));
}
private TagHelperOutput MakeTagHelperOutput(string tagName, IDictionary<string, string> attributes = null)
{
attributes = attributes ?? new Dictionary<string, string>();
return new TagHelperOutput(tagName, attributes);
}
}

View File

@ -33,6 +33,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ "method", "post" },
{ "asp-anti-forgery", true }
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something Else"));
var output = new TagHelperOutput(
@ -92,6 +93,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var viewContext = CreateViewContext();
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(
@ -137,6 +139,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var testViewContext = CreateViewContext();
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var expectedAttribute = new KeyValuePair<string, string>("asp-ROUTEE-NotRoute", "something");
@ -202,6 +205,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var viewContext = CreateViewContext();
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(
@ -256,6 +260,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
{ "METhod", "POST" }
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
@ -302,6 +307,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
});
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));

View File

@ -94,9 +94,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedPostContent = "original post-content";
var expectedTagName = "not-input";
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var originalAttributes = new Dictionary<string, string>
{
{ "class", "form-control" },
@ -148,9 +150,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedContent = originalContent + "<input class=\"form-control\" /><hidden />";
var expectedPostContent = "original post-content";
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var originalAttributes = new Dictionary<string, string>
{
{ "class", "form-control" },
@ -237,9 +241,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedPostContent = "original post-content";
var expectedTagName = "not-input";
var context = new TagHelperContext(allAttributes: contextAttributes,
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var context = new TagHelperContext(
allAttributes: contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var originalAttributes = new Dictionary<string, string>
{
{ "class", "form-control" },
@ -323,9 +329,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedPostContent = "original post-content";
var expectedTagName = "not-input";
var context = new TagHelperContext(allAttributes: contextAttributes,
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var context = new TagHelperContext(
allAttributes: contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var originalAttributes = new Dictionary<string, string>
{
{ "class", "form-control" },
@ -406,9 +414,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedPostContent = "original post-content";
var expectedTagName = "not-input";
var context = new TagHelperContext(allAttributes: contextAttributes,
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var context = new TagHelperContext(
allAttributes: contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var originalAttributes = new Dictionary<string, string>
{
{ "class", "form-control" },
@ -504,9 +514,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedPostContent = "original post-content";
var expectedTagName = "not-input";
var context = new TagHelperContext(allAttributes: contextAttributes,
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var context = new TagHelperContext(
allAttributes: contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var originalAttributes = new Dictionary<string, string>
{
{ "class", "form-control" },
@ -573,6 +585,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
@ -628,6 +641,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, originalAttributes);

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
public void DetermineMode_FindsFullModeMatchWithSingleAttribute()
{
// Arrange
var modeInfo = new []
var modeInfo = new[]
{
ModeAttributes.Create("mode0", new [] { "first-attr" })
};
@ -124,7 +124,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
{
attributes = attributes ?? new Dictionary<string, object>();
return new TagHelperContext(attributes, Guid.NewGuid().ToString("N"), () => Task.FromResult(content));
return new TagHelperContext(
attributes,
items: new Dictionary<object, object>(),
uniqueId: Guid.NewGuid().ToString("N"),
getChildContentAsync: () => Task.FromResult(content));
}
}
}

View File

@ -183,6 +183,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(tagHelperOutputContent.OriginalChildContent));
var htmlAttributes = new Dictionary<string, string>
@ -242,6 +243,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, expectedAttributes)

View File

@ -337,7 +337,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
attributes = attributes ?? new Dictionary<string, object>();
return new TagHelperContext(attributes, Guid.NewGuid().ToString("N"), () => Task.FromResult(content));
return new TagHelperContext(
attributes,
items: new Dictionary<object, object>(),
uniqueId: Guid.NewGuid().ToString("N"),
getChildContentAsync: () => Task.FromResult(content));
}
private static TagHelperOutput MakeTagHelperOutput(string tagName, IDictionary<string, string> attributes = null)

View File

@ -138,6 +138,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
};
var tagHelperContext = new TagHelperContext(
contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(originalContent));
var output = new TagHelperOutput(expectedTagName, originalAttributes)
@ -196,6 +197,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var originalPostContent = "original post-content";
var tagHelperContext = new TagHelperContext(
contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(originalContent));
var output = new TagHelperOutput(originalTagName, originalAttributes)
@ -251,6 +253,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var originalPostContent = "original post-content";
var tagHelperContext = new TagHelperContext(
contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(originalContent));
var output = new TagHelperOutput(originalTagName, originalAttributes)

View File

@ -244,7 +244,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
attributes = attributes ?? new Dictionary<string, object>();
return new TagHelperContext(attributes, Guid.NewGuid().ToString("N"), () => Task.FromResult(content));
return new TagHelperContext(
attributes,
items: new Dictionary<object, object>(),
uniqueId: Guid.NewGuid().ToString("N"),
getChildContentAsync: () => Task.FromResult(content));
}
private TagHelperOutput MakeTagHelperOutput(string tagName, IDictionary<string, string> attributes = null)

View File

@ -196,6 +196,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, originalAttributes)
@ -276,6 +277,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, originalAttributes)
@ -358,6 +360,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, originalAttributes);
@ -423,6 +426,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(tagName, originalAttributes);
@ -478,6 +482,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
contextAttributes,
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, originalAttributes);

View File

@ -26,6 +26,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
{ attributeName, attributeValue }
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var expectedAttribute = new KeyValuePair<string, string>(attributeName, attributeValue);
@ -55,6 +56,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
{ attributeName, "world" }
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));

View File

@ -109,6 +109,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var htmlAttributes = new Dictionary<string, string>
@ -165,6 +166,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(expectedTagName, expectedAttributes)

View File

@ -38,6 +38,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ "id", "myvalidationmessage" },
{ "for", modelExpression },
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(
@ -90,6 +91,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedPostContent = "original post-content";
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(
@ -140,9 +142,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Content = outputContent
};
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(childContent));
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(childContent));
var tagBuilder = new TagBuilder("span2")
{
InnerHtml = "New HTML"
@ -191,9 +195,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
"span",
attributes: new Dictionary<string, string>());
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(childContent));
var context = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult(childContent));
var tagBuilder = new TagBuilder("span2")
{
InnerHtml = "New HTML"

View File

@ -44,6 +44,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedContent = "original content";
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(),
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () => Task.FromResult("Something"));
var output = new TagHelperOutput(