Browse Source

Change the action level of the CA1725 rule and update affected methods

pull/1011/head
Kévin Chalet 6 years ago
parent
commit
87c7eec852
  1. 2
      eng/CodeAnalysis.ruleset
  2. 16
      samples/Mvc.Server/Helpers/FormValueRequiredAttribute.cs
  3. 30
      src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs
  4. 11
      src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs
  5. 10
      src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs
  6. 10
      test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs

2
eng/CodeAnalysis.ruleset

@ -69,7 +69,7 @@
<Rule Id="CA1720" Action="None" /> <!-- Identifier contains type name -->
<Rule Id="CA1721" Action="None" /> <!-- Property names should not match get methods -->
<Rule Id="CA1724" Action="None" /> <!-- Type names should not match namespaces -->
<Rule Id="CA1725" Action="Info" /> <!-- Parameter names should match base declaration -->
<Rule Id="CA1725" Action="Warning" /> <!-- Parameter names should match base declaration -->
<Rule Id="CA1801" Action="None" /> <!-- Review unused parameters -->
<Rule Id="CA1802" Action="Warning" /> <!-- Use literals where appropriate -->
<Rule Id="CA1806" Action="None" /> <!-- Do not ignore method results -->

16
samples/Mvc.Server/Helpers/FormValueRequiredAttribute.cs

@ -14,27 +14,27 @@ namespace Mvc.Server.Helpers
_name = name;
}
public override bool IsValidForRequest(RouteContext context, ActionDescriptor action)
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
if (string.Equals(context.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) ||
string.Equals(context.HttpContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) ||
string.Equals(context.HttpContext.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) ||
string.Equals(context.HttpContext.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase))
if (string.Equals(routeContext.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) ||
string.Equals(routeContext.HttpContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) ||
string.Equals(routeContext.HttpContext.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) ||
string.Equals(routeContext.HttpContext.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (string.IsNullOrEmpty(context.HttpContext.Request.ContentType))
if (string.IsNullOrEmpty(routeContext.HttpContext.Request.ContentType))
{
return false;
}
if (!context.HttpContext.Request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase))
if (!routeContext.HttpContext.Request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase))
{
return false;
}
return !string.IsNullOrEmpty(context.HttpContext.Request.Form[_name]);
return !string.IsNullOrEmpty(routeContext.HttpContext.Request.Form[_name]);
}
}
}

30
src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs

@ -19,40 +19,40 @@ namespace OpenIddict.Abstractions
/// <summary>
/// Determines whether the specified type is supported by this converter.
/// </summary>
/// <param name="type">The type to convert.</param>
/// <param name="typeToConvert">The type to convert.</param>
/// <returns><c>true</c> if the type is supported, <c>false</c> otherwise.</returns>
public override bool CanConvert([NotNull] Type type)
public override bool CanConvert([NotNull] Type typeToConvert)
{
if (type == null)
if (typeToConvert == null)
{
throw new ArgumentNullException(nameof(type));
throw new ArgumentNullException(nameof(typeToConvert));
}
return type == typeof(OpenIddictMessage) ||
type == typeof(OpenIddictRequest) ||
type == typeof(OpenIddictResponse);
return typeToConvert == typeof(OpenIddictMessage) ||
typeToConvert == typeof(OpenIddictRequest) ||
typeToConvert == typeof(OpenIddictResponse);
}
/// <summary>
/// Deserializes an <see cref="OpenIddictMessage"/> instance.
/// </summary>
/// <param name="reader">The JSON reader.</param>
/// <param name="type">The type of the deserialized instance.</param>
/// <param name="typeToConvert">The type of the deserialized instance.</param>
/// <param name="options">The JSON serializer options.</param>
/// <returns>The deserialized <see cref="OpenIddictMessage"/> instance.</returns>
public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (type == null)
if (typeToConvert == null)
{
throw new ArgumentNullException(nameof(type));
throw new ArgumentNullException(nameof(typeToConvert));
}
using var document = JsonDocument.ParseValue(ref reader);
return type == typeof(OpenIddictMessage) ? new OpenIddictMessage(document.RootElement.Clone()) :
type == typeof(OpenIddictRequest) ? new OpenIddictRequest(document.RootElement.Clone()) :
type == typeof(OpenIddictResponse) ? (OpenIddictMessage) new OpenIddictResponse(document.RootElement.Clone()) :
throw new ArgumentException("The specified type is not supported.", nameof(type));
return typeToConvert == typeof(OpenIddictMessage) ? new OpenIddictMessage(document.RootElement.Clone()) :
typeToConvert == typeof(OpenIddictRequest) ? new OpenIddictRequest(document.RootElement.Clone()) :
typeToConvert == typeof(OpenIddictResponse) ? (OpenIddictMessage) new OpenIddictResponse(document.RootElement.Clone()) :
throw new ArgumentException("The specified type is not supported.", nameof(typeToConvert));
}
/// <summary>

