Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ArgumentNullException.ThrowIfNull #1367

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace ApiTemplate;
using System.Reflection;
using Boxed.AspNetCore;

public static class ConfigurationBuilderExtensions
internal static class ConfigurationBuilderExtensions
{
public static IConfigurationBuilder AddCustomBootstrapConfiguration(
this IConfigurationBuilder configurationBuilder, string[] args) =>
Expand Down
2 changes: 1 addition & 1 deletion Source/ApiTemplate/Source/ApiTemplate/HostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace ApiTemplate;

using System.Runtime.InteropServices;

public static class HostExtensions
internal static class HostExtensions
{
public static void LogApplicationStarted(this IHost host)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ApiTemplate;
/// AddScoped - A new instance is created and returned for each request/response cycle.
/// AddTransient - A new instance is created and returned each time.
/// </remarks>
public static class ProjectServiceCollectionExtensions
internal static class ProjectServiceCollectionExtensions
{
public static IServiceCollection AddProjectCommands(this IServiceCollection services) =>
services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GraphQLTemplate;
using System.Reflection;
using Boxed.AspNetCore;

public static class ConfigurationBuilderExtensions
internal static class ConfigurationBuilderExtensions
{
public static IConfigurationBuilder AddCustomBootstrapConfiguration(
this IConfigurationBuilder configurationBuilder, string[] args) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace GraphQLTemplate;

using System.Runtime.InteropServices;

public static class HostExtensions
internal static class HostExtensions
{
public static void LogApplicationStarted(this IHost host)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace GraphQLTemplate;
using GraphQLTemplate.Options;
using Microsoft.AspNetCore.Mvc.Formatters;

public static class MvcBuilderExtensions
internal static class MvcBuilderExtensions
{
public static IMvcBuilder AddCustomMvcOptions(this IMvcBuilder builder, IConfiguration configuration) =>
builder.AddMvcOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OrleansTemplate.Server;
/// <summary>
/// <see cref="IConfigurationBuilder"/> extension methods.
/// </summary>
public static class ConfigurationBuilderExtensions
internal static class ConfigurationBuilderExtensions
{
public static IConfigurationBuilder AddCustomBootstrapConfiguration(
this IConfigurationBuilder configurationBuilder, string[] args) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace OrleansTemplate.Server;

using System.Runtime.InteropServices;

public static class HostExtensions
internal static class HostExtensions
{
public static void LogApplicationStarted(this IHost host)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OrleansTemplate.Server;
/// <summary>
/// <see cref="IServiceCollection"/> extension methods which extend ASP.NET Core services.
/// </summary>
public static class ServiceCollectionExtensions
internal static class ServiceCollectionExtensions
{
/// <summary>
/// Adds Open Telemetry services and configures instrumentation and exporters.
Expand All @@ -30,8 +30,8 @@ public static IServiceCollection AddCustomOpenTelemetryTracing(this IServiceColl
.AddAttributes(
new KeyValuePair<string, object>[]
{
new(OpenTelemetryAttributeName.Deployment.Environment, webHostEnvironment.EnvironmentName),
new(OpenTelemetryAttributeName.Host.Name, Environment.MachineName),
new(OpenTelemetryAttributeName.Deployment.Environment, webHostEnvironment.EnvironmentName),
new(OpenTelemetryAttributeName.Host.Name, Environment.MachineName),
}))
.AddAspNetCoreInstrumentation(
options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ public static ISiloBuilder UseIf(
bool condition,
Func<ISiloBuilder, ISiloBuilder> action)
{
if (siloBuilder is null)
{
throw new ArgumentNullException(nameof(siloBuilder));
}

if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
ArgumentNullException.ThrowIfNull(siloBuilder);
ArgumentNullException.ThrowIfNull(action);

if (condition)
{
Expand All @@ -51,20 +44,9 @@ public static ISiloBuilder UseIf(
Func<ISiloBuilder, bool> condition,
Func<ISiloBuilder, ISiloBuilder> action)
{
if (siloBuilder is null)
{
throw new ArgumentNullException(nameof(siloBuilder));
}

if (condition is null)
{
throw new ArgumentNullException(nameof(condition));
}

if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
ArgumentNullException.ThrowIfNull(siloBuilder);
ArgumentNullException.ThrowIfNull(condition);
ArgumentNullException.ThrowIfNull(action);

if (condition(siloBuilder))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@ public class TraceIdEnricher : ILogEventEnricher
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent is null)
{
throw new ArgumentNullException(nameof(logEvent));
}

if (propertyFactory is null)
{
throw new ArgumentNullException(nameof(propertyFactory));
}
ArgumentNullException.ThrowIfNull(logEvent);
ArgumentNullException.ThrowIfNull(propertyFactory);

var traceId = RequestContext.Get("TraceId");
var property = propertyFactory.CreateProperty("TraceId", traceId);
Expand Down
5 changes: 1 addition & 4 deletions Tests/Boxed.Templates.FunctionalTest/ApiTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public class ApiTemplateTest

public ApiTemplateTest(ITestOutputHelper testOutputHelper)
{
if (testOutputHelper is null)
{
throw new ArgumentNullException(nameof(testOutputHelper));
}
ArgumentNullException.ThrowIfNull(testOutputHelper);

TestLogger.WriteMessage = testOutputHelper.WriteLine;
}
Expand Down
5 changes: 1 addition & 4 deletions Tests/Boxed.Templates.FunctionalTest/GraphQLTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public class GraphQLTemplateTest

public GraphQLTemplateTest(ITestOutputHelper testOutputHelper)
{
if (testOutputHelper is null)
{
throw new ArgumentNullException(nameof(testOutputHelper));
}
ArgumentNullException.ThrowIfNull(testOutputHelper);

TestLogger.WriteMessage = testOutputHelper.WriteLine;
}
Expand Down
5 changes: 1 addition & 4 deletions Tests/Boxed.Templates.FunctionalTest/NuGetTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public class NuGetTemplateTest

public NuGetTemplateTest(ITestOutputHelper testOutputHelper)
{
if (testOutputHelper is null)
{
throw new ArgumentNullException(nameof(testOutputHelper));
}
ArgumentNullException.ThrowIfNull(testOutputHelper);

TestLogger.WriteMessage = testOutputHelper.WriteLine;
}
Expand Down
5 changes: 1 addition & 4 deletions Tests/Boxed.Templates.FunctionalTest/OrleansTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public class OrleansTemplateTest

public OrleansTemplateTest(ITestOutputHelper testOutputHelper)
{
if (testOutputHelper is null)
{
throw new ArgumentNullException(nameof(testOutputHelper));
}
ArgumentNullException.ThrowIfNull(testOutputHelper);

TestLogger.WriteMessage = testOutputHelper.WriteLine;
}
Expand Down
33 changes: 6 additions & 27 deletions Tests/Boxed.Templates.FunctionalTest/ReadinessCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ public static class ReadinessCheck
{
public static async Task<bool> StatusSelfAsync(HttpClient httpClient, HttpClient httpsClient)
{
if (httpClient is null)
{
throw new ArgumentNullException(nameof(httpClient));
}

if (httpsClient is null)
{
throw new ArgumentNullException(nameof(httpsClient));
}
ArgumentNullException.ThrowIfNull(httpClient);
ArgumentNullException.ThrowIfNull(httpsClient);

try
{
Expand All @@ -37,15 +30,8 @@ public static async Task<bool> StatusSelfAsync(HttpClient httpClient, HttpClient

public static async Task<bool> StatusSelfOverHttpAsync(HttpClient httpClient, HttpClient httpsClient)
{
if (httpClient is null)
{
throw new ArgumentNullException(nameof(httpClient));
}

if (httpsClient is null)
{
throw new ArgumentNullException(nameof(httpsClient));
}
ArgumentNullException.ThrowIfNull(httpClient);
ArgumentNullException.ThrowIfNull(httpsClient);

try
{
Expand All @@ -64,15 +50,8 @@ public static async Task<bool> StatusSelfOverHttpAsync(HttpClient httpClient, Ht

public static async Task<bool> FaviconAsync(HttpClient httpClient, HttpClient httpsClient)
{
if (httpClient is null)
{
throw new ArgumentNullException(nameof(httpClient));
}

if (httpsClient is null)
{
throw new ArgumentNullException(nameof(httpsClient));
}
ArgumentNullException.ThrowIfNull(httpClient);
ArgumentNullException.ThrowIfNull(httpsClient);

try
{
Expand Down