Adding exception message for paths not starting with / #251

This commit is contained in:
John Luo 2015-11-13 17:32:48 -08:00
parent d25c25c4b2
commit d4d04d2c96
4 changed files with 14 additions and 2 deletions

View File

@ -3,6 +3,7 @@
using System;
using System.Text.Encodings.Web;
using Microsoft.AspNet.Http.Abstractions;
namespace Microsoft.AspNet.Http
{
@ -29,7 +30,7 @@ namespace Microsoft.AspNet.Http
{
if (!string.IsNullOrEmpty(value) && value[0] != '/')
{
throw new ArgumentException(""/*Resources.Exception_PathMustStartWithSlash*/, nameof(value));
throw new ArgumentException(Resources.FormatException_PathMustStartWithSlash(nameof(value)), nameof(value));
}
_value = value;
}

View File

@ -10,6 +10,14 @@ namespace Microsoft.AspNet.Http.Abstractions
private static readonly ResourceManager _resourceManager
= new ResourceManager("Microsoft.AspNet.Http.Abstractions.Resources", typeof(Resources).GetTypeInfo().Assembly);
/// <summary>
/// '{0}' is not available.
/// </summary>
internal static string FormatException_PathMustStartWithSlash(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0);
}
/// <summary>
/// '{0}' is not available.
/// </summary>

View File

@ -132,4 +132,7 @@
<data name="Exception_UseMiddleMutlipleInvokes" xml:space="preserve">
<value>Multiple public '{0}' methods are available.</value>
</data>
<data name="Exception_PathMustStartWithSlash" xml:space="preserve">
<value>The path in '{0}' must start with '/'.</value>
</data>
</root>

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Http
public void CtorThrows_IfPathDoesNotHaveLeadingSlash()
{
// Act and Assert
ExceptionAssert.ThrowsArgument(() => new PathString("hello"), "value", "");
ExceptionAssert.ThrowsArgument(() => new PathString("hello"), "value", "The path in 'value' must start with '/'.");
}
[Theory]