11
src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs

@ -88,11 +88,11 @@ namespace OpenIddict.Abstractions
/// Determines whether the current <see cref="OpenIddictParameter"/>
/// instance is equal to the specified <see cref="OpenIddictParameter"/>.
/// </summary>
/// <param name="parameter">The other object to which to compare this instance.</param>
/// <param name="other">The other object to which to compare this instance.</param>
/// <returns><c>true</c> if the two instances are equal, <c>false</c> otherwise.</returns>
public bool Equals(OpenIddictParameter parameter)
public bool Equals(OpenIddictParameter other)
{
return (left: Value, right: parameter.Value) switch
return (left: Value, right: other.Value) switch
{
// If the two parameters reference the same instance, return true.
// Note: true will also be returned if the two parameters are null.
@ -200,10 +200,9 @@ namespace OpenIddict.Abstractions
/// Determines whether the current <see cref="OpenIddictParameter"/>
/// instance is equal to the specified <see cref="object"/>.
/// </summary>
/// <param name="value">The other object to which to compare this instance.</param>
/// <param name="obj">The other object to which to compare this instance.</param>
/// <returns><c>true</c> if the two instances are equal, <c>false</c> otherwise.</returns>
public override bool Equals(object value)
=> value is OpenIddictParameter parameter && Equals(parameter);
public override bool Equals(object obj) => obj is OpenIddictParameter parameter && Equals(parameter);
/// <summary>
/// Returns the hash code of the current <see cref="OpenIddictParameter"/> instance.

10
src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs

@ -28,11 +28,11 @@ namespace OpenIddict.EntityFrameworkCore
{
}
public override void Customize([NotNull] ModelBuilder builder, [NotNull] DbContext context)
public override void Customize([NotNull] ModelBuilder modelBuilder, [NotNull] DbContext context)
{
if (builder == null)
if (modelBuilder == null)
{
throw new ArgumentNullException(nameof(builder));
throw new ArgumentNullException(nameof(modelBuilder));
}
if (context == null)
@ -41,9 +41,9 @@ namespace OpenIddict.EntityFrameworkCore
}
// Register the OpenIddict entity sets.
builder.UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>();
modelBuilder.UseOpenIddict<TApplication, TAuthorization, TScope, TToken, TKey>();
base.Customize(builder, context);
base.Customize(modelBuilder, context);
}
}
}

10
test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs

@ -21,9 +21,9 @@ namespace OpenIddict.Abstractions.Tests.Primitives
var converter = new OpenIddictConverter();
// Act and assert
var exception = Assert.Throws<ArgumentNullException>(() => converter.CanConvert(type: null));
var exception = Assert.Throws<ArgumentNullException>(() => converter.CanConvert(typeToConvert: null));
Assert.Equal("type", exception.ParamName);
Assert.Equal("typeToConvert", exception.ParamName);
}
[Theory]
@ -58,10 +58,10 @@ namespace OpenIddict.Abstractions.Tests.Primitives
var exception = Assert.Throws<ArgumentNullException>(delegate
{
var reader = new Utf8JsonReader();
return converter.Read(ref reader, type: null, options: null);
return converter.Read(ref reader, typeToConvert: null, options: null);
});
Assert.Equal("type", exception.ParamName);
Assert.Equal("typeToConvert", exception.ParamName);
}
[Theory]
@ -87,7 +87,7 @@ namespace OpenIddict.Abstractions.Tests.Primitives
});
Assert.StartsWith("The specified type is not supported.", exception.Message);
Assert.Equal("type", exception.ParamName);
Assert.Equal("typeToConvert", exception.ParamName);
}
[Theory]

Loading…
Cancel
Save