< Summary

Information
Class: ProjectTemplate.Infrastructure.Data.ExternalLogins.EfCoreExternalLoginAccountResolver
Assembly: ProjectTemplate.Infrastructure
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/ExternalLogins/EfCoreExternalLoginAccountResolver.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 72
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
FindByProviderUserIdAsync()100%44100%
FindByLocalUserIdAsync()100%22100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/ExternalLogins/EfCoreExternalLoginAccountResolver.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using ProjectTemplate.Infrastructure.Data.Entities;
 3
 4namespace ProjectTemplate.Infrastructure.Data.ExternalLogins;
 5
 6/// <summary>
 7/// EF Core implementation of <see cref="IExternalLoginAccountResolver" />.
 8/// </summary>
 229public sealed class EfCoreExternalLoginAccountResolver(ApplicationDbContext dbContext)
 10    : IExternalLoginAccountResolver
 11{
 2212    private readonly ApplicationDbContext _dbContext = dbContext;
 13
 14    /// <summary>
 15    /// Finds an external login account by the provider name and provider user ID.
 16    /// </summary>
 17    /// <param name="providerName">Provider name. This value is matched case-insensitively after trimming and Unicode no
 18    /// <param name="providerUserId">Provider user ID. This value is trimmed and Unicode-normalized, but remains case-se
 19    /// <param name="cancellationToken">Cancellation token to cancel the operation if needed.</param>
 20    /// <returns>Returns the matching <see cref="ExternalLoginAccount" /> if found; otherwise, returns null.</returns>
 21    public async Task<ExternalLoginAccount?> FindByProviderUserIdAsync(
 22        string providerName,
 23        string providerUserId,
 24        CancellationToken cancellationToken = default)
 25    {
 1826        if (string.IsNullOrWhiteSpace(providerName) || string.IsNullOrWhiteSpace(providerUserId))
 27        {
 828            return null;
 29        }
 30
 1031        string normalizedProviderName =
 1032            PersistenceStringComparisonNormalizer.NormalizeRequiredLookupValue(providerName);
 33
 1034        string normalizedProviderUserId =
 1035            PersistenceStringComparisonNormalizer.NormalizeRequiredDisplayValue(providerUserId);
 36
 1037        return await _dbContext.ExternalLoginAccounts
 1038            .AsNoTracking()
 1039            .FirstOrDefaultAsync(
 1040                x => x.NormalizedProviderName == normalizedProviderName
 1041                    && x.ProviderUserId == normalizedProviderUserId,
 1042                cancellationToken)
 1043            .ConfigureAwait(false);
 1844    }
 45
 46    /// <summary>
 47    /// Finds all external login accounts associated with a specific local user ID.
 48    /// </summary>
 49    /// <param name="localUserId">
 50    /// Local user ID (the unique identifier for the user in the local system). If this value is Guid.Empty, an empty li
 51    /// </param>
 52    /// <param name="cancellationToken">
 53    /// Cancellation token to cancel the operation if needed.
 54    /// </param>
 55    /// <returns>
 56    /// Returns a list of <see cref="ExternalLoginAccount" /> instances associated with the specified local user ID. If 
 57    /// </returns>
 58    public async Task<IReadOnlyList<ExternalLoginAccount>> FindByLocalUserIdAsync(
 59        Guid localUserId,
 60        CancellationToken cancellationToken = default)
 61    {
 462        return localUserId == Guid.Empty
 463            ? []
 464            : (IReadOnlyList<ExternalLoginAccount>)await _dbContext.ExternalLoginAccounts
 465            .AsNoTracking()
 466            .Where(x => x.LocalUserId == localUserId)
 467            .OrderBy(x => x.ProviderName)
 468            .ThenBy(x => x.ProviderUserId)
 469            .ToListAsync(cancellationToken)
 470            .ConfigureAwait(false);
 471    }
 72}