diff --git a/Directory.Build.props b/Directory.Build.props index 3323a0bcc..d42d2900e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -78,7 +78,7 @@ - + @@ -98,7 +98,7 @@ - + diff --git a/samples/Mvc.Client/Controllers/AuthenticationController.cs b/samples/Mvc.Client/Controllers/AuthenticationController.cs index 77d8db67c..b2602638f 100644 --- a/samples/Mvc.Client/Controllers/AuthenticationController.cs +++ b/samples/Mvc.Client/Controllers/AuthenticationController.cs @@ -19,7 +19,7 @@ public class AuthenticationController : Controller public async Task SignIn([FromForm] string provider) { // Note: the "provider" parameter corresponds to the external - // authentication provider choosen by the user agent. + // authentication provider chosen by the user agent. if (string.IsNullOrWhiteSpace(provider)) { return BadRequest(); diff --git a/samples/Mvc.Client/Startup.cs b/samples/Mvc.Client/Startup.cs index ead835315..5408ec6a9 100644 --- a/samples/Mvc.Client/Startup.cs +++ b/samples/Mvc.Client/Startup.cs @@ -9,18 +9,8 @@ namespace Mvc.Client; -public class Startup +public class Startup(IConfiguration configuration, IHostEnvironment hostingEnvironment) { - public Startup(IConfiguration configuration, IHostEnvironment hostingEnvironment) - { - Configuration = configuration; - HostingEnvironment = hostingEnvironment; - } - - public IConfiguration Configuration { get; } - - private IHostEnvironment HostingEnvironment { get; } - public void ConfigureServices(IServiceCollection services) { services.AddRouting(); @@ -38,21 +28,21 @@ public void ConfigureServices(IServiceCollection services) .AddGoogle(options => { - options.ClientId = Configuration["Google:ClientId"] ?? string.Empty; - options.ClientSecret = Configuration["Google:ClientSecret"] ?? string.Empty; + options.ClientId = configuration["Google:ClientId"] ?? string.Empty; + options.ClientSecret = configuration["Google:ClientSecret"] ?? string.Empty; }) .AddTwitter(options => { - options.ClientId = Configuration["Twitter:ClientId"] ?? string.Empty; - options.ClientSecret = Configuration["Twitter:ClientSecret"] ?? string.Empty; + options.ClientId = configuration["Twitter:ClientId"] ?? string.Empty; + options.ClientSecret = configuration["Twitter:ClientSecret"] ?? string.Empty; }) .AddGitHub(options => { - options.ClientId = Configuration["GitHub:ClientId"] ?? string.Empty; - options.ClientSecret = Configuration["GitHub:ClientSecret"] ?? string.Empty; - options.EnterpriseDomain = Configuration["GitHub:EnterpriseDomain"] ?? string.Empty; + options.ClientId = configuration["GitHub:ClientId"] ?? string.Empty; + options.ClientSecret = configuration["GitHub:ClientSecret"] ?? string.Empty; + options.EnterpriseDomain = configuration["GitHub:EnterpriseDomain"] ?? string.Empty; options.Scope.Add("user:email"); }) @@ -69,8 +59,8 @@ public void ConfigureServices(IServiceCollection services) .AddDropbox(options => { - options.ClientId = Configuration["Dropbox:ClientId"] ?? string.Empty; - options.ClientSecret = Configuration["Dropbox:ClientSecret"] ?? string.Empty; + options.ClientId = configuration["Dropbox:ClientId"] ?? string.Empty; + options.ClientSecret = configuration["Dropbox:ClientSecret"] ?? string.Empty; }); services.AddMvc(); @@ -78,7 +68,7 @@ public void ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app) { - if (HostingEnvironment.IsDevelopment()) + if (hostingEnvironment.IsDevelopment()) { IdentityModelEventSource.ShowPII = true; } diff --git a/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs b/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs index ecfa38fa1..6fe1c8775 100644 --- a/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.AdobeIO/AdobeIOAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs index 0ae459585..415219e28 100644 --- a/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Amazon/AmazonAuthenticationHandler.cs @@ -39,7 +39,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string endpoint = Options.UserInformationEndpoint; + var endpoint = Options.UserInformationEndpoint; if (Options.Fields.Count > 0) { diff --git a/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs b/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs index 0a8d02cb6..61909555c 100644 --- a/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.AmoCrm/AmoCrmAuthenticationHandler.cs @@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string endpoint = Options.UserInformationEndpoint; + var endpoint = Options.UserInformationEndpoint; using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs index f200eba29..50b3facb7 100644 --- a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs +++ b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationEvents.cs @@ -14,7 +14,7 @@ public class AppleAuthenticationEvents : OAuthEvents /// /// Gets or sets the delegate that is invoked when the method is invoked. /// - public Func OnGenerateClientSecret { get; set; } = async context => + public Func OnGenerateClientSecret { get; set; } = static async context => { context.Options.ClientSecret = await context.Options.ClientSecretGenerator.GenerateAsync(context); }; @@ -22,7 +22,7 @@ public class AppleAuthenticationEvents : OAuthEvents /// /// Gets or sets the delegate that is invoked when the method is invoked. /// - public Func OnValidateIdToken { get; set; } = async context => + public Func OnValidateIdToken { get; set; } = static async context => { await context.Options.TokenValidator.ValidateAsync(context); }; diff --git a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs index 3946881d3..fb26c159e 100644 --- a/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs @@ -19,22 +19,14 @@ namespace AspNet.Security.OAuth.Apple; /// /// Defines a handler for authentication using Apple. /// -public partial class AppleAuthenticationHandler : OAuthHandler +/// The authentication options. +/// The logger to use. +/// The URL encoder to use. +public partial class AppleAuthenticationHandler( + [NotNull] IOptionsMonitor options, + [NotNull] ILoggerFactory logger, + [NotNull] UrlEncoder encoder) : OAuthHandler(options, logger, encoder) { - /// - /// Initializes a new instance of the class. - /// - /// The authentication options. - /// The logger to use. - /// The URL encoder to use. - public AppleAuthenticationHandler( - [NotNull] IOptionsMonitor options, - [NotNull] ILoggerFactory logger, - [NotNull] UrlEncoder encoder) - : base(options, logger, encoder) - { - } - /// /// The handler calls methods on the events which give the application control at certain points where processing is occurring. /// If it is not provided a default instance is supplied which does nothing when the methods are called. @@ -133,7 +125,7 @@ protected virtual IEnumerable ExtractClaimsFromToken([NotNull] string tok var claims = new List(securityToken.Claims) { - new Claim(ClaimTypes.NameIdentifier, securityToken.Subject, ClaimValueTypes.String, ClaimsIssuer), + new(ClaimTypes.NameIdentifier, securityToken.Subject, ClaimValueTypes.String, ClaimsIssuer), }; var emailClaim = claims.Find((p) => string.Equals(p.Type, "email", StringComparison.Ordinal)); @@ -283,19 +275,19 @@ private async Task HandleRemoteAuthenticateAsync( if (Options.SaveTokens) { - var authTokens = new List() - { - new AuthenticationToken() { Name = "access_token", Value = tokens.AccessToken }, - }; + List authTokens = + [ + new() { Name = "access_token", Value = tokens.AccessToken }, + ]; if (!string.IsNullOrEmpty(tokens.RefreshToken)) { - authTokens.Add(new AuthenticationToken() { Name = "refresh_token", Value = tokens.RefreshToken }); + authTokens.Add(new() { Name = "refresh_token", Value = tokens.RefreshToken }); } if (!string.IsNullOrEmpty(tokens.TokenType)) { - authTokens.Add(new AuthenticationToken() { Name = "token_type", Value = tokens.TokenType }); + authTokens.Add(new() { Name = "token_type", Value = tokens.TokenType }); } if (!string.IsNullOrEmpty(tokens.ExpiresIn)) @@ -306,7 +298,7 @@ private async Task HandleRemoteAuthenticateAsync( // https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx var expiresAt = TimeProvider.GetUtcNow().AddSeconds(value); - authTokens.Add(new AuthenticationToken() + authTokens.Add(new() { Name = "expires_at", Value = expiresAt.ToString("o", CultureInfo.InvariantCulture), @@ -318,7 +310,7 @@ private async Task HandleRemoteAuthenticateAsync( if (!string.IsNullOrEmpty(idToken)) { - authTokens.Add(new AuthenticationToken() { Name = "id_token", Value = idToken }); + authTokens.Add(new() { Name = "id_token", Value = idToken }); } properties.StoreTokens(authTokens); diff --git a/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs b/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs index 86bba117b..18e4c2b84 100644 --- a/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs +++ b/src/AspNet.Security.OAuth.Apple/AppleEmailClaimAction.cs @@ -10,16 +10,8 @@ namespace AspNet.Security.OAuth.Apple; -internal sealed class AppleEmailClaimAction : ClaimAction +internal sealed class AppleEmailClaimAction(AppleAuthenticationOptions options) : ClaimAction(ClaimTypes.Email, ClaimValueTypes.String) { - private readonly AppleAuthenticationOptions _options; - - internal AppleEmailClaimAction(AppleAuthenticationOptions options) - : base(ClaimTypes.Email, ClaimValueTypes.String) - { - _options = options; - } - public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer) { if (!identity.HasClaim((p) => string.Equals(p.Type, ClaimType, StringComparison.OrdinalIgnoreCase))) @@ -28,7 +20,7 @@ public override void Run(JsonElement userData, ClaimsIdentity identity, string i if (!string.IsNullOrEmpty(emailClaim?.Value)) { - identity.AddClaim(new Claim(ClaimType, emailClaim.Value, ValueType, _options.ClaimsIssuer)); + identity.AddClaim(new Claim(ClaimType, emailClaim.Value, ValueType, options.ClaimsIssuer)); } } } diff --git a/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs b/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs index ddaf0853b..1a95cfd12 100644 --- a/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs +++ b/src/AspNet.Security.OAuth.Apple/AppleGenerateClientSecretContext.cs @@ -11,16 +11,12 @@ namespace AspNet.Security.OAuth.Apple; /// /// Contains information about the current request. /// -public class AppleGenerateClientSecretContext : BaseContext +/// The HTTP context. +/// The authentication scheme. +/// The authentication options associated with the scheme. +public class AppleGenerateClientSecretContext( + HttpContext context, + AuthenticationScheme scheme, + AppleAuthenticationOptions options) : BaseContext(context, scheme, options) { - /// - /// Creates a new instance of the class. - /// - /// The HTTP context. - /// The authentication scheme. - /// The authentication options associated with the scheme. - public AppleGenerateClientSecretContext(HttpContext context, AuthenticationScheme scheme, AppleAuthenticationOptions options) - : base(context, scheme, options) - { - } } diff --git a/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs b/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs index 936bc1e1d..140d48f0b 100644 --- a/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs +++ b/src/AspNet.Security.OAuth.Apple/ApplePostConfigureOptions.cs @@ -19,27 +19,15 @@ namespace AspNet.Security.OAuth.Apple; /// /// A class used to setup defaults for all . /// -public class ApplePostConfigureOptions : IPostConfigureOptions +/// The to use. +/// The to use. +/// The to use. +public class ApplePostConfigureOptions( + IMemoryCache cache, + TimeProvider timeProvider, + ILoggerFactory loggerFactory) : IPostConfigureOptions { - private readonly IMemoryCache _cache; - private readonly TimeProvider _timeProvider; - private readonly ILoggerFactory _loggerFactory; - - /// - /// Initializes a new instance of the class. - /// - /// The to use. - /// The to use. - /// The to use. - public ApplePostConfigureOptions( - IMemoryCache cache, - TimeProvider timeProvider, - ILoggerFactory loggerFactory) - { - _cache = cache; - _timeProvider = timeProvider; - _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance; - } + private readonly ILoggerFactory _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance; /// public void PostConfigure( @@ -51,8 +39,8 @@ public void PostConfigure( var cryptoProviderFactory = new CryptoProviderFactory() { CacheSignatureProviders = false }; options.ClientSecretGenerator ??= new DefaultAppleClientSecretGenerator( - _cache, - _timeProvider, + cache, + timeProvider, cryptoProviderFactory, _loggerFactory.CreateLogger()); diff --git a/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs b/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs index 321e82739..f0dbb2734 100644 --- a/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs +++ b/src/AspNet.Security.OAuth.Apple/AppleValidateIdTokenContext.cs @@ -11,23 +11,18 @@ namespace AspNet.Security.OAuth.Apple; /// /// Contains information about the ID token to validate. /// -public class AppleValidateIdTokenContext : BaseContext +/// The HTTP context. +/// The authentication scheme. +/// The authentication options associated with the scheme. +/// The Apple ID token for the user to validate. +public class AppleValidateIdTokenContext( + HttpContext context, + AuthenticationScheme scheme, + AppleAuthenticationOptions options, + string idToken) : BaseContext(context, scheme, options) { - /// - /// Creates a new instance of the class. - /// - /// The HTTP context. - /// The authentication scheme. - /// The authentication options associated with the scheme. - /// The Apple ID token for the user to validate. - public AppleValidateIdTokenContext(HttpContext context, AuthenticationScheme scheme, AppleAuthenticationOptions options, string idToken) - : base(context, scheme, options) - { - IdToken = idToken; - } - /// /// Gets the Apple ID token. /// - public string IdToken { get; } + public string IdToken { get; } = idToken; } diff --git a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs index 8c0a4a394..b6c756717 100644 --- a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs +++ b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleClientSecretGenerator.cs @@ -12,31 +12,18 @@ namespace AspNet.Security.OAuth.Apple.Internal; -internal sealed partial class DefaultAppleClientSecretGenerator : AppleClientSecretGenerator +internal sealed partial class DefaultAppleClientSecretGenerator( + [NotNull] IMemoryCache cache, + [NotNull] TimeProvider timeProvider, + [NotNull] CryptoProviderFactory cryptoProviderFactory, + [NotNull] ILogger logger) : AppleClientSecretGenerator { - private readonly IMemoryCache _cache; - private readonly TimeProvider _timeProvider; - private readonly ILogger _logger; - private readonly CryptoProviderFactory _cryptoProviderFactory; - - public DefaultAppleClientSecretGenerator( - [NotNull] IMemoryCache cache, - [NotNull] TimeProvider clock, - [NotNull] CryptoProviderFactory cryptoProviderFactory, - [NotNull] ILogger logger) - { - _cache = cache; - _timeProvider = clock; - _cryptoProviderFactory = cryptoProviderFactory; - _logger = logger; - } - /// public override async Task GenerateAsync([NotNull] AppleGenerateClientSecretContext context) { var key = CreateCacheKey(context.Options); - var clientSecret = await _cache.GetOrCreateAsync(key, async (entry) => + var clientSecret = await cache.GetOrCreateAsync(key, async (entry) => { try { @@ -45,7 +32,7 @@ public override async Task GenerateAsync([NotNull] AppleGenerateClientSe } catch (Exception ex) { - Log.ClientSecretGenerationFailed(_logger, ex, context.Scheme.Name); + Log.ClientSecretGenerationFailed(logger, ex, context.Scheme.Name); throw; } }); @@ -70,10 +57,10 @@ private static string CreateCacheKey(AppleAuthenticationOptions options) private async Task<(string ClientSecret, DateTimeOffset ExpiresAt)> GenerateNewSecretAsync( [NotNull] AppleGenerateClientSecretContext context) { - var expiresAt = _timeProvider.GetUtcNow().Add(context.Options.ClientSecretExpiresAfter).UtcDateTime; + var expiresAt = timeProvider.GetUtcNow().Add(context.Options.ClientSecretExpiresAfter).UtcDateTime; var subject = new Claim("sub", context.Options.ClientId); - Log.GeneratingNewClientSecret(_logger, subject.Value, expiresAt); + Log.GeneratingNewClientSecret(logger, subject.Value, expiresAt); var tokenDescriptor = new SecurityTokenDescriptor() { @@ -93,7 +80,7 @@ private static string CreateCacheKey(AppleAuthenticationOptions options) clientSecret = context.Options.SecurityTokenHandler.CreateToken(tokenDescriptor); } - Log.GeneratedNewClientSecret(_logger, clientSecret); + Log.GeneratedNewClientSecret(logger, clientSecret); return (clientSecret, expiresAt); } @@ -122,7 +109,7 @@ private SigningCredentials CreateSigningCredentials(string keyId, ECDsa algorith // https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1302 return new SigningCredentials(key, SecurityAlgorithms.EcdsaSha256) { - CryptoProviderFactory = _cryptoProviderFactory, + CryptoProviderFactory = cryptoProviderFactory, }; } diff --git a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs index c4a79c641..179d3232a 100644 --- a/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs +++ b/src/AspNet.Security.OAuth.Apple/Internal/DefaultAppleIdTokenValidator.cs @@ -10,16 +10,9 @@ namespace AspNet.Security.OAuth.Apple.Internal; -internal sealed partial class DefaultAppleIdTokenValidator : AppleIdTokenValidator +internal sealed partial class DefaultAppleIdTokenValidator( + [NotNull] ILogger logger) : AppleIdTokenValidator { - private readonly ILogger _logger; - - public DefaultAppleIdTokenValidator( - [NotNull] ILogger logger) - { - _logger = logger; - } - public override async Task ValidateAsync([NotNull] AppleValidateIdTokenContext context) { if (context.Options.SecurityTokenHandler is null) @@ -58,8 +51,8 @@ public override async Task ValidateAsync([NotNull] AppleValidateIdTokenContext c } catch (Exception ex) { - Log.TokenValidationFailed(_logger, ex, validationParameters.ValidIssuer, validationParameters.ValidAudience); - Log.TokenInvalid(_logger, ex, context.IdToken); + Log.TokenValidationFailed(logger, ex, validationParameters.ValidIssuer, validationParameters.ValidAudience); + Log.TokenInvalid(logger, ex, context.IdToken); throw; } } diff --git a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs index ba6801431..5ca95ef3f 100644 --- a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs index 9ef9983af..5ba006d8e 100644 --- a/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs +++ b/src/AspNet.Security.OAuth.Baidu/BaiduAuthenticationOptions.cs @@ -29,7 +29,7 @@ public BaiduAuthenticationOptions() ClaimActions.MapCustomJson(BaiduAuthenticationConstants.Claims.Portrait, user => { - string? portrait = user.GetString("portrait"); + var portrait = user.GetString("portrait"); return string.IsNullOrWhiteSpace(portrait) ? null : $"https://tb.himg.baidu.com/sys/portrait/item/{WebUtility.UrlEncode(portrait)}"; diff --git a/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs b/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs index 4e02ea60f..66293ac46 100644 --- a/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.BattleNet/BattleNetAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs index 5fda22315..4a1ec4d87 100644 --- a/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Bitbucket/BitbucketAuthenticationHandler.cs @@ -51,7 +51,7 @@ protected override async Task CreateTicketAsync( !identity.HasClaim(claim => claim.Type == ClaimTypes.Email) && Options.Scope.Contains("email")) { - string? address = await GetEmailAsync(tokens); + var address = await GetEmailAsync(tokens); if (!string.IsNullOrEmpty(address)) { diff --git a/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs b/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs index c167ab4c4..f38cf494c 100644 --- a/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs +++ b/src/AspNet.Security.OAuth.Coinbase/CoinbaseAuthenticationExtensions.cs @@ -4,10 +4,7 @@ * for more information concerning the license and the contributors participating to this project. */ -using System; using AspNet.Security.OAuth.Coinbase; -using JetBrains.Annotations; -using Microsoft.AspNetCore.Authentication; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs b/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs index eec8a7bbc..51997775d 100644 --- a/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs +++ b/src/AspNet.Security.OAuth.Deezer/DeezerAuthenticationConstants.cs @@ -36,9 +36,9 @@ public static class Claims public static class Scopes { /// - /// Access users basic information - /// Includes name, firstname, profile picture only. - /// Default permission + /// Access users basic information. + /// Includes name, first name and profile picture only. + /// Default permission. /// public const string Identity = "basic_access"; diff --git a/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs b/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs index bdd4488fc..9b079eba4 100644 --- a/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.DigitalOcean/DigitalOceanAuthenticationHandler.cs @@ -4,7 +4,6 @@ * for more information concerning the license and the contributors participating to this project. */ -using System.Net; using System.Net.Http.Headers; using System.Security.Claims; using System.Text.Encodings.Web; diff --git a/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs index d9fd12737..369106ff2 100644 --- a/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Discord/DiscordAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override string BuildChallengeUrl( [NotNull] AuthenticationProperties properties, [NotNull] string redirectUri) { - string challengeUrl = base.BuildChallengeUrl(properties, redirectUri); + var challengeUrl = base.BuildChallengeUrl(properties, redirectUri); if (!string.IsNullOrEmpty(Options.Prompt)) { diff --git a/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs index 6cebf2380..c0df4fc32 100644 --- a/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Dropbox/DropboxAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override string BuildChallengeUrl( [NotNull] AuthenticationProperties properties, [NotNull] string redirectUri) { - string challengeUrl = base.BuildChallengeUrl(properties, redirectUri); + var challengeUrl = base.BuildChallengeUrl(properties, redirectUri); if (!string.IsNullOrEmpty(Options.AccessType)) { diff --git a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs index 89da20a99..c4f7a71f5 100644 --- a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlineAuthenticationHandler.cs @@ -34,7 +34,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string? accessToken = tokens.AccessToken; + var accessToken = tokens.AccessToken; if (string.IsNullOrWhiteSpace(accessToken)) { @@ -72,11 +72,12 @@ protected virtual IEnumerable ExtractClaimsFromToken([NotNull] string tok var nameClaim = ExtractClaim(securityToken, "name"); var expClaim = ExtractClaim(securityToken, "exp"); - var claims = new List(securityToken.Claims); - - claims.Add(new Claim(ClaimTypes.NameIdentifier, securityToken.Subject.Replace("CHARACTER:EVE:", string.Empty, StringComparison.OrdinalIgnoreCase), ClaimValueTypes.String, ClaimsIssuer)); - claims.Add(new Claim(ClaimTypes.Name, nameClaim.Value, ClaimValueTypes.String, ClaimsIssuer)); - claims.Add(new Claim(ClaimTypes.Expiration, UnixTimeStampToDateTime(expClaim.Value), ClaimValueTypes.DateTime, ClaimsIssuer)); + var claims = new List(securityToken.Claims) + { + new(ClaimTypes.NameIdentifier, securityToken.Subject.Replace("CHARACTER:EVE:", string.Empty, StringComparison.OrdinalIgnoreCase), ClaimValueTypes.String, ClaimsIssuer), + new(ClaimTypes.Name, nameClaim.Value, ClaimValueTypes.String, ClaimsIssuer), + new(ClaimTypes.Expiration, UnixTimeStampToDateTime(expClaim.Value), ClaimValueTypes.DateTime, ClaimsIssuer) + }; var scopes = claims.Where(x => string.Equals(x.Type, "scp", StringComparison.OrdinalIgnoreCase)).ToList(); @@ -96,23 +97,17 @@ protected virtual IEnumerable ExtractClaimsFromToken([NotNull] string tok private static Claim ExtractClaim([NotNull] JsonWebToken token, [NotNull] string claim) { var extractedClaim = token.Claims.FirstOrDefault(x => string.Equals(x.Type, claim, StringComparison.OrdinalIgnoreCase)); - - if (extractedClaim == null) - { - throw new AuthenticationFailureException($"The claim '{claim}' is missing from the EVEOnline JWT."); - } - - return extractedClaim; + return extractedClaim ?? throw new AuthenticationFailureException($"The claim '{claim}' is missing from the EVEOnline JWT."); } private static string UnixTimeStampToDateTime(string unixTimeStamp) { - if (!long.TryParse(unixTimeStamp, NumberStyles.Integer, CultureInfo.InvariantCulture, out long unixTime)) + if (!long.TryParse(unixTimeStamp, NumberStyles.Integer, CultureInfo.InvariantCulture, out var seconds)) { throw new AuthenticationFailureException($"The value {unixTimeStamp} of the 'exp' claim is not a valid 64-bit integer."); } - DateTimeOffset offset = DateTimeOffset.FromUnixTimeSeconds(unixTime); + DateTimeOffset offset = DateTimeOffset.FromUnixTimeSeconds(seconds); return offset.ToString("o", CultureInfo.InvariantCulture); } diff --git a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs index 620d40580..cd970e36b 100644 --- a/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs +++ b/src/AspNet.Security.OAuth.EVEOnline/EVEOnlinePostConfigureOptions.cs @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers * for more information concerning the license and the contributors participating to this project. @@ -19,9 +19,6 @@ public void PostConfigure( string? name, [NotNull] EVEOnlineAuthenticationOptions options) { - if (options.SecurityTokenHandler == null) - { - options.SecurityTokenHandler = new JsonWebTokenHandler(); - } + options.SecurityTokenHandler ??= new JsonWebTokenHandler(); } } diff --git a/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs b/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs index 7357da4ae..92ec25341 100644 --- a/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.GitHub/GitHubAuthenticationHandler.cs @@ -51,7 +51,7 @@ protected override async Task CreateTicketAsync( !identity.HasClaim(claim => claim.Type == ClaimTypes.Email) && Options.Scope.Contains("user:email")) { - string? address = await GetEmailAsync(tokens); + var address = await GetEmailAsync(tokens); if (!string.IsNullOrEmpty(address)) { diff --git a/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs index 404fe4f96..ca6fd45fc 100644 --- a/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Gitee/GiteeAuthenticationHandler.cs @@ -52,7 +52,7 @@ protected override async Task CreateTicketAsync( !identity.HasClaim(claim => claim.Type == ClaimTypes.Email) && Options.Scope.Contains("emails")) { - string? address = await GetEmailAsync(tokens); + var address = await GetEmailAsync(tokens); if (!string.IsNullOrEmpty(address)) { diff --git a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs index f34c4d526..02e76009e 100644 --- a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs +++ b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationExtensions.cs @@ -4,10 +4,7 @@ * for more information concerning the license and the contributors participating to this project. */ -using System; using AspNet.Security.OAuth.Instagram; -using JetBrains.Annotations; -using Microsoft.AspNetCore.Authentication; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs index f8681af8f..698945db7 100644 --- a/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Instagram/InstagramAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); if (Options.Fields.Count > 0) { diff --git a/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs b/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs index 8c1b4e3ce..5c50ef424 100644 --- a/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.JumpCloud/JumpCloudAuthenticationHandler.cs @@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string endpoint = Options.UserInformationEndpoint; + var endpoint = Options.UserInformationEndpoint; using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs b/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs index 4c81a148a..c63d532f1 100644 --- a/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs +++ b/src/AspNet.Security.OAuth.KakaoTalk/KakaoTalkAuthenticationOptions.cs @@ -28,7 +28,7 @@ public KakaoTalkAuthenticationOptions() ClaimActions.MapCustomJson(ClaimTypes.Name, user => { JsonElement property = user; - bool hasProperty = property.TryGetProperty("kakao_account", out property) + var hasProperty = property.TryGetProperty("kakao_account", out property) && property.TryGetProperty("profile", out property) && property.TryGetProperty("nickname", out property) && property.ValueKind == JsonValueKind.String; diff --git a/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs b/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs index c5641ffd5..bf70095a9 100644 --- a/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs +++ b/src/AspNet.Security.OAuth.Kloudless/KloudlessAuthenticationConstants.cs @@ -38,7 +38,7 @@ public static class Claims public static class Scopes { /// - /// Use all available services in kloudless + /// Use all available services in Kloudless. /// Default scope /// public const string Any = "any"; diff --git a/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs index 245b39a95..b25d6234a 100644 --- a/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs +++ b/src/AspNet.Security.OAuth.Kook/KookAuthenticationDefaults.cs @@ -12,12 +12,12 @@ namespace AspNet.Security.OAuth.Kook; public static class KookAuthenticationDefaults { /// - /// Default value for . + /// Default value for . /// public const string AuthenticationScheme = "Kook"; /// - /// Default value for . + /// Default value for . /// public static readonly string DisplayName = "Kook"; diff --git a/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs b/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs index d4fd1e57c..e5072f03c 100644 --- a/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationHandler.cs @@ -30,7 +30,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string requestUri = Options.UserInformationEndpoint; + var requestUri = Options.UserInformationEndpoint; var fields = Options.Fields .Where(f => !string.Equals(f, LinkedInAuthenticationConstants.EmailAddressField, StringComparison.OrdinalIgnoreCase)) .ToList(); @@ -61,7 +61,7 @@ protected override async Task CreateTicketAsync( if (!string.IsNullOrEmpty(Options.EmailAddressEndpoint) && Options.Fields.Contains(LinkedInAuthenticationConstants.EmailAddressField)) { - string? email = await GetEmailAsync(tokens); + var email = await GetEmailAsync(tokens); if (!string.IsNullOrEmpty(email)) { identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer)); diff --git a/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs b/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs index 08875dcef..2bce00dec 100644 --- a/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.MailRu/MailRuAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken!); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs index ae2da5a1a..59a4d3dd3 100644 --- a/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs +++ b/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationDefaults.cs @@ -12,12 +12,12 @@ namespace AspNet.Security.OAuth.Mixcloud; public static class MixcloudAuthenticationDefaults { /// - /// Default value for . + /// Default value for . /// public const string AuthenticationScheme = "Mixcloud"; /// - /// Default value for . + /// Default value for . /// public static readonly string DisplayName = "Mixcloud"; diff --git a/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs index 02524e763..0622334f6 100644 --- a/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Myob/MyobAuthenticationHandler.cs @@ -11,16 +11,11 @@ namespace AspNet.Security.OAuth.Myob; -public class MyobAuthenticationHandler : OAuthHandler +public class MyobAuthenticationHandler( + [NotNull] IOptionsMonitor options, + [NotNull] ILoggerFactory logger, + [NotNull] UrlEncoder encoder) : OAuthHandler(options, logger, encoder) { - public MyobAuthenticationHandler( - [NotNull] IOptionsMonitor options, - [NotNull] ILoggerFactory logger, - [NotNull] UrlEncoder encoder) - : base(options, logger, encoder) - { - } - protected override async Task CreateTicketAsync( [NotNull] ClaimsIdentity identity, [NotNull] AuthenticationProperties properties, diff --git a/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs index 8dd31819e..d529e464b 100644 --- a/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs +++ b/src/AspNet.Security.OAuth.Naver/NaverAuthenticationOptions.cs @@ -5,7 +5,6 @@ */ using System.Security.Claims; -using System.Text.Json; using static AspNet.Security.OAuth.Naver.NaverAuthenticationConstants; namespace AspNet.Security.OAuth.Naver; diff --git a/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs index 00eaabf26..6909384f8 100644 --- a/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Nextcloud/NextcloudAuthenticationHandler.cs @@ -28,8 +28,8 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string userId = tokens.Response!.RootElement.GetString("user_id") ?? string.Empty; - string userEndpoint = Options.UserInformationEndpoint.TrimEnd('/'); + var userId = tokens.Response!.RootElement.GetString("user_id") ?? string.Empty; + var userEndpoint = Options.UserInformationEndpoint.TrimEnd('/'); userEndpoint += $"/{Uri.EscapeDataString(userId)}"; using var request = new HttpRequestMessage(HttpMethod.Get, userEndpoint); diff --git a/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs index 432883414..8803d6a04 100644 --- a/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs @@ -14,16 +14,11 @@ namespace AspNet.Security.OAuth.Notion; -public class NotionAuthenticationHandler : OAuthHandler +public class NotionAuthenticationHandler( + [NotNull] IOptionsMonitor options, + [NotNull] ILoggerFactory logger, + [NotNull] UrlEncoder encoder) : OAuthHandler(options, logger, encoder) { - public NotionAuthenticationHandler( - [NotNull] IOptionsMonitor options, - [NotNull] ILoggerFactory logger, - [NotNull] UrlEncoder encoder) - : base(options, logger, encoder) - { - } - protected override async Task ExchangeCodeAsync([NotNull] OAuthCodeExchangeContext context) { var tokenRequestParameters = new Dictionary() diff --git a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs index bb922a1e3..d6093d56a 100644 --- a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs +++ b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationDefaults.cs @@ -68,5 +68,5 @@ public static class OktaAuthenticationDefaults /// Default path to use for . /// public static readonly string UserInformationEndpointPath = string.Format(CultureInfo.InvariantCulture, UserInformationEndpointPathFormat, DefaultAuthorizationServer); -#pragma warning disable CA1863 +#pragma warning restore CA1863 } diff --git a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs index db1a7ed3c..00a1916b9 100644 --- a/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Okta/OktaAuthenticationHandler.cs @@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string endpoint = Options.UserInformationEndpoint; + var endpoint = Options.UserInformationEndpoint; using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs index 53befd90b..165f4729c 100644 --- a/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Patreon/PatreonAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string endpoint = Options.UserInformationEndpoint; + var endpoint = Options.UserInformationEndpoint; if (Options.Fields.Count > 0) { diff --git a/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs b/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs index 45b8d07c7..6e35db98d 100644 --- a/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.PingOne/PingOneAuthenticationHandler.cs @@ -38,7 +38,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string endpoint = Options.UserInformationEndpoint; + var endpoint = Options.UserInformationEndpoint; using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs b/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs index 58941bd77..45513a00f 100644 --- a/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.QuickBooks/QuickBooksAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs index c3011970b..a8bfd0d71 100644 --- a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs +++ b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationDefaults.cs @@ -85,7 +85,7 @@ public static class ShopifyAuthenticationDefaults public static readonly string ShopifyEligibleForPaymentsClaimType = "urn:shopify:eligible_for_payments"; /// - /// The timezone that that the shop is using. + /// The time zone that that the shop is using. /// public static readonly string ShopifyTimezoneClaimType = "urn:shopify:timezone"; } diff --git a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs index f36fc28be..93b92b22f 100644 --- a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs +++ b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs @@ -7,9 +7,9 @@ namespace AspNet.Security.OAuth.Shopify; /// -/// Substitue for to enforce setting shop name +/// Substitute for to enforce setting shop name /// before Challenge and provide an override for . You -/// can accomplish the same thing by setting the approriate values in . +/// can accomplish the same thing by setting the appropriate values in . /// public class ShopifyAuthenticationProperties : AuthenticationProperties { diff --git a/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs index 25ecf2d55..9d98d655a 100644 --- a/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "token", tokens.AccessToken!); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "token", tokens.AccessToken!); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs index 4b1f5096d..c8dcbe10e 100644 --- a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationHandler.cs @@ -6,10 +6,8 @@ using System.Net.Http.Headers; using System.Security.Claims; -using System.Text; using System.Text.Encodings.Web; using System.Text.Json; -using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -30,7 +28,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string endpoint = Options.UserInformationEndpoint; + var endpoint = Options.UserInformationEndpoint; using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs index 54499f25c..45f801d8f 100644 --- a/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs +++ b/src/AspNet.Security.OAuth.Snapchat/SnapchatAuthenticationOptions.cs @@ -5,8 +5,6 @@ */ using System.Security.Claims; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; using static AspNet.Security.OAuth.Snapchat.SnapchatAuthenticationConstants; namespace AspNet.Security.OAuth.Snapchat; diff --git a/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs b/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs index 8c66a4dac..63ba254e6 100644 --- a/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.SoundCloud/SoundCloudAuthenticationHandler.cs @@ -29,7 +29,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "oauth_token", tokens.AccessToken!); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "oauth_token", tokens.AccessToken!); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs index f067e82d7..9db969bcf 100644 --- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs @@ -35,7 +35,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - (string tenantId, string webApiUrl) = await ProcessIdTokenAndGetContactIdentifierAsync(tokens, properties, identity); + (var tenantId, var webApiUrl) = await ProcessIdTokenAndGetContactIdentifierAsync(tokens, properties, identity); if (string.IsNullOrEmpty(tenantId)) { @@ -82,7 +82,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] ClaimsIdentity identity) { - string? idToken = tokens.Response!.RootElement.GetString("id_token"); + var idToken = tokens.Response!.RootElement.GetString("id_token"); if (Options.SaveTokens) { diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs index a3f7160de..0d0e885cd 100644 --- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs +++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationOptions.cs @@ -146,7 +146,7 @@ private string GetEnvironment() /// private void UpdateEndpoints() { - string env = GetEnvironment(); + var env = GetEnvironment(); #pragma warning disable CA1863 AuthorizationEndpoint = string.Format(CultureInfo.InvariantCulture, diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs index 5c6a7fad3..c55814304 100644 --- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs +++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationPostConfigureOptions.cs @@ -30,7 +30,7 @@ public void PostConfigure( // As seen in: // github.com/dotnet/aspnetcore/blob/master/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs#L71-L102 // need this now to successfully instantiate ConfigurationManager below. - if (options.Backchannel == null) + if (options.Backchannel is null) { #pragma warning disable CA2000 // Dispose objects before losing scope options.Backchannel = new HttpClient(options.BackchannelHttpHandler ?? new HttpClientHandler()); @@ -40,7 +40,7 @@ public void PostConfigure( options.Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB } - if (options.ConfigurationManager == null) + if (options.ConfigurationManager is null) { if (string.IsNullOrEmpty(options.MetadataAddress)) { @@ -57,9 +57,6 @@ public void PostConfigure( }; } - if (options.SecurityTokenHandler == null) - { - options.SecurityTokenHandler = new JsonWebTokenHandler(); - } + options.SecurityTokenHandler ??= new JsonWebTokenHandler(); } } diff --git a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs index f71098d91..2a7c76e23 100644 --- a/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs +++ b/src/AspNet.Security.OAuth.SuperOffice/SuperOfficeFunctionalRightsClaimAction.cs @@ -10,19 +10,11 @@ namespace AspNet.Security.OAuth.SuperOffice; -internal sealed class SuperOfficeFunctionalRightsClaimAction : ClaimAction +internal sealed class SuperOfficeFunctionalRightsClaimAction(SuperOfficeAuthenticationOptions options) : ClaimAction(ClaimTypes.Email, ClaimValueTypes.String) { - private readonly SuperOfficeAuthenticationOptions _options; - - internal SuperOfficeFunctionalRightsClaimAction(SuperOfficeAuthenticationOptions options) - : base(ClaimTypes.Email, ClaimValueTypes.String) - { - _options = options; - } - public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer) { - if (!_options.IncludeFunctionalRightsAsClaims || + if (!options.IncludeFunctionalRightsAsClaims || userData.ValueKind != JsonValueKind.Object) { return; diff --git a/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs index 6757e3be0..b4103847f 100644 --- a/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Twitter/TwitterAuthenticationHandler.cs @@ -106,10 +106,10 @@ protected override async Task ExchangeCodeAsync([NotNull] OA return response.IsSuccessStatusCode switch { true => OAuthTokenResponse.Success(JsonDocument.Parse(body)), - false => PrepareFailedOAuthTokenReponse(response, body) + false => PrepareFailedOAuthTokenResponse(response, body) }; - static OAuthTokenResponse PrepareFailedOAuthTokenReponse(HttpResponseMessage response, string body) + static OAuthTokenResponse PrepareFailedOAuthTokenResponse(HttpResponseMessage response, string body) { var exception = GetStandardErrorException(JsonDocument.Parse(body)); diff --git a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs index 91b26497e..a09ab57dc 100644 --- a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs +++ b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationOptions.cs @@ -45,7 +45,7 @@ public XeroAuthenticationOptions() /// Gets or sets the parameters used to validate identity tokens. /// /// Contains the types and definitions required for validating a token. - public TokenValidationParameters TokenValidationParameters { get; set; } = new TokenValidationParameters(); + public TokenValidationParameters TokenValidationParameters { get; set; } = new(); /// /// Gets or sets the configuration manager responsible for retrieving, caching, and refreshing the diff --git a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs index 6f3942aea..125e6f81c 100644 --- a/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs +++ b/src/AspNet.Security.OAuth.Xero/XeroAuthenticationPostConfigureOptions.cs @@ -45,21 +45,15 @@ public void PostConfigure( options.Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB } - if (options.ConfigurationManager == null) + options.ConfigurationManager ??= new ConfigurationManager( + options.MetadataAddress, + new OpenIdConnectConfigurationRetriever(), + new HttpDocumentRetriever(options.Backchannel)) { - options.ConfigurationManager = new ConfigurationManager( - options.MetadataAddress, - new OpenIdConnectConfigurationRetriever(), - new HttpDocumentRetriever(options.Backchannel)) - { - AutomaticRefreshInterval = TimeSpan.FromDays(1), - RefreshInterval = TimeSpan.FromSeconds(30) - }; - } + AutomaticRefreshInterval = TimeSpan.FromDays(1), + RefreshInterval = TimeSpan.FromSeconds(30) + }; - if (options.SecurityTokenHandler == null) - { - options.SecurityTokenHandler = new JsonWebTokenHandler(); - } + options.SecurityTokenHandler ??= new JsonWebTokenHandler(); } } diff --git a/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs index f7c315e60..404a33a75 100644 --- a/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Xumm/XummAuthenticationHandler.cs @@ -8,7 +8,6 @@ using System.Security.Claims; using System.Text.Encodings.Web; using System.Text.Json; -using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs b/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs index 3b1fba198..6a5977319 100644 --- a/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs +++ b/src/AspNet.Security.OAuth.Zendesk/ZendeskPostConfigureOptions.cs @@ -21,7 +21,7 @@ public void PostConfigure( { if (string.IsNullOrWhiteSpace(options.Domain)) { - throw new ArgumentException($"No Zendesk domain configured", nameof(options)); + throw new ArgumentException("No Zendesk domain configured", nameof(options)); } options.AuthorizationEndpoint = CreateUrl(options.Domain, AuthorizationEndpointPath); diff --git a/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs index 9ddbd8559..8ad5f73cf 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/AdobeIO/AdobeIOTests.cs @@ -8,21 +8,13 @@ namespace AspNet.Security.OAuth.AdobeIO; -public class AdobeIOTests : OAuthTests +public class AdobeIOTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public AdobeIOTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => AdobeIOAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddAdobeIO(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddAdobeIO(options => ConfigureDefaults(builder, options)); } [Theory] @@ -35,16 +27,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:adobeio:account_type", "ent")] [InlineData("urn:adobeio:email_verified", "True")] public async Task Can_Sign_In_Using_AdobeIO(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Fact] public async Task BuildChallengeUrl_Generates_Correct_Url() diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs index 7e7780c6f..d0c752bde 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Alipay/AlipayTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Alipay; -public class AlipayTests : OAuthTests +public class AlipayTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public AlipayTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => AlipayAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -35,16 +30,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:alipay:nick_name", "my-nickname")] [InlineData("urn:alipay:gender", "M")] public async Task Can_Sign_In_Using_Alipay(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs index 1d4b6dfd9..33e697fcd 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Amazon/AmazonTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Amazon; -public class AmazonTests : OAuthTests +public class AmazonTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public AmazonTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => AmazonAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -30,14 +25,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Email, "john@john-smith.local")] [InlineData(ClaimTypes.PostalCode, "90210")] public async Task Can_Sign_In_Using_Amazon(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs index 001d0aba8..dbb4b46c4 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/AmoCrm/AmoCrmTests.cs @@ -6,7 +6,7 @@ namespace AspNet.Security.OAuth.AmoCrm; -public class AmoCrmTests : OAuthTests +public class AmoCrmTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { public override string DefaultScheme => AmoCrmAuthenticationDefaults.AuthenticationScheme; @@ -25,14 +25,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Surname, "Smith")] [InlineData(ClaimTypes.Email, "john@john-smith.local")] public async Task Can_Sign_In_Using_AmoCrm(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs index 2e02a4251..b6ce0c853 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleTests.cs @@ -14,15 +14,10 @@ namespace AspNet.Security.OAuth.Apple; -public class AppleTests : OAuthTests +public class AppleTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { private static readonly JsonSerializerOptions SerializerOptions = new() { WriteIndented = true }; - public AppleTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => AppleAuthenticationDefaults.AuthenticationScheme; protected override HttpMethod RedirectMethod => HttpMethod.Post; @@ -60,13 +55,7 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Theory] @@ -93,13 +82,7 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Theory] @@ -133,13 +116,7 @@ static void ConfigureServices(IServiceCollection services) RedirectParameters.Clear(); // Simulate second sign in where user data is not returned - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Theory] @@ -156,13 +133,7 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Fact] @@ -354,7 +325,7 @@ void ConfigureServices(IServiceCollection services) using var server = CreateTestServer(ConfigureServices); // Act - var claims = await AuthenticateUserAsync(server); + await AuthenticateUserAsync(server); // Assert onGenerateClientSecretEventRaised.ShouldBeTrue(); @@ -413,7 +384,7 @@ void ConfigureServices(IServiceCollection services) using var server = CreateTestServer(ConfigureServices); // Act - var claims = await AuthenticateUserAsync(server); + await AuthenticateUserAsync(server); // Assert onGenerateClientSecretEventRaised.ShouldBeTrue(); @@ -501,7 +472,7 @@ public void Regenerate_Test_Jwts() iat, sub, atHash, - new Claim(JwtRegisteredClaimNames.Email, "johnny.appleseed@apple.local"), + new(JwtRegisteredClaimNames.Email, "johnny.appleseed@apple.local"), emailVerified, authTime, nonceSupported, @@ -519,11 +490,11 @@ public void Regenerate_Test_Jwts() iat, sub, atHash, - new Claim(JwtRegisteredClaimNames.Email, "ussckefuz6@privaterelay.appleid.com"), + new(JwtRegisteredClaimNames.Email, "ussckefuz6@privaterelay.appleid.com"), emailVerified, authTime, nonceSupported, - new Claim("is_private_email", "true"), + new("is_private_email", "true"), }; var privateEmailToken = new JwtSecurityToken( @@ -540,13 +511,13 @@ public void Regenerate_Test_Jwts() // Copy the values from the test output to bundles.json if you need to regenerate the JWTs to edit the claims // For https://appleid.apple.com/auth/keys - OutputHelper!.WriteLine($"RSA key: {serializedRsaPublicKey}"); + OutputHelper?.WriteLine($"RSA key: {serializedRsaPublicKey}"); // For https://appleid.apple.com/auth/token - OutputHelper!.WriteLine($"Public email JWT: {publicEmailIdToken}"); + OutputHelper?.WriteLine($"Public email JWT: {publicEmailIdToken}"); // For https://appleid.apple.local/auth/token/email - OutputHelper!.WriteLine($"Private email JWT: {privateEmailIdToken}"); + OutputHelper?.WriteLine($"Private email JWT: {privateEmailIdToken}"); } private sealed class CustomAppleAuthenticationEvents : AppleAuthenticationEvents diff --git a/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs index 46a2579ef..21e85f42b 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/ArcGIS/ArcGISTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.ArcGIS; -public class ArcGISTests : OAuthTests +public class ArcGISTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public ArcGISTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => ArcGISAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "John Smith")] [InlineData(ClaimTypes.Email, "john@john-smith.local")] public async Task Can_Sign_In_Using_ArcGIS(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs index 2626bb480..898141a7b 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Asana/AsanaTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Asana; -public class AsanaTests : OAuthTests +public class AsanaTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public AsanaTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => AsanaAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "John Smith")] [InlineData(ClaimTypes.Email, "john@john-smith.local")] public async Task Can_Sign_In_Using_Asana(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs index 3c46a75ff..26c9c874e 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Autodesk/AutodeskTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Autodesk; -public class AutodeskTests : OAuthTests +public class AutodeskTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public AutodeskTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => AutodeskAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Surname, "Smith")] [InlineData("urn:autodesk:emailverified", "True")] public async Task Can_Sign_In_Using_Autodesk(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs index b6280ea1a..32ee25bd1 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Baidu/BaiduTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.Baidu; -public class BaiduTests : OAuthTests +public class BaiduTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public BaiduTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => BaiduAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddBaidu(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddBaidu(options => ConfigureDefaults(builder, options)); } [Theory] @@ -28,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "my-name")] [InlineData("urn:baidu:portrait", "https://tb.himg.baidu.com/sys/portrait/item/my-portrait")] public async Task Can_Sign_In_Using_Baidu(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs index a52f4dfa1..21ec0b385 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Basecamp/BasecampTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Basecamp; -public class BasecampTests : OAuthTests +public class BasecampTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public BasecampTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => BasecampAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -26,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Surname, "Smith")] [InlineData(ClaimTypes.Email, "john@john-smith.local")] public async Task Can_Sign_In_Using_Basecamp(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs index a2f5490b2..26c6fd0e0 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/BattleNet/BattleNetTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.BattleNet; -public class BattleNetTests : OAuthTests +public class BattleNetTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public BattleNetTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => BattleNetAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "my-id")] [InlineData(ClaimTypes.Name, "John Smith")] public async Task Can_Sign_In_Using_BattleNet(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs index 6d812d3db..b0c0e2dfe 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Bitbucket/BitbucketTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Bitbucket; -public class BitbucketTests : OAuthTests +public class BitbucketTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public BitbucketTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => BitbucketAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -32,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:bitbucket:name", "John Smith")] [InlineData("urn:bitbucket:url", "https://bitbucket.org")] public async Task Can_Sign_In_Using_Bitbucket(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs index b1b89a914..64c3e9f28 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Buffer/BufferTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Buffer; -public class BufferTests : OAuthTests +public class BufferTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public BufferTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => BufferAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -23,14 +18,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [Theory] [InlineData(ClaimTypes.NameIdentifier, "my-id")] public async Task Can_Sign_In_Using_Buffer(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs index 67abe1765..67501ab3f 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/CiscoSpark/CiscoSparkTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.CiscoSpark; -public class CiscoSparkTests : OAuthTests +public class CiscoSparkTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public CiscoSparkTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => CiscoSparkAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "John Smith")] [InlineData(ClaimTypes.Email, "john@john-smith.local")] public async Task Can_Sign_In_Using_CiscoSpark(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs index 4446f8c05..3b22361d9 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Coinbase/CoinbaseTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Coinbase; -public class CoinbaseTests : OAuthTests +public class CoinbaseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public CoinbaseTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => CoinbaseAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -30,14 +25,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:coinbase:profile_url", "https://coinbase.com/jsmith")] [InlineData("urn:coinbase:username", "jsmith")] public async Task Can_Sign_In_Using_Coinbase(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs index 2d0745c49..cec48f04e 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Deezer/DeezerTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Deezer; -public class DeezerTests : OAuthTests +public class DeezerTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public DeezerTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => DeezerAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -46,16 +41,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(DeezerAuthenticationConstants.Claims.Type, "Type")] [InlineData(DeezerAuthenticationConstants.Claims.ExplicitContentLevel, "ExplicitContentLevel")] public async Task Can_Sign_In_Using_Deezer(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs index f0e2eedc8..488140977 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/DeviantArt/DeviantArtTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.DeviantArt; -public class DeviantArtTests : OAuthTests +public class DeviantArtTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public DeviantArtTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => DeviantArtAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "John Smith")] [InlineData("urn:deviantart:name", "John Smith")] public async Task Can_Sign_In_Using_Deviant_Art(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs index 37086ad0e..9aa3cd173 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/DigitalOcean/DigitalOceanTests.cs @@ -4,25 +4,15 @@ * for more information concerning the license and the contributors participating to this project. */ -using Microsoft.AspNetCore.WebUtilities; - namespace AspNet.Security.OAuth.DigitalOcean; -public class DigitalOceanTests : OAuthTests +public class DigitalOceanTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public DigitalOceanTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => DigitalOceanAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddDigitalOcean(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddDigitalOcean(options => ConfigureDefaults(builder, options)); } [Theory] @@ -31,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Email, "me@test.com")] [InlineData(DigitalOceanAuthenticationConstants.Claims.EmailVerified, "true")] public async Task Can_Sign_In_Using_DigitalOcean(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs index 538e61807..79be61d1b 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Discord/DiscordTests.cs @@ -9,13 +9,8 @@ namespace AspNet.Security.OAuth.Discord; -public class DiscordTests : OAuthTests +public class DiscordTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public DiscordTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => DiscordAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -30,16 +25,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.Discriminator, "1234")] [InlineData(Claims.AvatarHash, "dummy-avatar-hash")] public async Task Can_Sign_In_Using_Discord(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Fact] public async Task Authorization_Endpoint_Uri_by_Default_Does_Not_Contain_Prompt() diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs index 012e2b9b0..226467ce5 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Dropbox/DropboxTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Dropbox; -public class DropboxTests : OAuthTests +public class DropboxTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public DropboxTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => DropboxAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -27,16 +22,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "Franz Ferdinand (Personal)")] [InlineData(ClaimTypes.Email, "franz@gmail.com")] public async Task Can_Sign_In_Using_Dropbox(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData("offline")] @@ -67,7 +53,7 @@ void ConfigureServices(IServiceCollection services) using var server = CreateTestServer(ConfigureServices); // Act - var claims = await AuthenticateUserAsync(server); + await AuthenticateUserAsync(server); // Assert accessTypeIsSet.ShouldBeTrue(); @@ -98,7 +84,7 @@ void ConfigureServices(IServiceCollection services) using var server = CreateTestServer(ConfigureServices); // Act - var claims = await AuthenticateUserAsync(server); + await AuthenticateUserAsync(server); // Assert refreshTokenIsPresent.ShouldBeTrue(); diff --git a/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs index 87afd22e2..37bc02e19 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/EVEOnline/EVEOnlineTests.cs @@ -1,4 +1,4 @@ -/* +/* * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers * for more information concerning the license and the contributors participating to this project. @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.EVEOnline; -public class EVEOnlineTests : OAuthTests +public class EVEOnlineTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public EVEOnlineTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => EVEOnlineAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -26,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Expiration, "2019-12-31T23:59:59+00:00")] [InlineData("urn:eveonline:scopes", "my-scopes")] public async Task Can_Sign_In_Using_EVE_Online(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs index 33440a0a1..1ae42a2dc 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Ebay/EbayTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Ebay; -public class EbayTests : OAuthTests +public class EbayTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public EbayTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => EbayAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -30,16 +25,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "my-id")] [InlineData(ClaimTypes.Name, "John Smith")] public async Task Can_Sign_In_Using_Ebay(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs index 06aff9582..2b1e10522 100755 --- a/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/ExactOnline/ExactOnlineTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.ExactOnline; -public class ExactOnlineTests : OAuthTests +public class ExactOnlineTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public ExactOnlineTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => ExactOnlineAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,14 +26,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.Division, "12345")] [InlineData(Claims.Company, "Division Name")] public async Task Can_Sign_In_Using_ExactOnline(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs index b39115e7a..d045a4006 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Feishu/FeishuTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.Feishu; -public class FeishuTests : OAuthTests +public class FeishuTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public FeishuTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => FeishuAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddFeishu(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddFeishu(options => ConfigureDefaults(builder, options)); } [Theory] @@ -29,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(FeishuAuthenticationConstants.Claims.UnionId, "test-union-id")] [InlineData(FeishuAuthenticationConstants.Claims.Avatar, "https://www.feishu.cn/avatar/icon_big")] public async Task Can_Sign_In_Using_Feishu(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs index 2a4abe92e..a161fe51a 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Fitbit/FitbitTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Fitbit; -public class FitbitTests : OAuthTests +public class FitbitTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public FitbitTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => FitbitAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -26,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:fitbit:avatar", "https://fitbit.local/john-smith/avatar.png")] [InlineData("urn:fitbit:avatar150", "https://fitbit.local/john-smith/avatar-150.png")] public async Task Can_Sign_In_Using_Fitbit(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs index 411378f0b..78bc4168a 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Foursquare/FoursquareTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Foursquare; -public class FoursquareTests : OAuthTests +public class FoursquareTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public FoursquareTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => FoursquareAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -29,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Gender, "Male")] [InlineData(ClaimTypes.Uri, "https://foursquare.local/john-smith")] public async Task Can_Sign_In_Using_Foursquare(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs index ccac87217..650c7d093 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubEnterpriseTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.GitHub; -public class GitHubEnterpriseTests : OAuthTests +public class GitHubEnterpriseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public GitHubEnterpriseTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => GitHubAuthenticationDefaults.AuthenticationScheme; protected override string BundleName => "GitHub"; @@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:github:name", "monalisa octocat")] [InlineData("urn:github:url", "https://api.github.enterprise.local/users/octocat")] public async Task Can_Sign_In_Using_GitHub_Enterprise(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs index 8fd479f91..da3001590 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/GitHub/GitHubTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.GitHub; -public class GitHubTests : OAuthTests +public class GitHubTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public GitHubTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => GitHubAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,14 +26,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:github:name", "monalisa octocat")] [InlineData("urn:github:url", "https://api.github.com/users/octocat")] public async Task Can_Sign_In_Using_GitHub(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs index c99112968..b1ffa208c 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/GitLab/GitLabTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.GitLab; -public class GitLabTests : OAuthTests +public class GitLabTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public GitLabTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => GitLabAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddGitLab(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddGitLab(options => ConfigureDefaults(builder, options)); } [Theory] @@ -31,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(GitLabAuthenticationConstants.Claims.Url, "https://gitlab.com/testuser")] [InlineData(GitLabAuthenticationConstants.Claims.Avatar, "https://assets.gitlab-static.net/uploads/-/system/user/avatar/1234567/avatar.png")] public async Task Can_Sign_In_Using_GitHub(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs index 7e81a659d..bfc7e2cf5 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Gitee/GiteeTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Gitee; -public class GiteeTests : OAuthTests +public class GiteeTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public GiteeTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => GiteeAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -27,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:gitee:name", "name")] [InlineData("urn:gitee:url", "https://gitee.com/api/v5/users/loginname")] public async Task Can_Sign_In_Using_Gitee(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs index 346d809e8..9abe7b1c0 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Harvest/HarvestTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.Harvest; -public class HarvestTests : OAuthTests +public class HarvestTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public HarvestTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => HarvestAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddHarvest(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddHarvest(options => ConfigureDefaults(builder, options)); } [Theory] @@ -30,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Surname, "Smith")] [InlineData(ClaimTypes.Email, "john.smith@mail.com")] public async Task Can_Sign_In_Using_Harvest(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs index a746debef..775d4cc15 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/HealthGraph/HealthGraphTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.HealthGraph; -public class HealthGraphTests : OAuthTests +public class HealthGraphTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public HealthGraphTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => HealthGraphAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -23,14 +18,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [Theory] [InlineData(ClaimTypes.NameIdentifier, "my-id")] public async Task Can_Sign_In_Using_HealthGraph(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs index 513c55d64..1fe29ed58 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Huawei/HuaweiTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Huawei; -public class HuaweiTests : OAuthTests +public class HuaweiTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public HuaweiTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => HuaweiAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(HuaweiAuthenticationConstants.Claims.Avatar, "test-head-picture-url.jpg")] [InlineData(ClaimTypes.Email, "test-email@test")] public async Task Can_Sign_In_Using_Huawei(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs index 9245bcdf2..efaa9b98d 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/HubSpot/HubSpotTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.HubSpot; -public class HubSpotTests : OAuthTests +public class HubSpotTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public HubSpotTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => HubSpotAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:HubSpot:app_id", "696969")] [InlineData("urn:HubSpot:hub_domain", "dev-13371337.com")] public async Task Can_Sign_In_Using_HubSpot(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs index 80f7b959a..63fc08c8b 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Imgur/ImgurTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Imgur; -public class ImgurTests : OAuthTests +public class ImgurTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public ImgurTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => ImgurAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:imgur:proexpiration", "2019-03-17T14:00:00+00:00")] [InlineData("urn:imgur:reputation", "0")] public async Task Can_Sign_In_Using_Imgur(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs index 17563ee27..9e7dd0424 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/ApplicationFactory.cs @@ -97,8 +97,8 @@ private static void ConfigureApplication(IApplicationBuilder app, OAut { if (context.User.Identity?.IsAuthenticated == true) { - string xml = IdentityToXmlString(context.User); - byte[] buffer = Encoding.UTF8.GetBytes(xml); + var xml = IdentityToXmlString(context.User); + var buffer = Encoding.UTF8.GetBytes(xml); context.Response.StatusCode = 200; context.Response.ContentType = "text/xml"; diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs index 59f80cc6a..8116ad961 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/HttpRequestInterceptionFilter.cs @@ -12,21 +12,14 @@ namespace AspNet.Security.OAuth.Infrastructure; /// /// Registers an delegating handler to intercept HTTP requests made by the test application. /// -internal sealed class HttpRequestInterceptionFilter : IHttpMessageHandlerBuilderFilter +internal sealed class HttpRequestInterceptionFilter(HttpClientInterceptorOptions options) : IHttpMessageHandlerBuilderFilter { - private readonly HttpClientInterceptorOptions _options; - - internal HttpRequestInterceptionFilter(HttpClientInterceptorOptions options) - { - _options = options; - } - public Action Configure(Action next) { return builder => { next(builder); - builder.AdditionalHandlers.Add(_options.CreateHttpMessageHandler()); + builder.AdditionalHandlers.Add(options.CreateHttpMessageHandler()); }; } } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs index 5d3e94c4f..d170a46d7 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs @@ -35,7 +35,7 @@ protected override async Task SendAsync(HttpRequestMessage if (RedirectMethod == HttpMethod.Post) { var queryString = HttpUtility.ParseQueryString(result.Headers.Location!.Query); - string? state = queryString["state"]; + var state = queryString["state"]; var parameters = new Dictionary() { @@ -86,17 +86,17 @@ protected virtual Uri BuildLoopbackUri(HttpResponseMessage responseMessage) // successfully authenticated with the external login page they were redirected to. var queryString = HttpUtility.ParseQueryString(responseMessage.Headers.Location!.Query); - string? location = queryString["redirect_uri"] ?? RedirectUri; - string? state = queryString["state"]; + var location = queryString["redirect_uri"] ?? RedirectUri; + var state = queryString["state"]; var builder = new UriBuilder(location!); // Retain the _oauthstate parameter in redirect_uri for WeChat (see #262) const string OAuthStateKey = "_oauthstate"; var redirectQuery = HttpUtility.ParseQueryString(builder.Query); - string? oauthState = redirectQuery[OAuthStateKey]; + var oauthState = redirectQuery[OAuthStateKey]; - // Remove any query string parameters we do not explictly need to retain + // Remove any query string parameters we do not explicitly need to retain queryString.Clear(); queryString.Add("code", "a6ed8e7f-471f-44f1-903b-65946475f351"); diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs index 82a6c37e9..1ed0bdd41 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Instagram/InstagramTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Instagram; -public class InstagramTests : OAuthTests +public class InstagramTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public InstagramTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => InstagramAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -26,16 +21,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "jayposiris")] [InlineData(ClaimTypes.NameIdentifier, "17841405793187218")] public async Task Can_Sign_In_Using_Instagram(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(ClaimTypes.Name, "jayposiris")] @@ -55,12 +41,6 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs index 027be1b58..558139bb7 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudEnterpriseTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.JumpCloud; -public class JumpCloudEnterpriseTests : OAuthTests +public class JumpCloudEnterpriseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public JumpCloudEnterpriseTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => JumpCloudAuthenticationDefaults.AuthenticationScheme; protected override string BundleName => "JumpCloud"; @@ -33,14 +28,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "00uid4BxXw6I6TV4m0g3")] [InlineData(ClaimTypes.Surname, "Doe")] public async Task Can_Sign_In_Using_JumpCloud(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs index 1d3c849a2..8fa1e9e77 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/JumpCloud/JumpCloudTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.JumpCloud; -public class JumpCloudTests : OAuthTests +public class JumpCloudTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public JumpCloudTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => JumpCloudAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddJumpCloud(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddJumpCloud(options => ConfigureDefaults(builder, options)); } [Theory] @@ -30,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "00uid4BxXw6I6TV4m0g3")] [InlineData(ClaimTypes.Surname, "Doe")] public async Task Can_Sign_In_Using_JumpCloud(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs index 55c4873ef..67c87b62d 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/KakaoTalk/KakaoTalkTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.KakaoTalk; -public class KakaoTalkTests : OAuthTests +public class KakaoTalkTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public KakaoTalkTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => KakaoTalkAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -32,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.AgeRange, "20~29")] [InlineData(Claims.YearOfBirth, "2020")] public async Task Can_Sign_In_Using_KakaoTalk(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs index e7f797c27..8d5d0d834 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Keycloak/KeycloakTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Keycloak; -public class KeycloakTests : OAuthTests +public class KeycloakTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public KeycloakTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => KeycloakAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -42,13 +37,7 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Theory] @@ -88,13 +77,7 @@ void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Theory] @@ -116,12 +99,6 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs index eea4e497e..f4dd1ac24 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Kloudless/KloudlessTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Kloudless; -public class KloudlessTests : OAuthTests +public class KloudlessTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public KloudlessTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => KloudlessAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(KloudlessAuthenticationConstants.Claims.Type, "account")] [InlineData(KloudlessAuthenticationConstants.Claims.Enabled, "True")] public async Task Can_Sign_In_Using_Kloudless(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs index 0bcaf219b..6f44cd16f 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Kook/KookTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Kook; -public class KookTests : OAuthTests +public class KookTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public KookTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => KookAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -32,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.BannerUrl, "https://xxx.com/assets/banner.png/icon")] [InlineData(Claims.IsMobileVerified, "True")] public async Task Can_Sign_In_Using_Kook(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs index cea9b885a..ef4f87e8c 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Kroger/KrogerTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Kroger; -public class KrogerTests : OAuthTests +public class KrogerTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public KrogerTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => KrogerAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -23,14 +18,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [Theory] [InlineData(ClaimTypes.NameIdentifier, "53990804-cfd1-43f3-8256-bdc9817a4fd0")] public async Task Can_Sign_In_Using_Kroger(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs index 7f58b92e3..f3b2ed941 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Lichess/LichessTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Lichess; -public class LichessTests : OAuthTests +public class LichessTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public LichessTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => LichessAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,14 +26,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.GivenName, "Thibault")] [InlineData(ClaimTypes.Surname, "Duplessis")] public async Task Can_Sign_In_Using_Lichess(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs index 6c5fe34f5..1b85a071f 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Line/LineTests.cs @@ -8,15 +8,10 @@ namespace AspNet.Security.OAuth.Line; -public class LineTests : OAuthTests +public class LineTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { public override string DefaultScheme => LineAuthenticationDefaults.AuthenticationScheme; - public LineTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { builder.AddLine(options => @@ -32,16 +27,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:line:picture_url", "my-picture")] [InlineData(ClaimTypes.Email, "my-email")] public async Task Can_Sign_In_Using_Line(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false, false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs index bd476412b..8f8956a5d 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/LinkedIn/LinkedInTests.cs @@ -8,15 +8,10 @@ namespace AspNet.Security.OAuth.LinkedIn; -public class LinkedInTests : OAuthTests +public class LinkedInTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { private Action? additionalConfiguration; - public LinkedInTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => LinkedInAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -48,13 +43,7 @@ public async Task Can_Sign_In_Using_LinkedIn(string claimType, string claimValue // Arrange additionalConfiguration = options => options.Fields.Add(LinkedInAuthenticationConstants.ProfileFields.PictureUrl); - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } [Theory] @@ -63,16 +52,7 @@ public async Task Can_Sign_In_Using_LinkedIn(string claimType, string claimValue [InlineData(ClaimTypes.GivenName, "Frodon")] [InlineData(ClaimTypes.Surname, "Sacquet")] public async Task Can_Sign_In_Using_LinkedIn_Localized(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(ClaimTypes.NameIdentifier, "1R2RtA")] @@ -84,7 +64,7 @@ public async Task Can_Sign_In_Using_LinkedIn_Localized_With_Custom_Resolver(stri // Arrange additionalConfiguration = options => options.MultiLocaleStringResolver = (values, preferredLocale) => { - if (values.TryGetValue("fr_FR", out string? value)) + if (values.TryGetValue("fr_FR", out var value)) { return value; } @@ -92,12 +72,6 @@ public async Task Can_Sign_In_Using_LinkedIn_Localized_With_Custom_Resolver(stri return values.Values.FirstOrDefault(); }; - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs index 78d7ed00b..9de5447d3 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/MailChimp/MailChimpTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.MailChimp; -public class MailChimpTests : OAuthTests +public class MailChimpTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public MailChimpTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => MailChimpAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "John Smith")] [InlineData(ClaimTypes.Email, "john@john-smith.local")] public async Task Can_Sign_In_Using_MailChimp(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs index e412e0acd..d95f6676e 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/MailRu/MailRuTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.MailRu; -public class MailRuTests : OAuthTests +public class MailRuTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public MailRuTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => MailRuAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddMailRu(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddMailRu(options => ConfigureDefaults(builder, options)); } [Theory] @@ -32,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Gender, "m")] [InlineData("urn:mailru:profileimage", "https://filin.mail.ru/pic?d=idofpic&width=180&height=180")] public async Task Can_Sign_In_Using_MailRu(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs index ee1fa8d9b..285bc508d 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Mixcloud/MixcloudTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Mixcloud; -public class MixcloudTests : OAuthTests +public class MixcloudTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public MixcloudTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => MixcloudAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -33,16 +28,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:mixcloud:profileimageurl", "https://mixcloud.local/images/320wx320h")] [InlineData("urn:mixcloud:profilethumbnailurl", "https://mixcloud.local/images/thumbnail")] public async Task Can_Sign_In_Using_Mixcloud(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs index e232581c0..f68aeaa18 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Moodle; -public class MoodleTests : OAuthTests +public class MoodleTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public MoodleTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => MoodleAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -40,16 +35,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.Language, "en")] [InlineData(Claims.Description, "John Doe's Moodle account")] public async Task Can_Sign_In_Using_Moodle(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(ClaimTypes.Name, "张三")] @@ -80,12 +66,6 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs index 3b1d8033e..c69a40519 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Myob/MyobTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Myob; -public class MyobTests : OAuthTests +public class MyobTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public MyobTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => MyobAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "my-id")] [InlineData(ClaimTypes.Name, "John Smith")] public async Task Can_Sign_In_Using_Myob(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs index a5c41361b..ea52901a4 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Naver/NaverTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Naver; -public class NaverTests : OAuthTests +public class NaverTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public NaverTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => NaverAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.YearOfBirth, "2020")] [InlineData(Claims.ProfileImage, "https://ssl.pstatic.net/static/pwe/address/img_profile.png")] public async Task Can_Sign_In_Using_Naver(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs index 6679d5c87..052ff657c 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/NetEase/NetEaseTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.NetEase; -public class NetEaseTests : OAuthTests +public class NetEaseTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public NetEaseTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => NetEaseAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "820014421")] [InlineData(ClaimTypes.Name, "urstest_mreg")] public async Task Can_Sign_In_Using_NetEase(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs index 980d438f0..efc71afe6 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Nextcloud/NextcloudTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Nextcloud; -public class NextcloudTests : OAuthTests +public class NextcloudTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public NextcloudTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => NextcloudAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -36,14 +31,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:nextcloud:language", "de")] [InlineData("urn:nextcloud:locale", "de_DE")] public async Task Can_Sign_In_Using_Nextcloud(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs index 3af6e785b..ca20113d3 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Notion/NotionTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.Notion; -public class NotionTests : OAuthTests +public class NotionTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public NotionTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => NotionAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddNotion(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddNotion(options => ConfigureDefaults(builder, options)); } [Theory] @@ -28,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:notion:workspace_icon", "icon")] [InlineData("urn:notion:bot_id", "mybot")] public async Task Can_Sign_In_Using_Notion(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs b/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs index c62cc12aa..b445a2d11 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs @@ -31,7 +31,7 @@ namespace AspNet.Security.OAuth; public abstract class OAuthTests : ITestOutputHelperAccessor where TOptions : OAuthOptions, new() { - protected OAuthTests() + protected OAuthTests(ITestOutputHelper outputHelper) { Interceptor = new HttpClientInterceptorOptions() .ThrowsOnMissingRegistration() @@ -43,6 +43,8 @@ protected OAuthTests() RedirectParameters = RedirectParameters, RedirectUri = RedirectUri, }; + + OutputHelper = outputHelper; } /// @@ -94,6 +96,19 @@ protected OAuthTests() /// The application. protected internal virtual void ConfigureApplication(IApplicationBuilder app) { + // No-op + } + + protected async Task AuthenticateUserAndAssertClaimValue(string claimType, string claimValue, Action? configureServices = null) + { + // Arrange + using var server = CreateTestServer(configureServices); + + // Act + var claims = await AuthenticateUserAsync(server); + + // Assert + AssertClaim(claims, claimType, claimValue); } /// @@ -329,7 +344,7 @@ protected async Task BuildChallengeUriAsync( var dataProtector = Substitute.For(); dataProtector.Protect(Arg.Any()) - .Returns(Array.Empty()); + .Returns([]); options.StateDataFormat ??= new PropertiesDataFormat(dataProtector); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs index 06ca89886..fe03ec707 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Odnoklassniki/OdnoklassnikiTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Odnoklassniki; -public class OdnoklassnikiTests : OAuthTests +public class OdnoklassnikiTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public OdnoklassnikiTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => OdnoklassnikiAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -39,16 +34,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:ok:image2", "https://i.mycdn.me/res/stub_128x96.gif")] [InlineData("urn:ok:image3", "https://i.mycdn.me/res/stub_128x96.gif")] public async Task Can_Sign_In_Using_Odnoklassniki(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs index f27966d8b..cd953ca8d 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Okta/OktaTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Okta; -public class OktaTests : OAuthTests +public class OktaTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public OktaTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => OktaAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,16 +26,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "00uid4BxXw6I6TV4m0g3")] [InlineData(ClaimTypes.Surname, "Doe")] public async Task Can_Sign_In_Using_Okta(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(ClaimTypes.Email, "jane.doe@example.com")] @@ -59,12 +45,6 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs index ad68474ea..7dcb4f15b 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Onshape/OnshapeTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Onshape; -public class OnshapeTests : OAuthTests +public class OnshapeTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public OnshapeTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => OnshapeAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -24,14 +19,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "my-id")] [InlineData(ClaimTypes.Name, "John Smith")] public async Task Can_Sign_In_Using_Onshape(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs index 03c2196d5..8024caf72 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/PackageMetadataTests.cs @@ -19,13 +19,13 @@ public static class PackageMetadataTests public static IEnumerable Projects() { - foreach (string directory in Directory.EnumerateDirectories(Path.Combine(_solutionRoot!, "src"))) + foreach (var directory in Directory.EnumerateDirectories(Path.Combine(_solutionRoot!, "src"))) { - foreach (string project in Directory.EnumerateFiles(directory, "*.csproj")) + foreach (var project in Directory.EnumerateFiles(directory, "*.csproj")) { - string projectName = Path.GetFileNameWithoutExtension(project); + var projectName = Path.GetFileNameWithoutExtension(project); - foreach (string propertyName in new[] { "Authors", "Description", "PackageTags" }) + foreach (var propertyName in new[] { "Authors", "Description", "PackageTags" }) { yield return new object[] { projectName, propertyName }; } @@ -38,7 +38,7 @@ public static IEnumerable Projects() public static async Task Project_Has_Expected_Package_Metadata(string projectName, string propertyName) { // Arrange - string path = Path.Combine(_solutionRoot!, "src", projectName, projectName) + ".csproj"; + var path = Path.Combine(_solutionRoot!, "src", projectName, projectName) + ".csproj"; using var stream = File.OpenRead(path); XElement project = await XElement.LoadAsync(stream, LoadOptions.None, CancellationToken.None); @@ -48,7 +48,7 @@ public static async Task Project_Has_Expected_Package_Metadata(string projectNam private static void AssertPackageMetadata(XElement project, string propertyName) { - bool found = false; + var found = false; foreach (XElement item in project.Descendants("PropertyGroup").Descendants()) { diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Patreon/PatreonTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Patreon/PatreonTests.cs index 5d1a76b98..f4498d090 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Patreon/PatreonTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Patreon/PatreonTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Patreon; -public class PatreonTests : OAuthTests +public class PatreonTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public PatreonTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => PatreonAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -29,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Webpage, "https://patreon.local/JohnSmith")] [InlineData("urn:patreon:avatar", "https://patreon.local/JohnSmith/avatar.png")] public async Task Can_Sign_In_Using_Patreon(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Paypal/PaypalTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Paypal/PaypalTests.cs index ab6eb2b55..27f742540 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Paypal/PaypalTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Paypal/PaypalTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Paypal; -public class PaypalTests : OAuthTests +public class PaypalTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public PaypalTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => PaypalAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -27,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.GivenName, "identity")] [InlineData(ClaimTypes.Surname, "test")] public async Task Can_Sign_In_Using_Paypal(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/PingOne/PingOneTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/PingOne/PingOneTests.cs index 7ad2bff69..6bc0f8aa7 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/PingOne/PingOneTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/PingOne/PingOneTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.PingOne; -public class PingOneTests : OAuthTests +public class PingOneTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public PingOneTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => PingOneAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,16 +26,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "00uid4BxXw6I6TV4m0g3")] [InlineData(ClaimTypes.Surname, "Doe")] public async Task Can_Sign_In_Using_PingOne(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(ClaimTypes.Email, "jane.doe@example.com")] @@ -59,12 +45,6 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/QQ/QQTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/QQ/QQTests.cs index aed28e738..4dc4e4bde 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/QQ/QQTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/QQ/QQTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.QQ; -public class QQTests : OAuthTests +public class QQTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public QQTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => QQAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -36,16 +31,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:qq:avatar_full", "https://qq.local/avatar-large.png")] [InlineData("urn:qq:unionid", "my-union-id")] public async Task Can_Sign_In_Using_QQ(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/QuickBooks/QuickBooksTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/QuickBooks/QuickBooksTests.cs index 0d9245039..c116dde2c 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/QuickBooks/QuickBooksTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/QuickBooks/QuickBooksTests.cs @@ -9,21 +9,13 @@ namespace AspNet.Security.OAuth.QuickBooksTests; -public class QuickBooksTests : OAuthTests +public class QuickBooksTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public QuickBooksTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => QuickBooksAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddQuickBooks(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddQuickBooks(options => ConfigureDefaults(builder, options)); } [Theory] @@ -35,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.GivenName, "John")] [InlineData(ClaimTypes.Surname, "Smith")] public async Task Can_Sign_In_Using_QuickBooks(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Reddit/RedditTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Reddit/RedditTests.cs index 01d32cc43..ba0e0650f 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Reddit/RedditTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Reddit/RedditTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Reddit; -public class RedditTests : OAuthTests +public class RedditTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public RedditTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => RedditAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -27,16 +22,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "John Smith")] [InlineData("urn:reddit:over18", "True")] public async Task Can_Sign_In_Using_Reddit(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Salesforce/SalesforceTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Salesforce/SalesforceTests.cs index f8127d4e1..4dd3187ed 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Salesforce/SalesforceTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Salesforce/SalesforceTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Salesforce; -public class SalesforceTests : OAuthTests +public class SalesforceTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public SalesforceTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => SalesforceAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:salesforce:thumbnail_photo", "https://yourInstance.salesforce.com/profilephoto/005/T")] [InlineData("urn:salesforce:utc_offset", "-28800000")] public async Task Can_Sign_In_Using_Salesforce(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/ServiceChannel/ServiceChannelTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/ServiceChannel/ServiceChannelTests.cs index 0e5fa175e..ae9dd5cdc 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/ServiceChannel/ServiceChannelTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/ServiceChannel/ServiceChannelTests.cs @@ -4,32 +4,17 @@ * for more information concerning the license and the contributors participating to this project. */ -using System.Security.Claims; -using System.Threading.Tasks; -using AspNet.Security.OAuth.ServiceChannel; -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.DependencyInjection; -using Xunit; -using Xunit.Abstractions; using static AspNet.Security.OAuth.ServiceChannel.ServiceChannelAuthenticationConstants; namespace AspNet.Security.OAuth.ServiceChannel; -public class ServiceChannelTests : OAuthTests +public class ServiceChannelTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public ServiceChannelTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => ServiceChannelAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddServiceChannel(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddServiceChannel(options => ConfigureDefaults(builder, options)); } [Theory] @@ -39,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.ProviderId, "2000156703")] [InlineData(Claims.ProviderName, "uicccf")] public async Task Can_Sign_In_Using_ServiceChannel(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Shopify/ShopifyTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Shopify/ShopifyTests.cs index 5ef103d2c..127248864 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Shopify/ShopifyTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Shopify/ShopifyTests.cs @@ -15,8 +15,8 @@ public class ShopifyTests : OAuthTests private const string TestShopName = "apple"; public ShopifyTests(ITestOutputHelper outputHelper) + : base(outputHelper) { - OutputHelper = outputHelper; LoopbackRedirectHandler.LoopbackParameters.Add("shop", "apple.myshopify.com"); } @@ -45,16 +45,7 @@ protected override void ConfigureDefaults(AuthenticationBuilder builder, Shopify [InlineData(ClaimTypes.NameIdentifier, "apple.myshopify.com")] [InlineData("urn:shopify:plan_name", "enterprise")] public async Task Can_Sign_In_Using_Shopify(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Slack/SlackTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Slack/SlackTests.cs index 6c0e43e0c..8807487a4 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Slack/SlackTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Slack/SlackTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Slack; -public class SlackTests : OAuthTests +public class SlackTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public SlackTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => SlackAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -34,14 +29,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:slack:team_name", "Captain Fabian's Naval Supply")] [InlineData("urn:slack:user_id", "U0G9QF9C6")] public async Task Can_Sign_In_Using_Slack(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Smartsheet/SmartsheetTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Smartsheet/SmartsheetTests.cs index fefa61bfa..219536b87 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Smartsheet/SmartsheetTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Smartsheet/SmartsheetTests.cs @@ -5,13 +5,8 @@ */ namespace AspNet.Security.OAuth.Smartsheet; -public class SmartsheetTests : OAuthTests +public class SmartsheetTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public SmartsheetTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => SmartsheetAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -26,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Email, "fred@example.com")] [InlineData(SmartsheetAuthenticationConstants.Claims.ProfileImage, "https://example.com/profile.png")] public async Task Can_Sign_In_Using_Smartsheet(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Snapchat/SnapchatTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Snapchat/SnapchatTests.cs index ea67129bd..e2b4b9665 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Snapchat/SnapchatTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Snapchat/SnapchatTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.Snapchat; -public class SnapchatTests : OAuthTests +public class SnapchatTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public SnapchatTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => SnapchatAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddSnapchat(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddSnapchat(options => ConfigureDefaults(builder, options)); } [Theory] @@ -31,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("organization_id", "id")] [InlineData("id", "id")] public async Task Can_Sign_In_Using_Snapchat(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/SoundCloud/SoundCloudTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/SoundCloud/SoundCloudTests.cs index ba0057484..972885acf 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/SoundCloud/SoundCloudTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/SoundCloud/SoundCloudTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.SoundCloud; -public class SoundCloudTests : OAuthTests +public class SoundCloudTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public SoundCloudTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => SoundCloudAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:soundcloud:fullname", "John Q Smith")] [InlineData("urn:soundcloud:profileurl", "https://soundcloud.local/JohnSmith")] public async Task Can_Sign_In_Using_SoundCloud(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Spotify/SpotifyTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Spotify/SpotifyTests.cs index 57099b99e..efb37b089 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Spotify/SpotifyTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Spotify/SpotifyTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Spotify; -public class SpotifyTests : OAuthTests +public class SpotifyTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public SpotifyTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => SpotifyAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,14 +26,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:spotify:url", "https://open.spotify.com/user/wizzler")] [InlineData("urn:spotify:profilepicture", "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/t1.0-1/1970403_10152215092574354_1798272330_n.jpg")] public async Task Can_Sign_In_Using_Spotify(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/StackExchange/StackExchangeTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/StackExchange/StackExchangeTests.cs index 3f8ae5108..d5bcd183c 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/StackExchange/StackExchangeTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/StackExchange/StackExchangeTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.StackExchange; -public class StackExchangeTests : OAuthTests +public class StackExchangeTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public StackExchangeTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => StackExchangeAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -30,14 +25,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Webpage, "https://example.com/")] [InlineData("urn:stackexchange:link", "https://example.stackexchange.com/users/1/example-user")] public async Task Can_Sign_In_Using_StackExchange(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/StaticAnalysisTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/StaticAnalysisTests.cs index 1b5956be4..938ae753f 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/StaticAnalysisTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/StaticAnalysisTests.cs @@ -12,7 +12,7 @@ namespace AspNet.Security.OAuth; public static class StaticAnalysisTests { #if JETBRAINS_ANNOTATIONS - [Xunit.Fact] + [Fact] #endif public static void Publicly_Visible_Parameters_Have_Null_Annotations() { @@ -21,7 +21,7 @@ public static void Publicly_Visible_Parameters_Have_Null_Annotations() var types = GetPublicTypes(assemblyNames); var nullabilityContext = new NullabilityInfoContext(); - int testedMethods = 0; + var testedMethods = 0; // Act foreach (var type in types) @@ -34,7 +34,7 @@ public static void Publicly_Visible_Parameters_Have_Null_Annotations() foreach (var parameter in parameters) { - bool hasNullabilityAnnotation = parameter + var hasNullabilityAnnotation = parameter .GetCustomAttributes() .Any((p) => p.GetType().FullName == "JetBrains.Annotations.CanBeNullAttribute" || p.GetType().FullName == "JetBrains.Annotations.NotNullAttribute"); diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Strava/StravaTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Strava/StravaTests.cs index b62ecd3fd..be5183175 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Strava/StravaTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Strava/StravaTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Strava; -public class StravaTests : OAuthTests +public class StravaTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public StravaTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => StravaAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -38,16 +33,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:strava:profile-medium", "https://strava.local/images/JohnSmith-medium.png")] [InlineData("urn:strava:updated-at", "2019-03-17T16:13:00+00:00")] public async Task Can_Sign_In_Using_Strava(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Streamlabs/StreamlabsTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Streamlabs/StreamlabsTests.cs index cd6c81b92..49df2e2c9 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Streamlabs/StreamlabsTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Streamlabs/StreamlabsTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Streamlabs; -public class StreamlabsTests : OAuthTests +public class StreamlabsTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public StreamlabsTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => StreamlabsAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -37,16 +32,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:streamlabs:youtubeid", "UCC8H-NrBvYEqZ5KG-jzS_Oy")] [InlineData("urn:streamlabs:youtubetitle", "Sertay")] public async Task Can_Sign_In_Using_Streamlabs(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/SuperOffice/SuperOfficeTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/SuperOffice/SuperOfficeTests.cs index 408d38052..8fa46c44d 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/SuperOffice/SuperOfficeTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/SuperOffice/SuperOfficeTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.SuperOffice; -public class SuperOfficeTests : OAuthTests +public class SuperOfficeTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public SuperOfficeTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => SuperOfficeAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -47,16 +42,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(SuperOfficeAuthenticationConstants.PrincipalNames.RoleName, "User level 0")] [InlineData(SuperOfficeAuthenticationConstants.PrincipalNames.SecondaryGroups, "2")] public async Task Can_Sign_In_Using_SuperOffice(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(SuperOfficeAuthenticationConstants.PrincipalNames.ContextIdentifier, "Cust12345")] @@ -73,13 +59,7 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Fact] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Trakt/TraktTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Trakt/TraktTests.cs index a1cda366b..802da3e6a 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Trakt/TraktTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Trakt/TraktTests.cs @@ -6,21 +6,13 @@ namespace AspNet.Security.OAuth.Trakt; -public class TraktTests : OAuthTests +public class TraktTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public TraktTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => TraktAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) { - builder.AddTrakt(options => - { - ConfigureDefaults(builder, options); - }); + builder.AddTrakt(options => ConfigureDefaults(builder, options)); } [Theory] @@ -30,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:trakt:vip_ep", "True")] [InlineData("urn:trakt:private", "False")] public async Task Can_Sign_In_Using_Trakt(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Trovo/TrovoTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Trovo/TrovoTests.cs index 292c14fde..138e833c8 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Trovo/TrovoTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Trovo/TrovoTests.cs @@ -9,13 +9,8 @@ namespace AspNet.Security.OAuth.Trovo; -public class TrovoTests : OAuthTests +public class TrovoTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public TrovoTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => TrovoAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,16 +26,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(Claims.ProfilePic, "https://headicon.trovo.live/user/cxq7kbiaaaaabd5cniezh3x5cu.jpeg?t=2")] [InlineData(Claims.ChannelId, "100000021")] public async Task Can_Sign_In_Using_Trovo(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Twitch/TwitchTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Twitch/TwitchTests.cs index d95bbf025..2765b81f9 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Twitch/TwitchTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Twitch/TwitchTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Twitch; -public class TwitchTests : OAuthTests +public class TwitchTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public TwitchTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => TwitchAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -33,16 +28,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:twitch:profileimageurl", "https://static-cdn.jtvnw.net/jtv_user_pictures/dallas-profile_image-1a2c906ee2c35f12-300x300.png")] [InlineData("urn:twitch:type", "staff")] public async Task Can_Sign_In_Using_Twitch(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false, false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Twitter/TwitterTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Twitter/TwitterTests.cs index df067fe47..148346069 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Twitter/TwitterTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Twitter/TwitterTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Twitter; -public class TwitterTests : OAuthTests +public class TwitterTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public TwitterTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => TwitterAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -32,14 +27,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Name, "TwitterDev")] [InlineData("urn:twitter:name", "Twitter Dev")] public async Task Can_Sign_In_Using_Twitter(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Untappd/UntappdTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Untappd/UntappdTests.cs index 03e94fcdb..852b7ae46 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Untappd/UntappdTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Untappd/UntappdTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Untappd; -public class UntappdTests : OAuthTests +public class UntappdTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public UntappdTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => UntappdAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Webpage, "https://untappd.local/JohnSmith")] [InlineData("urn:untappd:link", "https://untappd.local/john-smith.png")] public async Task Can_Sign_In_Using_Untappd(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Vimeo/VimeoTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Vimeo/VimeoTests.cs index 1f65e5fbf..a66404986 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Vimeo/VimeoTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Vimeo/VimeoTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Vimeo; -public class VimeoTests : OAuthTests +public class VimeoTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public VimeoTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => VimeoAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -25,14 +20,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:vimeo:fullname", "John Smith")] [InlineData("urn:vimeo:profileurl", "https://vimeo.local/JohnSmith")] public async Task Can_Sign_In_Using_Vimeo(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/VisualStudio/VisualStudioTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/VisualStudio/VisualStudioTests.cs index 637b8a829..98465e9ac 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/VisualStudio/VisualStudioTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/VisualStudio/VisualStudioTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.VisualStudio; -public class VisualStudioTests : OAuthTests +public class VisualStudioTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public VisualStudioTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => VisualStudioAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,16 +23,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Email, "john@john-smith.local")] [InlineData(ClaimTypes.GivenName, "John")] public async Task Can_Sign_In_Using_Visual_Studio(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Vkontakte/VkontakteTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Vkontakte/VkontakteTests.cs index da34bb206..02536cc70 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Vkontakte/VkontakteTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Vkontakte/VkontakteTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Vkontakte; -public class VkontakteTests : OAuthTests +public class VkontakteTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public VkontakteTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => VkontakteAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -29,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:vkontakte:photo:link", "https://vk.local/photo.png")] [InlineData("urn:vkontakte:photo_thumb:link", "https://vk.local/thumbnail.png")] public async Task Can_Sign_In_Using_Vkontakte(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Weibo/WeiboTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Weibo/WeiboTests.cs index a28a62926..f380285cc 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Weibo/WeiboTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Weibo/WeiboTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Weibo; -public class WeiboTests : OAuthTests +public class WeiboTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public WeiboTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => WeiboAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -38,16 +33,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:weibo:profile_image_url", "https://weibo.local/profile.png")] [InlineData("urn:weibo:screen_name", "JohnSmith")] public async Task Can_Sign_In_Using_Weibo(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Weixin/WeixinTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Weixin/WeixinTests.cs index 4430e1a4c..9f8e6ceac 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Weixin/WeixinTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Weixin/WeixinTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Weixin; -public class WeixinTests : OAuthTests +public class WeixinTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public WeixinTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => WeixinAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -33,16 +28,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:weixin:privilege", "a,b,c")] [InlineData("urn:weixin:province", "Hebei")] public async Task Can_Sign_In_Using_Weixin(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(ClaimTypes.NameIdentifier, "my-id")] @@ -65,13 +51,7 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Theory] @@ -96,13 +76,7 @@ static void ConfigureServices(IServiceCollection services) }); } - using var server = CreateTestServer(ConfigureServices); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); + await AuthenticateUserAndAssertClaimValue(claimType, claimValue, ConfigureServices); } [Theory] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/WordPress/WordPressTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/WordPress/WordPressTests.cs index 88a885930..5efac2635 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/WordPress/WordPressTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/WordPress/WordPressTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.WordPress; -public class WordPressTests : OAuthTests +public class WordPressTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public WordPressTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => WordPressAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -29,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:wordpress:primaryblog", "https://john-smith.wordpress.local")] [InlineData("urn:wordpress:profileurl", "https://www.wordpress.local/john-smith")] public async Task Can_Sign_In_Using_WordPress(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/WorkWeixin/WorkWeixinTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/WorkWeixin/WorkWeixinTests.cs index f076b1f34..08c1e3f2a 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/WorkWeixin/WorkWeixinTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/WorkWeixin/WorkWeixinTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.WorkWeixin; -public class WorkWeixinTests : OAuthTests +public class WorkWeixinTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public WorkWeixinTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => WorkWeixinAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -31,16 +26,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:workweixin:mobile", "888888")] [InlineData("urn:workweixin:alias", "my-alias")] public async Task Can_Sign_In_Using_WorkWeixin(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Xero/XeroTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Xero/XeroTests.cs index bf41defe2..2e59e4467 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Xero/XeroTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Xero/XeroTests.cs @@ -9,13 +9,8 @@ namespace AspNet.Security.OAuth.Xero; -public class XeroTests : OAuthTests +public class XeroTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public XeroTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => XeroAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -43,16 +38,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("sid", "c37c8dce142c4ce98c1d646df83dafeb")] [InlineData("global_session_id", "c37c8dce142c4ce98c1d646df83dafeb")] public async Task Can_Sign_In_Using_Xero(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Xumm/XummTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Xumm/XummTests.cs index 5727f9514..b705137f2 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Xumm/XummTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Xumm/XummTests.cs @@ -4,17 +4,10 @@ * for more information concerning the license and the contributors participating to this project. */ -using Microsoft.AspNetCore.WebUtilities; - namespace AspNet.Security.OAuth.Xumm; -public class XummTests : OAuthTests +public class XummTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public XummTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => XummAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +21,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Email, "john.smith@xumm.me")] [InlineData(XummAuthenticationConstants.Claims.Picture, "Avatar")] public async Task Can_Sign_In_Using_Xumm(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Yahoo/YahooTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Yahoo/YahooTests.cs index 3fee31be4..e79ed3442 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Yahoo/YahooTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Yahoo/YahooTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Yahoo; -public class YahooTests : OAuthTests +public class YahooTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public YahooTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => YahooAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,14 +23,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:yahoo:givenname", "John")] [InlineData("urn:yahoo:picture", "https://www.yahoo.local/JohnSmith/image.png")] public async Task Can_Sign_In_Using_Yahoo(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Yammer/YammerTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Yammer/YammerTests.cs index f0dc6596e..d8f8b1105 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Yammer/YammerTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Yammer/YammerTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Yammer; -public class YammerTests : OAuthTests +public class YammerTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public YammerTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => YammerAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -29,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData("urn:yammer:link", "https://www.yammer.com")] [InlineData("urn:yammer:job_title", "Developer")] public async Task Can_Sign_In_Using_Yammer(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Yandex/YandexTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Yandex/YandexTests.cs index 53ef05fcb..80720166b 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Yandex/YandexTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Yandex/YandexTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Yandex; -public class YandexTests : OAuthTests +public class YandexTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public YandexTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => YandexAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -27,14 +22,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.GivenName, "John")] [InlineData(ClaimTypes.Surname, "Smith")] public async Task Can_Sign_In_Using_Yandex(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); } diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Zalo/ZaloTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Zalo/ZaloTests.cs index e7aa96269..2f91902a8 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Zalo/ZaloTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Zalo/ZaloTests.cs @@ -8,13 +8,8 @@ namespace AspNet.Security.OAuth.Zalo; -public class ZaloTests : OAuthTests +public class ZaloTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public ZaloTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => ZaloAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -28,16 +23,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.Gender, "male")] [InlineData(ClaimTypes.DateOfBirth, "1987-02-01")] public async Task Can_Sign_In_Using_Zalo(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); [Theory] [InlineData(false)] diff --git a/test/AspNet.Security.OAuth.Providers.Tests/Zendesk/ZendeskTests.cs b/test/AspNet.Security.OAuth.Providers.Tests/Zendesk/ZendeskTests.cs index 5ed95d8f2..5025f7d96 100644 --- a/test/AspNet.Security.OAuth.Providers.Tests/Zendesk/ZendeskTests.cs +++ b/test/AspNet.Security.OAuth.Providers.Tests/Zendesk/ZendeskTests.cs @@ -6,13 +6,8 @@ namespace AspNet.Security.OAuth.Zendesk; -public class ZendeskTests : OAuthTests +public class ZendeskTests(ITestOutputHelper outputHelper) : OAuthTests(outputHelper) { - public ZendeskTests(ITestOutputHelper outputHelper) - { - OutputHelper = outputHelper; - } - public override string DefaultScheme => ZendeskAuthenticationDefaults.AuthenticationScheme; protected internal override void RegisterAuthentication(AuthenticationBuilder builder) @@ -29,14 +24,5 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu [InlineData(ClaimTypes.NameIdentifier, "35436")] [InlineData(ClaimTypes.Email, "johnnyagent@zendesk.com")] public async Task Can_Sign_In_Using_Zendesk(string claimType, string claimValue) - { - // Arrange - using var server = CreateTestServer(); - - // Act - var claims = await AuthenticateUserAsync(server); - - // Assert - AssertClaim(claims, claimType, claimValue); - } + => await AuthenticateUserAndAssertClaimValue(claimType, claimValue); }