From d4d04d2c96d9050742e45ebb7006cd0ea4af3dcc Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 13 Nov 2015 17:32:48 -0800 Subject: [PATCH] Adding exception message for paths not starting with / #251 --- src/Microsoft.AspNet.Http.Abstractions/PathString.cs | 3 ++- .../Properties/Resources.Designer.cs | 8 ++++++++ src/Microsoft.AspNet.Http.Abstractions/Resources.resx | 3 +++ .../PathStringTests.cs | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Http.Abstractions/PathString.cs b/src/Microsoft.AspNet.Http.Abstractions/PathString.cs index ef6e1bb39e..78c01cdcc1 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/PathString.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/PathString.cs @@ -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; } diff --git a/src/Microsoft.AspNet.Http.Abstractions/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Http.Abstractions/Properties/Resources.Designer.cs index 9fb86a30c6..82505c66e0 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/Properties/Resources.Designer.cs @@ -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); + /// + /// '{0}' is not available. + /// + internal static string FormatException_PathMustStartWithSlash(object p0) + { + return string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0); + } + /// /// '{0}' is not available. /// diff --git a/src/Microsoft.AspNet.Http.Abstractions/Resources.resx b/src/Microsoft.AspNet.Http.Abstractions/Resources.resx index bdd74fd6de..1c947c352b 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/Resources.resx +++ b/src/Microsoft.AspNet.Http.Abstractions/Resources.resx @@ -132,4 +132,7 @@ Multiple public '{0}' methods are available. + + The path in '{0}' must start with '/'. + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Http.Abstractions.Tests/PathStringTests.cs b/test/Microsoft.AspNet.Http.Abstractions.Tests/PathStringTests.cs index 48d403a9ee..3eb5673d60 100644 --- a/test/Microsoft.AspNet.Http.Abstractions.Tests/PathStringTests.cs +++ b/test/Microsoft.AspNet.Http.Abstractions.Tests/PathStringTests.cs @@ -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]