Skip to content

Commit

Permalink
More ArgumentNullException updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSmoke committed Oct 3, 2023
1 parent 5a61c56 commit f2d1e04
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static class ServiceCollectionExtensions
/// <exception cref="ArgumentNullException"></exception>
public static void AddAjaxServices(this IServiceCollection services)
{
if (services == null)
throw new ArgumentNullException(nameof(services));
ArgumentNullException.ThrowIfNull(services);

// Register the 401/403 handler
services.AddTransient<IAuthorizationMiddlewareResultHandler, AjaxAuthorizationMiddlewareResultHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class InMemoryUserSessionStore : IUserSessionStore

public Task<UserSession?> GetAsync(string key, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
ArgumentNullException.ThrowIfNull(key);

token.ThrowIfCancellationRequested();

Expand All @@ -35,8 +34,7 @@ public class InMemoryUserSessionStore : IUserSessionStore

public Task AddAsync(UserSession session, CancellationToken token = default)
{
if (session == null)
throw new ArgumentNullException(nameof(session));
ArgumentNullException.ThrowIfNull(session);

token.ThrowIfCancellationRequested();

Expand All @@ -47,11 +45,8 @@ public Task AddAsync(UserSession session, CancellationToken token = default)

public Task UpdateAsync(string key, UserSession session, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));

if (session == null)
throw new ArgumentNullException(nameof(session));
ArgumentNullException.ThrowIfNull(key);
ArgumentNullException.ThrowIfNull(session);

token.ThrowIfCancellationRequested();

Expand All @@ -62,8 +57,7 @@ public Task UpdateAsync(string key, UserSession session, CancellationToken token

public Task DeleteAsync(string key, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
ArgumentNullException.ThrowIfNull(key);

token.ThrowIfCancellationRequested();

Expand All @@ -74,8 +68,7 @@ public Task DeleteAsync(string key, CancellationToken token = default)

public Task DeleteBySessionIdAsync(string sessionId, CancellationToken token = default)
{
if (sessionId == null)
throw new ArgumentNullException(nameof(sessionId));
ArgumentNullException.ThrowIfNull(sessionId);

token.ThrowIfCancellationRequested();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private UserSession CreateUserSession(string key, AuthenticationTicket ticket)
if (string.IsNullOrWhiteSpace(key))
throw new InvalidOperationException("Invalid key");

if (ticket == null)
throw new ArgumentNullException(nameof(ticket));
ArgumentNullException.ThrowIfNull(ticket);

var subject = ticket.Principal.FindFirst(JwtClaimTypes.Subject)?.Value;
var sessionId = ticket.Principal.FindFirst(JwtClaimTypes.SessionId)?.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ public static OpenIdConnectSessionHandlerBuilder AddOpenIdConnectSessionHandler(
this IServiceCollection services,
Action<OpenIdConnectSessionHandlerOptions> configure)
{
if (services == null)
throw new ArgumentNullException(nameof(services));

if (configure == null)
throw new ArgumentNullException(nameof(configure));
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configure);

services.AddOptions<OpenIdConnectSessionHandlerOptions>()
.Validate(o =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ public static OpenIdConnectSessionHandlerBuilder AddStackExchangeRedisUserSessio
this OpenIdConnectSessionHandlerBuilder builder,
Action<RedisUserSessionCacheOptions> configure)
{
if (builder == null)
throw new ArgumentNullException(nameof(builder));

if (configure == null)
throw new ArgumentNullException(nameof(configure));
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configure);

builder.Services.AddOptions<RedisUserSessionCacheOptions>()
.Validate(o =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ public class RedisUserSessionStore : IUserSessionStore

public RedisUserSessionStore(IOptions<RedisUserSessionCacheOptions> cacheOptions)
{
if (cacheOptions == null) throw new ArgumentNullException(nameof(cacheOptions));
ArgumentNullException.ThrowIfNull(cacheOptions);

var options = cacheOptions.Value;

if (options == null) throw new ArgumentException("Options cannot be null");

if (options.Connection == null) throw new ArgumentException("Connection cannot be null");

_database = options.Connection.GetDatabase();
Expand All @@ -32,8 +31,7 @@ public RedisUserSessionStore(IOptions<RedisUserSessionCacheOptions> cacheOptions

public async Task AddAsync(UserSession session, CancellationToken token = default)
{
if (session == null)
throw new ArgumentNullException(nameof(session));
ArgumentNullException.ThrowIfNull(session);

token.ThrowIfCancellationRequested();

Expand All @@ -47,11 +45,8 @@ public async Task AddAsync(UserSession session, CancellationToken token = defaul

public async Task UpdateAsync(string key, UserSession session, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));

if (session == null)
throw new ArgumentNullException(nameof(session));
ArgumentNullException.ThrowIfNull(key);
ArgumentNullException.ThrowIfNull(session);

token.ThrowIfCancellationRequested();

Expand All @@ -70,8 +65,7 @@ public async Task UpdateAsync(string key, UserSession session, CancellationToken

public async Task DeleteAsync(string key, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
ArgumentNullException.ThrowIfNull(key);

token.ThrowIfCancellationRequested();

Expand All @@ -87,8 +81,7 @@ public async Task DeleteAsync(string key, CancellationToken token = default)

public async Task DeleteBySessionIdAsync(string sessionId, CancellationToken token = default)
{
if (sessionId == null)
throw new ArgumentNullException(nameof(sessionId));
ArgumentNullException.ThrowIfNull(sessionId);

token.ThrowIfCancellationRequested();

Expand All @@ -108,8 +101,7 @@ public async Task DeleteBySessionIdAsync(string sessionId, CancellationToken tok

private async Task<UserSession?> GetInternalAsync(string key, CancellationToken token = default)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
ArgumentNullException.ThrowIfNull(key);

token.ThrowIfCancellationRequested();

Expand Down

0 comments on commit f2d1e04

Please sign in to comment.