Browse Source

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

pull/2510/head
Kévin Chalet 2 weeks ago
parent
commit
892bca1548
  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);
if (names is not { Count: > 0 })
if (names is not { IsEmpty: false })
{
application.DisplayNames = null;
@ -878,7 +878,7 @@ public class OpenIddictEntityFrameworkApplicationStore<
{
ArgumentNullException.ThrowIfNull(application);
if (properties is not { Count: > 0 })
if (properties is not { IsEmpty: false })
{
application.Properties = null;
@ -983,7 +983,7 @@ public class OpenIddictEntityFrameworkApplicationStore<
{
ArgumentNullException.ThrowIfNull(application);
if (settings is not { Count: > 0 })
if (settings is not { IsEmpty: false })
{
application.Settings = null;

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

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

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

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

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

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

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

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

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

@ -574,7 +574,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{
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)
: null;
@ -596,14 +596,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{
ArgumentNullException.ThrowIfNull(application);
if (permissions.IsDefaultOrEmpty)
{
application.Permissions = null;
return ValueTask.CompletedTask;
}
application.Permissions = permissions.ToArray();
application.Permissions = permissions is { IsDefaultOrEmpty: false } ? [.. permissions] : null;
return ValueTask.CompletedTask;
}
@ -614,14 +607,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{
ArgumentNullException.ThrowIfNull(application);
if (uris.IsDefaultOrEmpty)
{
application.PostLogoutRedirectUris = null;
return ValueTask.CompletedTask;
}
application.PostLogoutRedirectUris = uris.ToArray();
application.PostLogoutRedirectUris = uris is { IsDefaultOrEmpty: false } ? [.. uris] : null;
return ValueTask.CompletedTask;
}
@ -643,14 +629,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{
ArgumentNullException.ThrowIfNull(application);
if (uris.IsDefaultOrEmpty)
{
application.RedirectUris = null;
return ValueTask.CompletedTask;
}
application.RedirectUris = uris.ToArray();
application.RedirectUris = uris is { IsDefaultOrEmpty: false } ? [.. uris] : null;
return ValueTask.CompletedTask;
}
@ -660,14 +639,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{
ArgumentNullException.ThrowIfNull(application);
if (requirements.IsDefaultOrEmpty)
{
application.Requirements = null;
return ValueTask.CompletedTask;
}
application.Requirements = requirements.ToArray();
application.Requirements = requirements is { IsDefaultOrEmpty: false } ? [.. requirements] : null;
return ValueTask.CompletedTask;
}
@ -678,7 +650,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
{
ArgumentNullException.ThrowIfNull(application);
application.Settings = settings;
application.Settings = settings is { IsEmpty: false } ? settings : null;
return ValueTask.CompletedTask;
}

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

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

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

@ -332,7 +332,7 @@ public class OpenIddictEntityFrameworkCoreResourceStore<
{
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)
: null;
@ -355,7 +355,7 @@ public class OpenIddictEntityFrameworkCoreResourceStore<
{
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)
: null;

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

@ -360,7 +360,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
{
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)
: null;
@ -383,7 +383,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
{
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)
: null;
@ -416,14 +416,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
{
ArgumentNullException.ThrowIfNull(scope);
if (resources.IsDefaultOrEmpty)
{
scope.Resources = null;
return ValueTask.CompletedTask;
}
scope.Resources = resources.ToArray();
scope.Resources = resources is { IsDefaultOrEmpty: false } ? [.. resources] : null;
return ValueTask.CompletedTask;
}

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

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

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

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

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

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

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

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

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

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

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

@ -363,7 +363,7 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable
from parameter in parameters
group parameter by parameter.Key into grouping
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))
@ -406,7 +406,7 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable
from parameter in parameters
group parameter by parameter.Key into grouping
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))
@ -445,7 +445,7 @@ public class OpenIddictServerIntegrationTestClient : IAsyncDisposable
from parameter in parameters
group parameter by parameter.Key into grouping
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();

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

@ -363,7 +363,7 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable
from parameter in parameters
group parameter by parameter.Key into grouping
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))
@ -406,7 +406,7 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable
from parameter in parameters
group parameter by parameter.Key into grouping
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))
@ -445,7 +445,7 @@ public class OpenIddictValidationIntegrationTestClient : IAsyncDisposable
from parameter in parameters
group parameter by parameter.Key into grouping
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();

Loading…
Cancel
Save