Fix attribute routing error message related to replace tokens
This commit is contained in:
parent
5070526f43
commit
de0f277892
|
|
@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Mvc.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
internal static string AttributeRoute_TokenReplacement_ReplacementValueNotFound
|
internal static string AttributeRoute_TokenReplacement_ReplacementValueNotFound
|
||||||
{
|
{
|
||||||
|
|
@ -435,7 +435,7 @@ namespace Microsoft.AspNetCore.Mvc.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
internal static string FormatAttributeRoute_TokenReplacement_ReplacementValueNotFound(object p0, object p1, object p2)
|
internal static string FormatAttributeRoute_TokenReplacement_ReplacementValueNotFound(object p0, object p1, object p2)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@
|
||||||
<comment>{1} is the specific error message.</comment>
|
<comment>{1} is the specific error message.</comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="AttributeRoute_TokenReplacement_ReplacementValueNotFound" xml:space="preserve">
|
<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>
|
||||||
<data name="AttributeRoute_TokenReplacement_UnclosedToken" xml:space="preserve">
|
<data name="AttributeRoute_TokenReplacement_UnclosedToken" xml:space="preserve">
|
||||||
<value>A replacement token is not closed.</value>
|
<value>A replacement token is not closed.</value>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
internal static string FormatPageActionDescriptorProvider_RouteTemplateCannotBeOverrideable(object p0)
|
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);
|
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)
|
private static string GetString(string name, params string[] formatterNames)
|
||||||
{
|
{
|
||||||
var value = _resourceManager.GetString(name);
|
var value = _resourceManager.GetString(name);
|
||||||
|
|
|
||||||
|
|
@ -174,11 +174,12 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
Assert.Equal(expected, ex.Message);
|
Assert.Equal(expected, ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void ReplaceTokens_UnknownValue()
|
[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
|
// Arrange
|
||||||
var template = "[area]/[controller]/[action2]";
|
|
||||||
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
{
|
{
|
||||||
{ "area", "Help" },
|
{ "area", "Help" },
|
||||||
|
|
@ -187,9 +188,10 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
|
||||||
};
|
};
|
||||||
|
|
||||||
var expected =
|
var expected =
|
||||||
"While processing template '[area]/[controller]/[action2]', " +
|
$"While processing template '{template}', " +
|
||||||
"a replacement value for the token 'action2' could not be found. " +
|
$"a replacement value for the token '{token}' could not be found. " +
|
||||||
"Available tokens: 'action, area, controller'.";
|
"Available tokens: 'action, area, controller'. To use a '[' or ']' as a literal string in a " +
|
||||||
|
"route or within a constraint, use '[[' or ']]' instead.";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var ex = Assert.Throws<InvalidOperationException>(
|
var ex = Assert.Throws<InvalidOperationException>(
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
"Error 1:" + Environment.NewLine +
|
"Error 1:" + Environment.NewLine +
|
||||||
$"For action: '{controllerTypeInfo.FullName}.Unknown ({assemblyName})'" + Environment.NewLine +
|
$"For action: '{controllerTypeInfo.FullName}.Unknown ({assemblyName})'" + Environment.NewLine +
|
||||||
"Error: While processing template 'stub/[action]/[unknown]', a replacement value for the token 'unknown' " +
|
"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 +
|
Environment.NewLine +
|
||||||
"Error 2:" + Environment.NewLine +
|
"Error 2:" + Environment.NewLine +
|
||||||
$"For action: '{controllerTypeInfo.FullName}.Invalid ({assemblyName})'" + Environment.NewLine +
|
$"For action: '{controllerTypeInfo.FullName}.Invalid ({assemblyName})'" + Environment.NewLine +
|
||||||
|
|
@ -906,7 +907,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
"Error 1:" + Environment.NewLine +
|
"Error 1:" + Environment.NewLine +
|
||||||
$"For action: '{controllerTypeInfo.FullName}.Get ({assemblyName})'" + Environment.NewLine +
|
$"For action: '{controllerTypeInfo.FullName}.Get ({assemblyName})'" + Environment.NewLine +
|
||||||
"Error: While processing template 'Products_[unknown]', a replacement value for the token 'unknown' " +
|
"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
|
// Act & Assert
|
||||||
var ex = Assert.Throws<InvalidOperationException>(() => { provider.GetDescriptors(); });
|
var ex = Assert.Throws<InvalidOperationException>(() => { provider.GetDescriptors(); });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue