Changed expected exception message to the one defined in Resources.resx.
Removed the Debug.Assert as that caused the test runner to crash as in this case the preceding part is not a literal. Fixes the test runner crash.
This commit is contained in:
parent
f457c7b9d8
commit
a18f59ab88
|
|
@ -187,7 +187,7 @@
|
|||
<value>In a route parameter, '{' and '}' must be escaped with '{{' and '}}'.</value>
|
||||
</data>
|
||||
<data name="TemplateRoute_OptionalParameterCanbBePrecededByPeriod" xml:space="preserve">
|
||||
<value>In the segment '{0}', the optional parameter '{1}' is preceded by an invalid segment '{2}'. Only a period (.) can precede an optional parameter.</value>
|
||||
<value>In the segment '{0}', the optional parameter '{1}' is preceded by an invalid segment '{2}'. Only a period (.) can precede an optional parameter.</value>
|
||||
</data>
|
||||
<data name="TemplateRoute_OptionalParameterHasTobeTheLast" xml:space="preserve">
|
||||
<value>An optional parameter must be at the end of the segment. In the segment '{0}', optional parameter '{1}' is followed by '{2}'.</value>
|
||||
|
|
|
|||
|
|
@ -342,20 +342,26 @@ namespace Microsoft.AspNetCore.Routing.Template
|
|||
// This optional parameter is the last part in the segment
|
||||
if (i == segment.Parts.Count - 1)
|
||||
{
|
||||
Debug.Assert(segment.Parts[i - 1].IsLiteral);
|
||||
|
||||
// the optional parameter is preceded by a period
|
||||
if (segment.Parts[i - 1].Text == PeriodString)
|
||||
if(!segment.Parts[i - 1].IsLiteral)
|
||||
{
|
||||
segment.Parts[i - 1].IsOptionalSeperator = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The optional parameter is preceded by a literal other than period
|
||||
// The optional parameter is preceded by something that is not a literal.
|
||||
// Example of error message:
|
||||
// "In the complex segment {RouteValue}-{param?}, the optional parameter 'param'is preceded
|
||||
// by an invalid segment "-". Only valid literal to precede an optional parameter is a
|
||||
// period (.).
|
||||
// "In the segment '{RouteValue}-{param?}', the optional parameter 'param' is preceded
|
||||
// by an invalid segment '-'. Only a period (.) can precede an optional parameter.
|
||||
context.Error = string.Format(
|
||||
Resources.TemplateRoute_OptionalParameterCanbBePrecededByPeriod,
|
||||
segment.DebuggerToString(),
|
||||
part.Name,
|
||||
segment.Parts[i - 1].DebuggerToString());
|
||||
|
||||
return false;
|
||||
}
|
||||
if(segment.Parts[i - 1].Text != PeriodString)
|
||||
{
|
||||
// The optional parameter is preceded by a literal other than period.
|
||||
// Example of error message:
|
||||
// "In the segment '{RouteValue}-{param?}', the optional parameter 'param' is preceded
|
||||
// by an invalid segment '-'. Only a period (.) can precede an optional parameter.
|
||||
context.Error = string.Format(
|
||||
Resources.TemplateRoute_OptionalParameterCanbBePrecededByPeriod,
|
||||
segment.DebuggerToString(),
|
||||
|
|
@ -364,6 +370,7 @@ namespace Microsoft.AspNetCore.Routing.Template
|
|||
|
||||
return false;
|
||||
}
|
||||
segment.Parts[i - 1].IsOptionalSeperator = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -545,19 +545,19 @@ namespace Microsoft.AspNetCore.Routing.Template.Tests
|
|||
+ Environment.NewLine + "Parameter name: routeTemplate");
|
||||
}
|
||||
|
||||
[Theory(Skip = "Skipped because it causes the test framework to crash")]
|
||||
[Theory]
|
||||
[InlineData("{p1}-{p2?}", "-")]
|
||||
[InlineData("{p1}..{p2?}", "..")]
|
||||
[InlineData("..{p2?}", "..")]
|
||||
[InlineData("{p1}.abc.{p2?}", ".abc.")]
|
||||
[InlineData("{p1}{p2?}", "p1")]
|
||||
[InlineData("{p1}{p2?}", "{p1}")]
|
||||
public void Parse_ComplexSegment_OptionalParametersSeperatedByPeriod_Invalid(string template, string parameter)
|
||||
{
|
||||
// Act and Assert
|
||||
ExceptionAssert.Throws<ArgumentException>(
|
||||
() => TemplateParser.Parse(template),
|
||||
"In the complex segment '"+ template +"', the optional parameter 'p2' is preceded by an invalid " +
|
||||
"segment '" + parameter +"'. Only valid literal to precede an optional parameter is a period (.)." +
|
||||
"In the segment '"+ template +"', the optional parameter 'p2' is preceded by an invalid " +
|
||||
"segment '" + parameter +"'. Only a period (.) can precede an optional parameter." +
|
||||
Environment.NewLine + "Parameter name: routeTemplate");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue