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

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
@ -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 +
@ -701,7 +702,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
VerifyMultiLineError(expectedMessage, exception.Message, unorderedStart: 1, unorderedLineCount: 2);
}
// Verify that the expected exception and error message is thrown even when the user builds the model
// Verify that the expected exception and error message is thrown even when the user builds the model
// incorrectly.
[Fact]
public void AttributeRouting_ThrowsIfAttributeRoutedAndNonAttributedActions_OnTheSameMethod_UsingCustomConvention()
@ -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(); });