Browse Source

Normalize collection empty checks in the Entity Framework/Entity Framework Core/MongoDB stores

pull/2514/head
Kévin Chalet 2 months ago
parent
commit
ee3bfb76c0
  1. 6
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs
  2. 2
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs
  3. 6
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs
  4. 6
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs
  5. 2
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs
  6. 40
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs
  7. 9
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs
  8. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs
  9. 13
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs
  10. 11
      src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs
  11. 2
      src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
  12. 2
      src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs
  13. 2
      src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs
  14. 2
      src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs
  15. 6
      test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs
  16. 6
      test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs

6
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs

@ -763,7 +763,7 @@ public class OpenIddictEntityFrameworkApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (names is not { Count: > 0 }) if (names is not { IsEmpty: false })
{ {
application.DisplayNames = null; application.DisplayNames = null;
@ -878,7 +878,7 @@ public class OpenIddictEntityFrameworkApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
application.Properties = null; application.Properties = null;
@ -983,7 +983,7 @@ public class OpenIddictEntityFrameworkApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (settings is not { Count: > 0 }) if (settings is not { IsEmpty: false })
{ {
application.Settings = null; application.Settings = null;

2
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs

@ -747,7 +747,7 @@ public class OpenIddictEntityFrameworkAuthorizationStore<
{ {
ArgumentNullException.ThrowIfNull(authorization); ArgumentNullException.ThrowIfNull(authorization);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
authorization.Properties = null; authorization.Properties = null;

6
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs

@ -410,7 +410,7 @@ public class OpenIddictEntityFrameworkResourceStore<
{ {
ArgumentNullException.ThrowIfNull(resource); ArgumentNullException.ThrowIfNull(resource);
if (descriptions is not { Count: > 0 }) if (descriptions is not { IsEmpty: false })
{ {
resource.Descriptions = null; resource.Descriptions = null;
@ -456,7 +456,7 @@ public class OpenIddictEntityFrameworkResourceStore<
{ {
ArgumentNullException.ThrowIfNull(resource); ArgumentNullException.ThrowIfNull(resource);
if (names is not { Count: > 0 }) if (names is not { IsEmpty: false })
{ {
resource.DisplayNames = null; resource.DisplayNames = null;
@ -502,7 +502,7 @@ public class OpenIddictEntityFrameworkResourceStore<
{ {
ArgumentNullException.ThrowIfNull(resource); ArgumentNullException.ThrowIfNull(resource);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
resource.Properties = null; resource.Properties = null;

6
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs

@ -480,7 +480,7 @@ public class OpenIddictEntityFrameworkScopeStore<
{ {
ArgumentNullException.ThrowIfNull(scope); ArgumentNullException.ThrowIfNull(scope);
if (descriptions is not { Count: > 0 }) if (descriptions is not { IsEmpty: false })
{ {
scope.Descriptions = null; scope.Descriptions = null;
@ -526,7 +526,7 @@ public class OpenIddictEntityFrameworkScopeStore<
{ {
ArgumentNullException.ThrowIfNull(scope); ArgumentNullException.ThrowIfNull(scope);
if (names is not { Count: > 0 }) if (names is not { IsEmpty: false })
{ {
scope.DisplayNames = null; scope.DisplayNames = null;
@ -572,7 +572,7 @@ public class OpenIddictEntityFrameworkScopeStore<
{ {
ArgumentNullException.ThrowIfNull(scope); ArgumentNullException.ThrowIfNull(scope);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
scope.Properties = null; scope.Properties = null;

2
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs

@ -886,7 +886,7 @@ public class OpenIddictEntityFrameworkTokenStore<
{ {
ArgumentNullException.ThrowIfNull(token); ArgumentNullException.ThrowIfNull(token);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
token.Properties = null; token.Properties = null;

40
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs

@ -574,7 +574,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
application.DisplayNames = names is { Count: > 0 } application.DisplayNames = names is { IsEmpty: false }
? names.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value) ? names.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value)
: null; : null;
@ -596,14 +596,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (permissions.IsDefaultOrEmpty) application.Permissions = permissions is { IsDefaultOrEmpty: false } ? [.. permissions] : null;
{
application.Permissions = null;
return ValueTask.CompletedTask;
}
application.Permissions = permissions.ToArray();
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }
@ -614,14 +607,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (uris.IsDefaultOrEmpty) application.PostLogoutRedirectUris = uris is { IsDefaultOrEmpty: false } ? [.. uris] : null;
{
application.PostLogoutRedirectUris = null;
return ValueTask.CompletedTask;
}
application.PostLogoutRedirectUris = uris.ToArray();
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }
@ -643,14 +629,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (uris.IsDefaultOrEmpty) application.RedirectUris = uris is { IsDefaultOrEmpty: false } ? [.. uris] : null;
{
application.RedirectUris = null;
return ValueTask.CompletedTask;
}
application.RedirectUris = uris.ToArray();
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }
@ -660,14 +639,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (requirements.IsDefaultOrEmpty) application.Requirements = requirements is { IsDefaultOrEmpty: false } ? [.. requirements] : null;
{
application.Requirements = null;
return ValueTask.CompletedTask;
}
application.Requirements = requirements.ToArray();
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }
@ -678,7 +650,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
application.Settings = settings; application.Settings = settings is { IsEmpty: false } ? settings : null;
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }

9
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs

@ -825,14 +825,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore<
{ {
ArgumentNullException.ThrowIfNull(authorization); ArgumentNullException.ThrowIfNull(authorization);
if (scopes.IsDefaultOrEmpty) authorization.Scopes = scopes is { IsDefaultOrEmpty: false } ? [.. scopes] : null;
{
authorization.Scopes = null;
return ValueTask.CompletedTask;
}
authorization.Scopes = scopes.ToArray();
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }

4
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs

@ -332,7 +332,7 @@ public class OpenIddictEntityFrameworkCoreResourceStore<
{ {
ArgumentNullException.ThrowIfNull(resource); ArgumentNullException.ThrowIfNull(resource);
resource.Descriptions = descriptions is { Count: > 0 } resource.Descriptions = descriptions is { IsEmpty: false }
? descriptions.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value) ? descriptions.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value)
: null; : null;
@ -355,7 +355,7 @@ public class OpenIddictEntityFrameworkCoreResourceStore<
{ {
ArgumentNullException.ThrowIfNull(resource); ArgumentNullException.ThrowIfNull(resource);
resource.DisplayNames = names is { Count: > 0 } resource.DisplayNames = names is { IsEmpty: false }
? names.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value) ? names.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value)
: null; : null;

13
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs

@ -360,7 +360,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
{ {
ArgumentNullException.ThrowIfNull(scope); ArgumentNullException.ThrowIfNull(scope);
scope.Descriptions = descriptions is { Count: > 0 } scope.Descriptions = descriptions is { IsEmpty: false }
? descriptions.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value) ? descriptions.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value)
: null; : null;
@ -383,7 +383,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
{ {
ArgumentNullException.ThrowIfNull(scope); ArgumentNullException.ThrowIfNull(scope);
scope.DisplayNames = names is { Count: > 0 } scope.DisplayNames = names is { IsEmpty: false }
? names.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value) ? names.ToImmutableDictionary(static pair => pair.Key.Name, static pair => pair.Value)
: null; : null;
@ -416,14 +416,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
{ {
ArgumentNullException.ThrowIfNull(scope); ArgumentNullException.ThrowIfNull(scope);
if (resources.IsDefaultOrEmpty) scope.Resources = resources is { IsDefaultOrEmpty: false } ? [.. resources] : null;
{
scope.Resources = null;
return ValueTask.CompletedTask;
}
scope.Resources = resources.ToArray();
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }

11
src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs

@ -510,7 +510,7 @@ public class OpenIddictMongoDbApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
application.Properties = null; application.Properties = null;
@ -568,14 +568,7 @@ public class OpenIddictMongoDbApplicationStore<
{ {
ArgumentNullException.ThrowIfNull(application); ArgumentNullException.ThrowIfNull(application);
if (settings is not { Count: > 0 }) application.Settings = settings is { IsEmpty: false } ? settings : null;
{
application.Settings = null;
return ValueTask.CompletedTask;
}
application.Settings = settings;
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }

2
src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs

@ -491,7 +491,7 @@ public class OpenIddictMongoDbAuthorizationStore<
{ {
ArgumentNullException.ThrowIfNull(authorization); ArgumentNullException.ThrowIfNull(authorization);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
authorization.Properties = null; authorization.Properties = null;

2
src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs

@ -360,7 +360,7 @@ public class OpenIddictMongoDbResourceStore<
{ {
ArgumentNullException.ThrowIfNull(resource); ArgumentNullException.ThrowIfNull(resource);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
resource.Properties = null; resource.Properties = null;

2
src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs

@ -387,7 +387,7 @@ public class OpenIddictMongoDbScopeStore<
{ {
ArgumentNullException.ThrowIfNull(scope); ArgumentNullException.ThrowIfNull(scope);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
scope.Properties = null; scope.Properties = null;

2
src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs

@ -590,7 +590,7 @@ public class OpenIddictMongoDbTokenStore<
{ {
ArgumentNullException.ThrowIfNull(token); ArgumentNullException.ThrowIfNull(token);
if (properties is not { Count: > 0 }) if (properties is not { IsEmpty: false })
{ {
token.Properties = null; token.Properties = null;

6
test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTestClient.cs

@ -363,7 +363,7 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable
from parameter in parameters from parameter in parameters
group parameter by parameter.Key into grouping group parameter by parameter.Key into grouping
let values = grouping.Select(parameter => parameter.Value) let values = grouping.Select(parameter => parameter.Value)
select KeyValuePair.Create(grouping.Key, new StringValues(values.ToArray()))); select KeyValuePair.Create(grouping.Key, new StringValues([.. values])));
} }
else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase))
@ -406,7 +406,7 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable
from parameter in parameters from parameter in parameters
group parameter by parameter.Key into grouping group parameter by parameter.Key into grouping
let values = grouping.Select(parameter => parameter.Value) let values = grouping.Select(parameter => parameter.Value)
select KeyValuePair.Create(grouping.Key, new StringValues(values.ToArray()))); select KeyValuePair.Create(grouping.Key, new StringValues([.. values])));
} }
else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase))
@ -445,7 +445,7 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable
from parameter in parameters from parameter in parameters
group parameter by parameter.Key into grouping group parameter by parameter.Key into grouping
let values = grouping.Select(parameter => parameter.Value) let values = grouping.Select(parameter => parameter.Value)
select KeyValuePair.Create(grouping.Key, new StringValues(values.ToArray()))); select KeyValuePair.Create(grouping.Key, new StringValues([.. values])));
} }
return new OpenIddictResponse(); return new OpenIddictResponse();

6
test/OpenIddict.Validation.IntegrationTests/OpenIddictValidationIntegrationTestClient.cs

@ -363,7 +363,7 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable
from parameter in parameters from parameter in parameters
group parameter by parameter.Key into grouping group parameter by parameter.Key into grouping
let values = grouping.Select(parameter => parameter.Value) let values = grouping.Select(parameter => parameter.Value)
select KeyValuePair.Create(grouping.Key, new StringValues(values.ToArray()))); select KeyValuePair.Create(grouping.Key, new StringValues([.. values])));
} }
else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase))
@ -406,7 +406,7 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable
from parameter in parameters from parameter in parameters
group parameter by parameter.Key into grouping group parameter by parameter.Key into grouping
let values = grouping.Select(parameter => parameter.Value) let values = grouping.Select(parameter => parameter.Value)
select KeyValuePair.Create(grouping.Key, new StringValues(values.ToArray()))); select KeyValuePair.Create(grouping.Key, new StringValues([.. values])));
} }
else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(message.Content?.Headers?.ContentType?.MediaType, "text/plain", StringComparison.OrdinalIgnoreCase))
@ -445,7 +445,7 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable
from parameter in parameters from parameter in parameters
group parameter by parameter.Key into grouping group parameter by parameter.Key into grouping
let values = grouping.Select(parameter => parameter.Value) let values = grouping.Select(parameter => parameter.Value)
select KeyValuePair.Create(grouping.Key, new StringValues(values.ToArray()))); select KeyValuePair.Create(grouping.Key, new StringValues([.. values])));
} }
return new OpenIddictResponse(); return new OpenIddictResponse();

Loading…
Cancel
Save