Fix attribute routing error message related to replace tokens

This commit is contained in:
Kiran Challa 2017-01-03 15:45:13 -08:00 committed by Kiran Challa
parent 5070526f43
commit de0f277892
5 changed files with 44 additions and 56 deletions

View File

@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Mvc.Core
}
/// <summary>
/// While processing template '{0}', a replacement value for the token '{1}' could not be found. Available tokens: '{2}'.
/// While processing template '{0}', a replacement value for the token '{1}' could not be found. Available tokens: '{2}'. To use a '[' or ']' as a literal string in a route or within a constraint, use '[[' or ']]' instead.
/// </summary>
internal static string AttributeRoute_TokenReplacement_ReplacementValueNotFound
{
@ -435,7 +435,7 @@ namespace Microsoft.AspNetCore.Mvc.Core
}
/// <summary>
/// While processing template '{0}', a replacement value for the token '{1}' could not be found. Available tokens: '{2}'.
/// While processing template '{0}', a replacement value for the token '{1}' could not be found. Available tokens: '{2}'. To use a '[' or ']' as a literal string in a route or within a constraint, use '[[' or ']]' instead.
/// </summary>
internal static string FormatAttributeRoute_TokenReplacement_ReplacementValueNotFound(object p0, object p1, object p2)
{

View File

@ -199,7 +199,7 @@
<comment>{1} is the specific error message.</comment>
</data>
<data name="AttributeRoute_TokenReplacement_ReplacementValueNotFound" xml:space="preserve">
<value>While processing template '{0}', a replacement value for the token '{1}' could not be found. Available tokens: '{2}'.</value>
<value>While processing template '{0}', a replacement value for the token '{1}' could not be found. Available tokens: '{2}'. To use a '[' or ']' as a literal string in a route or within a constraint, use '[[' or ']]' instead.</value>
</data>
<data name="AttributeRoute_TokenReplacement_UnclosedToken" xml:space="preserve">
<value>A replacement token is not closed.</value>

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
}
/// <summary>
/// The @page directive for the Razor page at {0} cannot override the relative path prefix.
/// The route for the page at '{0}' cannot start with / or ~/. Pages do not support overriding the file path of the page.
/// </summary>
internal static string FormatPageActionDescriptorProvider_RouteTemplateCannotBeOverrideable(object p0)
{
@ -74,22 +74,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
return string.Format(CultureInfo.CurrentCulture, GetString("ActivatedInstance_MustBeAnInstanceOf"), p0, p1);
}
/// <summary>
/// The Razor page type '{0}' does not have a parameterless constructor.
/// </summary>
internal static string PageActivator_TypeDoesNotHaveParameterlessConstructor
{
get { return GetString("PageActivator_TypeDoesNotHaveParameterlessConstructor"); }
}
/// <summary>
/// The Razor page type '{0}' does not have a parameterless constructor.
/// </summary>
internal static string FormatPageActivator_TypeDoesNotHaveParameterlessConstructor(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("PageActivator_TypeDoesNotHaveParameterlessConstructor"), p0);
}
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);

View File

@ -174,11 +174,12 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
Assert.Equal(expected, ex.Message);
}
[Fact]
public void ReplaceTokens_UnknownValue()
[Theory]
[InlineData("[area]/[controller]/[action]/{deptName:regex(^[a-zA-Z]{1}[a-zA-Z0-9_]*$)}", "a-zA-Z")]
[InlineData("[area]/[controller]/[action2]", "action2")]
public void ReplaceTokens_UnknownValue(string template, string token)
{
// Arrange
var template = "[area]/[controller]/[action2]";
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "area", "Help" },
@ -187,9 +188,10 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
};
var expected =
"While processing template '[area]/[controller]/[action2]', " +
"a replacement value for the token 'action2' could not be found. " +
"Available tokens: 'action, area, controller'.";
$"While processing template '{template}', " +
$"a replacement value for the token '{token}' could not be found. " +
"Available tokens: 'action, area, controller'. To use a '[' or ']' as a literal string in a " +
"route or within a constraint, use '[[' or ']]' instead.";
// Act
var ex = Assert.Throws<InvalidOperationException>(

View File

@ -444,7 +444,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
"Error 1:" + Environment.NewLine +
$"For action: '{controllerTypeInfo.FullName}.Unknown ({assemblyName})'" + Environment.NewLine +
"Error: While processing template 'stub/[action]/[unknown]', a replacement value for the token 'unknown' " +
"could not be found. Available tokens: 'action, controller'." + Environment.NewLine +
"could not be found. Available tokens: 'action, controller'. To use a '[' or ']' as a literal string in" +
" a route or within a constraint, use '[[' or ']]' instead." + Environment.NewLine +
Environment.NewLine +
"Error 2:" + Environment.NewLine +
$"For action: '{controllerTypeInfo.FullName}.Invalid ({assemblyName})'" + Environment.NewLine +
@ -906,7 +907,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
"Error 1:" + Environment.NewLine +
$"For action: '{controllerTypeInfo.FullName}.Get ({assemblyName})'" + Environment.NewLine +
"Error: While processing template 'Products_[unknown]', a replacement value for the token 'unknown' " +
"could not be found. Available tokens: 'action, controller'.";
"could not be found. Available tokens: 'action, controller'. To use a '[' or ']' as a literal string" +
" in a route or within a constraint, use '[[' or ']]' instead.";
// Act & Assert
var ex = Assert.Throws<InvalidOperationException>(() => { provider.GetDescriptors(); });