From 2c5e9c6a69f7103be29bebae4821b241d50af9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 6 Oct 2019 17:47:25 +0200 Subject: [PATCH] Use Enumerable.Contains() instead of ImmutableArray.Contains() and add missing cancellation tokens --- .../Stores/OpenIddictApplicationStore.cs | 38 +++++++++---------- .../Stores/OpenIddictAuthorizationStore.cs | 28 +++++++------- .../Stores/OpenIddictScopeStore.cs | 38 ++++++++++--------- .../Stores/OpenIddictTokenStore.cs | 34 ++++++++--------- .../Stores/OpenIddictApplicationStore.cs | 22 +++++------ .../Stores/OpenIddictAuthorizationStore.cs | 22 +++++------ .../Stores/OpenIddictScopeStore.cs | 22 ++++++----- .../Stores/OpenIddictTokenStore.cs | 16 ++++---- .../Stores/OpenIddictApplicationStore.cs | 4 +- .../Stores/OpenIddictAuthorizationStore.cs | 4 +- .../Stores/OpenIddictScopeStore.cs | 8 ++-- .../Stores/OpenIddictTokenStore.cs | 4 +- .../Stores/OpenIddictApplicationStore.cs | 6 +-- .../Stores/OpenIddictAuthorizationStore.cs | 2 +- .../Stores/OpenIddictScopeStore.cs | 6 ++- 15 files changed, 131 insertions(+), 123 deletions(-) diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs index a83d134f..f48f5b92 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs @@ -106,8 +106,8 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of applications in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Applications.LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Applications.LongCountAsync(cancellationToken); /// /// Determines the number of applications that match the specified query. @@ -119,14 +119,14 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of applications that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Applications).LongCountAsync()); + return await query(Applications).LongCountAsync(cancellationToken); } /// @@ -135,7 +135,7 @@ namespace OpenIddict.EntityFramework /// The application to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -144,7 +144,7 @@ namespace OpenIddict.EntityFramework Applications.Add(application); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -233,7 +233,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the client application corresponding to the identifier. /// - public virtual ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -242,9 +242,9 @@ namespace OpenIddict.EntityFramework var key = ConvertIdentifierFromString(identifier); - return new ValueTask((from application in Applications - where application.Id.Equals(key) - select application).FirstOrDefaultAsync()); + return await (from application in Applications + where application.Id.Equals(key) + select application).FirstOrDefaultAsync(cancellationToken); } /// @@ -256,16 +256,16 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the client application corresponding to the identifier. /// - public virtual ValueTask FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); } - return new ValueTask((from application in Applications - where application.ClientId == identifier - select application).FirstOrDefaultAsync()); + return await (from application in Applications + where application.ClientId == identifier + select application).FirstOrDefaultAsync(cancellationToken); } /// @@ -330,7 +330,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the first element returned when executing the query. /// - public virtual ValueTask GetAsync( + public virtual async ValueTask GetAsync( [NotNull] Func, TState, IQueryable> query, [CanBeNull] TState state, CancellationToken cancellationToken) { @@ -339,7 +339,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Applications, state).FirstOrDefaultAsync(cancellationToken)); + return await query(Applications, state).FirstOrDefaultAsync(cancellationToken); } /// @@ -488,7 +488,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.Permissions) - .Select(element => (string) element) + .Select(permission => (string) permission) .ToImmutableArray(); }); @@ -525,7 +525,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.PostLogoutRedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); @@ -597,7 +597,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.RedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs index 05795c98..ea3019b5 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs @@ -106,8 +106,8 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of authorizations in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Authorizations.LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Authorizations.LongCountAsync(cancellationToken); /// /// Determines the number of authorizations that match the specified query. @@ -119,14 +119,14 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of authorizations that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Authorizations).LongCountAsync()); + return await query(Authorizations).LongCountAsync(cancellationToken); } /// @@ -135,7 +135,7 @@ namespace OpenIddict.EntityFramework /// The authorization to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { @@ -144,7 +144,7 @@ namespace OpenIddict.EntityFramework Authorizations.Add(authorization); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -366,7 +366,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the authorization corresponding to the identifier. /// - public virtual ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -375,9 +375,9 @@ namespace OpenIddict.EntityFramework var key = ConvertIdentifierFromString(identifier); - return new ValueTask((from authorization in Authorizations.Include(authorization => authorization.Application) - where authorization.Id.Equals(key) - select authorization).FirstOrDefaultAsync(cancellationToken)); + return await (from authorization in Authorizations.Include(authorization => authorization.Application) + where authorization.Id.Equals(key) + select authorization).FirstOrDefaultAsync(cancellationToken); } /// @@ -447,7 +447,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the first element returned when executing the query. /// - public virtual ValueTask GetAsync( + public virtual async ValueTask GetAsync( [NotNull] Func, TState, IQueryable> query, [CanBeNull] TState state, CancellationToken cancellationToken) { @@ -456,8 +456,8 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query( - Authorizations.Include(authorization => authorization.Application), state).FirstOrDefaultAsync(cancellationToken)); + return await query( + Authorizations.Include(authorization => authorization.Application), state).FirstOrDefaultAsync(cancellationToken); } /// @@ -544,7 +544,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(authorization.Scopes) - .Select(element => (string) element) + .Select(scope => (string) scope) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs index 8619b6d0..00b01b95 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs @@ -89,8 +89,8 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of scopes in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Scopes.LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Scopes.LongCountAsync(cancellationToken); /// /// Determines the number of scopes that match the specified query. @@ -102,14 +102,14 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of scopes that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Scopes).LongCountAsync()); + return await query(Scopes).LongCountAsync(cancellationToken); } /// @@ -118,7 +118,7 @@ namespace OpenIddict.EntityFramework /// The scope to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { @@ -127,7 +127,7 @@ namespace OpenIddict.EntityFramework Scopes.Add(scope); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -168,7 +168,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the scope corresponding to the identifier. /// - public virtual ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -177,9 +177,9 @@ namespace OpenIddict.EntityFramework var key = ConvertIdentifierFromString(identifier); - return new ValueTask((from scope in Scopes - where scope.Id.Equals(key) - select scope).FirstOrDefaultAsync(cancellationToken)); + return await (from scope in Scopes + where scope.Id.Equals(key) + select scope).FirstOrDefaultAsync(cancellationToken); } /// @@ -191,16 +191,16 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the scope corresponding to the specified name. /// - public virtual ValueTask FindByNameAsync([NotNull] string name, CancellationToken cancellationToken) + public virtual async ValueTask FindByNameAsync([NotNull] string name, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("The scope name cannot be null or empty.", nameof(name)); } - return new ValueTask((from scope in Scopes - where scope.Name == name - select scope).FirstOrDefaultAsync(cancellationToken)); + return await (from scope in Scopes + where scope.Name == name + select scope).FirstOrDefaultAsync(cancellationToken); } /// @@ -217,8 +217,10 @@ namespace OpenIddict.EntityFramework throw new ArgumentException("Scope names cannot be null or empty.", nameof(names)); } + // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure + // ImmutableArray.Contains() (which is not fully supported by Entity Framework 6.x) is not used instead. return (from scope in Scopes - where names.Contains(scope.Name) + where Enumerable.Contains(names, scope.Name) select scope).AsAsyncEnumerable(cancellationToken); } @@ -258,7 +260,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the first element returned when executing the query. /// - public virtual ValueTask GetAsync( + public virtual async ValueTask GetAsync( [NotNull] Func, TState, IQueryable> query, [CanBeNull] TState state, CancellationToken cancellationToken) { @@ -267,7 +269,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Scopes, state).FirstOrDefaultAsync(cancellationToken)); + return await query(Scopes, state).FirstOrDefaultAsync(cancellationToken); } /// @@ -411,7 +413,7 @@ namespace OpenIddict.EntityFramework .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(scope.Resources) - .Select(element => (string) element) + .Select(resource => (string) resource) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs index 57297d2f..914fb14f 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs @@ -106,8 +106,8 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of applications in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Tokens.LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Tokens.LongCountAsync(cancellationToken); /// /// Determines the number of tokens that match the specified query. @@ -119,14 +119,14 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of tokens that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Tokens).LongCountAsync()); + return await query(Tokens).LongCountAsync(cancellationToken); } /// @@ -135,7 +135,7 @@ namespace OpenIddict.EntityFramework /// The token to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -144,7 +144,7 @@ namespace OpenIddict.EntityFramework Tokens.Add(token); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -338,7 +338,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the token corresponding to the unique identifier. /// - public virtual ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { @@ -347,9 +347,9 @@ namespace OpenIddict.EntityFramework var key = ConvertIdentifierFromString(identifier); - return new ValueTask((from token in Tokens.Include(token => token.Application).Include(token => token.Authorization) - where token.Id.Equals(key) - select token).FirstOrDefaultAsync(cancellationToken)); + return await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization) + where token.Id.Equals(key) + select token).FirstOrDefaultAsync(cancellationToken); } /// @@ -362,16 +362,16 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the tokens corresponding to the specified reference identifier. /// - public virtual ValueTask FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken) + public virtual async ValueTask FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(identifier)) { throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier)); } - return new ValueTask((from token in Tokens.Include(token => token.Application).Include(token => token.Authorization) - where token.ReferenceId == identifier - select token).FirstOrDefaultAsync(cancellationToken)); + return await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization) + where token.ReferenceId == identifier + select token).FirstOrDefaultAsync(cancellationToken); } /// @@ -440,7 +440,7 @@ namespace OpenIddict.EntityFramework /// A that can be used to monitor the asynchronous operation, /// whose result returns the first element returned when executing the query. /// - public virtual ValueTask GetAsync( + public virtual async ValueTask GetAsync( [NotNull] Func, TState, IQueryable> query, [CanBeNull] TState state, CancellationToken cancellationToken) { @@ -449,9 +449,9 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query( + return await query( Tokens.Include(token => token.Application) - .Include(token => token.Authorization), state).FirstOrDefaultAsync(cancellationToken)); + .Include(token => token.Authorization), state).FirstOrDefaultAsync(cancellationToken); } /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs index fcc8e467..fa1e2b7a 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs @@ -127,8 +127,8 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of applications in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Applications.AsQueryable().LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Applications.AsQueryable().LongCountAsync(cancellationToken); /// /// Determines the number of applications that match the specified query. @@ -140,14 +140,14 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of applications that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Applications).LongCountAsync()); + return await query(Applications).LongCountAsync(cancellationToken); } /// @@ -156,7 +156,7 @@ namespace OpenIddict.EntityFrameworkCore /// The application to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken) { if (application == null) { @@ -165,7 +165,7 @@ namespace OpenIddict.EntityFrameworkCore Context.Add(application); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -377,7 +377,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the first element returned when executing the query. /// - public virtual ValueTask GetAsync( + public virtual async ValueTask GetAsync( [NotNull] Func, TState, IQueryable> query, [CanBeNull] TState state, CancellationToken cancellationToken) { @@ -386,7 +386,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Applications.AsTracking(), state).FirstOrDefaultAsync(cancellationToken)); + return await query(Applications.AsTracking(), state).FirstOrDefaultAsync(cancellationToken); } /// @@ -535,7 +535,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.Permissions) - .Select(element => (string) element) + .Select(permission => (string) permission) .ToImmutableArray(); }); @@ -572,7 +572,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.PostLogoutRedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); @@ -644,7 +644,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.RedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs index 662c42b8..118e65ec 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs @@ -127,8 +127,8 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of authorizations in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Authorizations.AsQueryable().LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Authorizations.AsQueryable().LongCountAsync(cancellationToken); /// /// Determines the number of authorizations that match the specified query. @@ -140,14 +140,14 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of authorizations that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Authorizations).LongCountAsync()); + return await query(Authorizations).LongCountAsync(cancellationToken); } /// @@ -156,7 +156,7 @@ namespace OpenIddict.EntityFrameworkCore /// The authorization to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { @@ -165,7 +165,7 @@ namespace OpenIddict.EntityFrameworkCore Context.Add(authorization); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -500,7 +500,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the first element returned when executing the query. /// - public virtual ValueTask GetAsync( + public virtual async ValueTask GetAsync( [NotNull] Func, TState, IQueryable> query, [CanBeNull] TState state, CancellationToken cancellationToken) { @@ -509,9 +509,9 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query( + return await query( Authorizations.Include(authorization => authorization.Application) - .AsTracking(), state).FirstOrDefaultAsync(cancellationToken)); + .AsTracking(), state).FirstOrDefaultAsync(cancellationToken); } /// @@ -598,7 +598,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(authorization.Scopes) - .Select(element => (string) element) + .Select(scope => (string) scope) .ToImmutableArray(); }); @@ -853,7 +853,7 @@ namespace OpenIddict.EntityFrameworkCore // Warning: FindAsync() is deliberately not used to work around a breaking change introduced // in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned). var application = await Applications.AsQueryable() - .FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken); + .FirstOrDefaultAsync(application => application.Id.Equals(key), cancellationToken); if (application == null) { diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs index 27991a20..54205bf6 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs @@ -106,8 +106,8 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of scopes in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Scopes.AsQueryable().LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Scopes.AsQueryable().LongCountAsync(cancellationToken); /// /// Determines the number of scopes that match the specified query. @@ -119,14 +119,14 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of scopes that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Scopes).LongCountAsync()); + return await query(Scopes).LongCountAsync(cancellationToken); } /// @@ -135,7 +135,7 @@ namespace OpenIddict.EntityFrameworkCore /// The scope to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken) { if (scope == null) { @@ -144,7 +144,7 @@ namespace OpenIddict.EntityFrameworkCore Scopes.Add(scope); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -234,8 +234,10 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentException("Scope names cannot be null or empty.", nameof(names)); } + // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure + // ImmutableArray.Contains() (which is not fully supported by Entity Framework Core) is not used instead. return (from scope in Scopes.AsTracking() - where names.Contains(scope.Name) + where Enumerable.Contains(names, scope.Name) select scope).AsAsyncEnumerable(); } @@ -273,7 +275,7 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the first element returned when executing the query. /// - public virtual ValueTask GetAsync( + public virtual async ValueTask GetAsync( [NotNull] Func, TState, IQueryable> query, [CanBeNull] TState state, CancellationToken cancellationToken) { @@ -282,7 +284,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Scopes.AsTracking(), state).FirstOrDefaultAsync(cancellationToken)); + return await query(Scopes.AsTracking(), state).FirstOrDefaultAsync(cancellationToken); } /// @@ -426,7 +428,7 @@ namespace OpenIddict.EntityFrameworkCore .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(scope.Resources) - .Select(element => (string) element) + .Select(resource => (string) resource) .ToImmutableArray(); }); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs index 2d65a32d..6c357d28 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs @@ -126,8 +126,8 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of applications in the database. /// - public virtual ValueTask CountAsync(CancellationToken cancellationToken) - => new ValueTask(Tokens.AsQueryable().LongCountAsync()); + public virtual async ValueTask CountAsync(CancellationToken cancellationToken) + => await Tokens.AsQueryable().LongCountAsync(cancellationToken); /// /// Determines the number of tokens that match the specified query. @@ -139,14 +139,14 @@ namespace OpenIddict.EntityFrameworkCore /// A that can be used to monitor the asynchronous operation, /// whose result returns the number of tokens that match the specified query. /// - public virtual ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) + public virtual async ValueTask CountAsync([NotNull] Func, IQueryable> query, CancellationToken cancellationToken) { if (query == null) { throw new ArgumentNullException(nameof(query)); } - return new ValueTask(query(Tokens).LongCountAsync()); + return await query(Tokens).LongCountAsync(cancellationToken); } /// @@ -155,7 +155,7 @@ namespace OpenIddict.EntityFrameworkCore /// The token to create. /// The that can be used to abort the operation. /// A that can be used to monitor the asynchronous operation. - public virtual ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken) + public virtual async ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken) { if (token == null) { @@ -164,7 +164,7 @@ namespace OpenIddict.EntityFrameworkCore Context.Add(token); - return new ValueTask(Context.SaveChangesAsync(cancellationToken)); + await Context.SaveChangesAsync(cancellationToken); } /// @@ -914,7 +914,7 @@ namespace OpenIddict.EntityFrameworkCore // Warning: FindAsync() is deliberately not used to work around a breaking change introduced // in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned). var application = await Applications.AsQueryable() - .FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken); + .FirstOrDefaultAsync(application => application.Id.Equals(key), cancellationToken); if (application == null) { @@ -966,7 +966,7 @@ namespace OpenIddict.EntityFrameworkCore // Warning: FindAsync() is deliberately not used to work around a breaking change introduced // in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned). var authorization = await Authorizations.AsQueryable() - .FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken); + .FirstOrDefaultAsync(authorization => authorization.Id.Equals(key), cancellationToken); if (authorization == null) { diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs index 03c604b7..b8dbbbe6 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs @@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs index b5bc7eb1..381a3e52 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs @@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs index 62d2dfbe..3c67375e 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs @@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } /// @@ -200,7 +200,9 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName); - await foreach (var scope in collection.Find(scope => names.Contains(scope.Name)).ToAsyncEnumerable(cancellationToken)) + // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure + // ImmutableArray.Contains() (which is not fully supported by MongoDB) is not used instead. + await foreach (var scope in collection.Find(scope => Enumerable.Contains(names, scope.Name)).ToAsyncEnumerable(cancellationToken)) { yield return scope; } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs index 60471335..d0aaef0d 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs @@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); - return await collection.CountDocumentsAsync(FilterDefinition.Empty); + return await collection.CountDocumentsAsync(FilterDefinition.Empty, null, cancellationToken); } /// @@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb var database = await Context.GetDatabaseAsync(cancellationToken); var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName); - return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(); + return await ((IMongoQueryable) query(collection.AsQueryable())).LongCountAsync(cancellationToken); } /// diff --git a/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs index 2f60bf1b..e162e030 100644 --- a/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs @@ -475,7 +475,7 @@ namespace OpenIddict.NHibernate .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.Permissions) - .Select(element => (string) element) + .Select(permission => (string) permission) .ToImmutableArray(); }); @@ -512,7 +512,7 @@ namespace OpenIddict.NHibernate .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.PostLogoutRedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); @@ -573,7 +573,7 @@ namespace OpenIddict.NHibernate .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(application.RedirectUris) - .Select(element => (string) element) + .Select(address => (string) address) .ToImmutableArray(); }); diff --git a/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs index 80e065db..023ffcca 100644 --- a/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs @@ -551,7 +551,7 @@ namespace OpenIddict.NHibernate .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(authorization.Scopes) - .Select(element => (string) element) + .Select(scope => (string) scope) .ToImmutableArray(); }); diff --git a/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs index 9b740cd6..1c0b3b39 100644 --- a/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs @@ -235,8 +235,10 @@ namespace OpenIddict.NHibernate { var session = await Context.GetSessionAsync(cancellationToken); + // Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure + // ImmutableArray.Contains() (which is not fully supported by NHibernate) is not used instead. await foreach (var scope in (from scope in session.Query() - where names.Contains(scope.Name) + where Enumerable.Contains(names, scope.Name) select scope).AsAsyncEnumerable(cancellationToken)) { yield return scope; @@ -433,7 +435,7 @@ namespace OpenIddict.NHibernate .SetSlidingExpiration(TimeSpan.FromMinutes(1)); return JArray.Parse(scope.Resources) - .Select(element => (string) element) + .Select(resource => (string) resource) .ToImmutableArray(); });