Require CookieBuilder.Name to be a not null or empty

This commit is contained in:
Nate McMaster 2017-06-30 09:20:13 -07:00
parent 271faf11bb
commit 199b0fa212
3 changed files with 57 additions and 55 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNetCore.Http.Abstractions;
namespace Microsoft.AspNetCore.Http namespace Microsoft.AspNetCore.Http
{ {
@ -10,10 +11,18 @@ namespace Microsoft.AspNetCore.Http
/// </summary> /// </summary>
public class CookieBuilder public class CookieBuilder
{ {
private string _name;
/// <summary> /// <summary>
/// The name of the cookie. /// The name of the cookie.
/// </summary> /// </summary>
public virtual string Name { get; set; } public virtual string Name
{
get => _name;
set => _name = !string.IsNullOrEmpty(value)
? value
: throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(value));
}
/// <summary> /// <summary>
/// The cookie path. /// The cookie path.

View File

@ -15,193 +15,183 @@ namespace Microsoft.AspNetCore.Http.Abstractions
/// </summary> /// </summary>
internal static string Exception_UseMiddlewareIServiceProviderNotAvailable internal static string Exception_UseMiddlewareIServiceProviderNotAvailable
{ {
get { return GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"); } get => GetString("Exception_UseMiddlewareIServiceProviderNotAvailable");
} }
/// <summary> /// <summary>
/// '{0}' is not available. /// '{0}' is not available.
/// </summary> /// </summary>
internal static string FormatException_UseMiddlewareIServiceProviderNotAvailable(object p0) internal static string FormatException_UseMiddlewareIServiceProviderNotAvailable(object p0)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"), p0);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"), p0);
}
/// <summary> /// <summary>
/// No public '{0}' method found. /// No public '{0}' or '{1}' method found.
/// </summary> /// </summary>
internal static string Exception_UseMiddlewareNoInvokeMethod internal static string Exception_UseMiddlewareNoInvokeMethod
{ {
get { return GetString("Exception_UseMiddlewareNoInvokeMethod"); } get => GetString("Exception_UseMiddlewareNoInvokeMethod");
} }
/// <summary> /// <summary>
/// No public '{0}' method found. /// No public '{0}' or '{1}' method found.
/// </summary> /// </summary>
internal static string FormatException_UseMiddlewareNoInvokeMethod(object p0, object p1) internal static string FormatException_UseMiddlewareNoInvokeMethod(object p0, object p1)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoInvokeMethod"), p0, p1);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoInvokeMethod"), p0, p1);
}
/// <summary> /// <summary>
/// '{0}' does not return an object of type '{1}'. /// '{0}' or '{1}' does not return an object of type '{2}'.
/// </summary> /// </summary>
internal static string Exception_UseMiddlewareNonTaskReturnType internal static string Exception_UseMiddlewareNonTaskReturnType
{ {
get { return GetString("Exception_UseMiddlewareNonTaskReturnType"); } get => GetString("Exception_UseMiddlewareNonTaskReturnType");
} }
/// <summary> /// <summary>
/// '{0}' does not return an object of type '{1}'. /// '{0}' or '{1}' does not return an object of type '{2}'.
/// </summary> /// </summary>
internal static string FormatException_UseMiddlewareNonTaskReturnType(object p0, object p1, object p2) internal static string FormatException_UseMiddlewareNonTaskReturnType(object p0, object p1, object p2)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNonTaskReturnType"), p0, p1, p2);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNonTaskReturnType"), p0, p1, p2);
}
/// <summary> /// <summary>
/// The '{0}' method's first argument must be of type '{1}'. /// The '{0}' or '{1}' method's first argument must be of type '{2}'.
/// </summary> /// </summary>
internal static string Exception_UseMiddlewareNoParameters internal static string Exception_UseMiddlewareNoParameters
{ {
get { return GetString("Exception_UseMiddlewareNoParameters"); } get => GetString("Exception_UseMiddlewareNoParameters");
} }
/// <summary> /// <summary>
/// The '{0}' method's first argument must be of type '{1}'. /// The '{0}' or '{1}' method's first argument must be of type '{2}'.
/// </summary> /// </summary>
internal static string FormatException_UseMiddlewareNoParameters(object p0, object p1, object p2) internal static string FormatException_UseMiddlewareNoParameters(object p0, object p1, object p2)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoParameters"), p0, p1, p2);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoParameters"), p0, p1, p2);
}
/// <summary> /// <summary>
/// Multiple public '{0}' methods are available. /// Multiple public '{0}' or '{1}' methods are available.
/// </summary> /// </summary>
internal static string Exception_UseMiddleMutlipleInvokes internal static string Exception_UseMiddleMutlipleInvokes
{ {
get { return GetString("Exception_UseMiddleMutlipleInvokes"); } get => GetString("Exception_UseMiddleMutlipleInvokes");
} }
/// <summary> /// <summary>
/// Multiple public '{0}' methods are available. /// Multiple public '{0}' or '{1}' methods are available.
/// </summary> /// </summary>
internal static string FormatException_UseMiddleMutlipleInvokes(object p0, object p1) internal static string FormatException_UseMiddleMutlipleInvokes(object p0, object p1)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddleMutlipleInvokes"), p0, p1);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddleMutlipleInvokes"), p0, p1);
}
/// <summary> /// <summary>
/// The path in '{0}' must start with '/'. /// The path in '{0}' must start with '/'.
/// </summary> /// </summary>
internal static string Exception_PathMustStartWithSlash internal static string Exception_PathMustStartWithSlash
{ {
get { return GetString("Exception_PathMustStartWithSlash"); } get => GetString("Exception_PathMustStartWithSlash");
} }
/// <summary> /// <summary>
/// The path in '{0}' must start with '/'. /// The path in '{0}' must start with '/'.
/// </summary> /// </summary>
internal static string FormatException_PathMustStartWithSlash(object p0) internal static string FormatException_PathMustStartWithSlash(object p0)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0);
}
/// <summary> /// <summary>
/// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'. /// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'.
/// </summary> /// </summary>
internal static string Exception_InvokeMiddlewareNoService internal static string Exception_InvokeMiddlewareNoService
{ {
get { return GetString("Exception_InvokeMiddlewareNoService"); } get => GetString("Exception_InvokeMiddlewareNoService");
} }
/// <summary> /// <summary>
/// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'. /// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'.
/// </summary> /// </summary>
internal static string FormatException_InvokeMiddlewareNoService(object p0, object p1) internal static string FormatException_InvokeMiddlewareNoService(object p0, object p1)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeMiddlewareNoService"), p0, p1);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeMiddlewareNoService"), p0, p1);
}
/// <summary> /// <summary>
/// The '{0}' method must not have ref or out parameters. /// The '{0}' method must not have ref or out parameters.
/// </summary> /// </summary>
internal static string Exception_InvokeDoesNotSupportRefOrOutParams internal static string Exception_InvokeDoesNotSupportRefOrOutParams
{ {
get { return GetString("Exception_InvokeDoesNotSupportRefOrOutParams"); } get => GetString("Exception_InvokeDoesNotSupportRefOrOutParams");
} }
/// <summary> /// <summary>
/// The '{0}' method must not have ref or out parameters. /// The '{0}' method must not have ref or out parameters.
/// </summary> /// </summary>
internal static string FormatException_InvokeDoesNotSupportRefOrOutParams(object p0) internal static string FormatException_InvokeDoesNotSupportRefOrOutParams(object p0)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeDoesNotSupportRefOrOutParams"), p0);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeDoesNotSupportRefOrOutParams"), p0);
}
/// <summary> /// <summary>
/// The value must be greater than zero. /// The value must be greater than zero.
/// </summary> /// </summary>
internal static string Exception_PortMustBeGreaterThanZero internal static string Exception_PortMustBeGreaterThanZero
{ {
get { return GetString("Exception_PortMustBeGreaterThanZero"); } get => GetString("Exception_PortMustBeGreaterThanZero");
} }
/// <summary> /// <summary>
/// The value must be greater than zero. /// The value must be greater than zero.
/// </summary> /// </summary>
internal static string FormatException_PortMustBeGreaterThanZero() internal static string FormatException_PortMustBeGreaterThanZero()
{ => GetString("Exception_PortMustBeGreaterThanZero");
return GetString("Exception_PortMustBeGreaterThanZero");
}
/// <summary> /// <summary>
/// No service for type '{0}' has been registered. /// No service for type '{0}' has been registered.
/// </summary> /// </summary>
internal static string Exception_UseMiddlewareNoMiddlewareFactory internal static string Exception_UseMiddlewareNoMiddlewareFactory
{ {
get { return GetString("Exception_UseMiddlewareNoMiddlewareFactory"); } get => GetString("Exception_UseMiddlewareNoMiddlewareFactory");
} }
/// <summary> /// <summary>
/// No service for type '{0}' has been registered. /// No service for type '{0}' has been registered.
/// </summary> /// </summary>
internal static string FormatException_UseMiddlewareNoMiddlewareFactory(object p0) internal static string FormatException_UseMiddlewareNoMiddlewareFactory(object p0)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoMiddlewareFactory"), p0);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoMiddlewareFactory"), p0);
}
/// <summary> /// <summary>
/// '{0}' failed to create middleware of type '{1}'. /// '{0}' failed to create middleware of type '{1}'.
/// </summary> /// </summary>
internal static string Exception_UseMiddlewareUnableToCreateMiddleware internal static string Exception_UseMiddlewareUnableToCreateMiddleware
{ {
get { return GetString("Exception_UseMiddlewareUnableToCreateMiddleware"); } get => GetString("Exception_UseMiddlewareUnableToCreateMiddleware");
} }
/// <summary> /// <summary>
/// '{0}' failed to create middleware of type '{1}'. /// '{0}' failed to create middleware of type '{1}'.
/// </summary> /// </summary>
internal static string FormatException_UseMiddlewareUnableToCreateMiddleware(object p0, object p1) internal static string FormatException_UseMiddlewareUnableToCreateMiddleware(object p0, object p1)
{ => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareUnableToCreateMiddleware"), p0, p1);
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareUnableToCreateMiddleware"), p0, p1);
}
/// <summary> /// <summary>
/// Types that implement '{0}' do not support explicit arguments. /// Types that implement '{0}' do not support explicit arguments.
/// </summary> /// </summary>
internal static string Exception_UseMiddlewareExplicitArgumentsNotSupported internal static string Exception_UseMiddlewareExplicitArgumentsNotSupported
{ {
get { return GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"); } get => GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported");
} }
/// <summary> /// <summary>
/// Types that implement '{0}' do not support explicit arguments. /// Types that implement '{0}' do not support explicit arguments.
/// </summary> /// </summary>
internal static string FormatException_UseMiddlewareExplicitArgumentsNotSupported(object p0) internal static string FormatException_UseMiddlewareExplicitArgumentsNotSupported(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"), p0);
/// <summary>
/// Argument cannot be null or empty.
/// </summary>
internal static string ArgumentCannotBeNullOrEmpty
{ {
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"), p0); get => GetString("ArgumentCannotBeNullOrEmpty");
} }
/// <summary>
/// Argument cannot be null or empty.
/// </summary>
internal static string FormatArgumentCannotBeNullOrEmpty()
=> GetString("ArgumentCannotBeNullOrEmpty");
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);

View File

@ -153,4 +153,7 @@
<data name="Exception_UseMiddlewareExplicitArgumentsNotSupported" xml:space="preserve"> <data name="Exception_UseMiddlewareExplicitArgumentsNotSupported" xml:space="preserve">
<value>Types that implement '{0}' do not support explicit arguments.</value> <value>Types that implement '{0}' do not support explicit arguments.</value>
</data> </data>
<data name="ArgumentCannotBeNullOrEmpty" xml:space="preserve">
<value>Argument cannot be null or empty.</value>
</data>
</root> </root>