Skip to content

Commit 2ada567

Browse files
committed
fix: analyzer errors
1 parent fcfcb50 commit 2ada567

File tree

7 files changed

+61
-29
lines changed

7 files changed

+61
-29
lines changed

src/RapidIntegrationTesting.Utility/Extensions/IntegrationTestExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class IntegrationTestExtensions
1616
/// <exception cref="ArgumentNullException"></exception>
1717
public static string GetRelativePathToController(this string controllerName, string apiVersion = "1.0")
1818
{
19-
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
19+
ArgumentNullException.ThrowIfNull(controllerName);
2020
return $"api/v{apiVersion}/{controllerName.Replace("Controller", "", StringComparison.OrdinalIgnoreCase)}";
2121
}
2222

@@ -29,7 +29,7 @@ public static string GetRelativePathToController(this string controllerName, str
2929
[SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Pointless if it was URI")]
3030
public static Uri AsRelativeUri(this string url)
3131
{
32-
if (url == null) throw new ArgumentNullException(nameof(url));
32+
ArgumentNullException.ThrowIfNull(url);
3333
return new Uri(url, UriKind.Relative);
3434
}
3535

@@ -43,8 +43,8 @@ public static Uri AsRelativeUri(this string url)
4343
[SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Pointless if it was URI")]
4444
public static Uri AsRelativeUri(this string url, Dictionary<string, string> queryParams)
4545
{
46-
if (url == null) throw new ArgumentNullException(nameof(url));
47-
if (queryParams == null) throw new ArgumentNullException(nameof(queryParams));
46+
ArgumentNullException.ThrowIfNull(url);
47+
ArgumentNullException.ThrowIfNull(queryParams);
4848
string paramString = queryParams.Count == 0
4949
? string.Empty
5050
: "?" + string.Join('&', queryParams.Select(x => $"{x.Key}={x.Value}"));
@@ -63,8 +63,8 @@ public static Uri AsRelativeUri(this string url, Dictionary<string, string> quer
6363
[SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Pointless if it was URI")]
6464
public static Uri AsRelativeUri(this string url, params (string key, string value)[] queryParams)
6565
{
66-
if (url == null) throw new ArgumentNullException(nameof(url));
67-
if (queryParams == null) throw new ArgumentNullException(nameof(queryParams));
66+
ArgumentNullException.ThrowIfNull(url);
67+
ArgumentNullException.ThrowIfNull(queryParams);
6868
string paramString = queryParams.Length == 0
6969
? string.Empty
7070
: "?" + string.Join('&', queryParams.Select(x => $"{x.key}={x.value}"));

src/RapidIntegrationTesting.Utility/Seeder/TestSeeder.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public TestSeeder<TDbContext> Unseed<TEntity>(IdRetriever idRetriever)
6565
/// <param name="idRetriever">A function to retrieve the entity's id</param>
6666
protected void Create<T>(T entity, EntityIdRetriever<T> idRetriever) where T : class
6767
{
68-
if (idRetriever == null) throw new ArgumentNullException(nameof(idRetriever));
68+
ArgumentNullException.ThrowIfNull(idRetriever);
6969
object[] id = idRetriever(entity);
7070
DbContext.Set<T>().Add(entity);
7171
_unseeder.Add(new UnseedInfo(typeof(T), () => id));
@@ -119,8 +119,7 @@ protected void Create<T>(T entity, EntityIdRetriever<T> idRetriever) where T : c
119119
protected T FindRequiredCreated<T>(Func<T, bool> predicate) where T : class
120120
{
121121
T? entity = FindCreated(predicate);
122-
if (entity is null) throw new InvalidOperationException("Entity could not be found");
123-
return entity;
122+
return entity ?? throw new InvalidOperationException("Entity could not be found");
124123
}
125124

126125
/// <summary>
@@ -133,7 +132,6 @@ protected T FindRequiredCreated<T>(Func<T, bool> predicate) where T : class
133132
protected T FindRequiredCreated<T>(params object[] keyValues) where T : class
134133
{
135134
T? entity = FindCreated<T>(keyValues);
136-
if (entity is null) throw new InvalidOperationException("Entity could not be found");
137-
return entity;
135+
return entity ?? throw new InvalidOperationException("Entity could not be found");
138136
}
139137
}

src/RapidIntegrationTesting/RapidIntegrationTesting.xml

Lines changed: 41 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RapidIntegrationTesting/SignalR/SignalRCallbackDescriptorExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class SignalRCallbackDescriptorExtensions
1515
/// <exception cref="ArgumentNullException"></exception>
1616
public static void RegisterDescriptors(this HubConnection hubConnection, params ISignalRCallbackDescriptor[] descriptors)
1717
{
18-
if (descriptors == null) throw new ArgumentNullException(nameof(descriptors));
18+
ArgumentNullException.ThrowIfNull(descriptors);
1919
foreach (ISignalRCallbackDescriptor signalrCallbackDescriptor in descriptors)
2020
signalrCallbackDescriptor.Setup(hubConnection);
2121
}
@@ -30,7 +30,7 @@ public static void RegisterDescriptors(this HubConnection hubConnection, params
3030
/// <exception cref="ArgumentNullException"></exception>
3131
public static HubConnection Build(this IHubConnectionBuilder builder, params ISignalRCallbackDescriptor[] descriptors)
3232
{
33-
if (builder == null) throw new ArgumentNullException(nameof(builder));
33+
ArgumentNullException.ThrowIfNull(builder);
3434
HubConnection hubConnection = builder.Build();
3535
hubConnection.RegisterDescriptors(descriptors);
3636
return hubConnection;

src/RapidIntegrationTesting/SignalR/SignalRCallbackDescriptorFactory.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class SignalRCallbackDescriptorFactory
1818
/// <exception cref="ArgumentNullException"></exception>
1919
public static ISignalRCallbackDescriptor Create<TInterface>(Expression<Func<TInterface, Task>> expression, Action handler)
2020
{
21-
if (expression == null) throw new ArgumentNullException(nameof(expression));
21+
ArgumentNullException.ThrowIfNull(expression);
2222

2323
string name = expression.GetNameAndEnsureParameters(0);
2424
return new SignalRCallbackDescriptorNoValue(name, handler);
@@ -34,8 +34,7 @@ public static ISignalRCallbackDescriptor Create<TInterface>(Expression<Func<TInt
3434
/// <exception cref="ArgumentNullException"></exception>
3535
public static ISignalRCallbackDescriptor Create<TInterface>(Expression<Func<TInterface, Task>> expression, Func<Task> handler)
3636
{
37-
if (expression == null)
38-
throw new ArgumentNullException(nameof(expression));
37+
ArgumentNullException.ThrowIfNull(expression);
3938

4039
string name = expression.GetNameAndEnsureParameters(0);
4140
return new SignalRAsyncCallbackDescriptorNoValue(name, handler);
@@ -52,7 +51,7 @@ public static ISignalRCallbackDescriptor Create<TInterface>(Expression<Func<TInt
5251
/// <exception cref="ArgumentNullException"></exception>
5352
public static ISignalRCallbackDescriptor Create<TInterface, TArgument>(Expression<Func<TInterface, TArgument, Task>> expression, Action<TArgument> handler)
5453
{
55-
if (expression == null) throw new ArgumentNullException(nameof(expression));
54+
ArgumentNullException.ThrowIfNull(expression);
5655

5756
string name = expression.GetNameAndEnsureParameters(1, typeof(TArgument));
5857
return new SignalRCallbackDescriptor<TArgument>(name, handler);
@@ -69,8 +68,7 @@ public static ISignalRCallbackDescriptor Create<TInterface, TArgument>(Expressio
6968
/// <exception cref="ArgumentNullException"></exception>
7069
public static ISignalRCallbackDescriptor Create<TInterface, TArgument>(Expression<Func<TInterface, TArgument, Task>> expression, Func<TArgument, Task> handler)
7170
{
72-
if (expression == null)
73-
throw new ArgumentNullException(nameof(expression));
71+
ArgumentNullException.ThrowIfNull(expression);
7472

7573
string name = expression.GetNameAndEnsureParameters(1, typeof(TArgument));
7674
return new SignalRAsyncCallbackDescriptor<TArgument>(name, handler);

src/RapidIntegrationTesting/SignalR/SignalRTestingCallbackDescriptorFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static class SignalRTestingCallbackDescriptorFactory
2424
/// <exception cref="TimeoutException"></exception>
2525
public static ISignalRCallbackDescriptor Create<TInterface, TArgument>(Expression<Func<TInterface, TArgument, Task>> expression, out Task<TArgument> signalReceived, int timeout = 30_000)
2626
{
27-
if (expression == null) throw new ArgumentNullException(nameof(expression));
27+
ArgumentNullException.ThrowIfNull(expression);
2828

2929
string name = expression.GetNameAndEnsureParameters(1, typeof(TArgument));
3030
var tcs = new TaskCompletionSource<TArgument>();
@@ -47,7 +47,7 @@ public static ISignalRCallbackDescriptor Create<TInterface, TArgument>(Expressio
4747
/// <exception cref="ArgumentNullException"></exception>
4848
public static ISignalRCallbackDescriptor Create<TInterface>(Expression<Func<TInterface, Task>> expression, out Task signalReceived, int timeout = 30_000)
4949
{
50-
if (expression == null) throw new ArgumentNullException(nameof(expression));
50+
ArgumentNullException.ThrowIfNull(expression);
5151

5252
string name = expression.GetNameAndEnsureParameters(0);
5353
var tcs = new TaskCompletionSource();

src/RapidIntegrationTesting/TestingWebAppFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public HubConnection ConfigureSignalRCallbacks(params ISignalRCallbackDescriptor
5353
/// <exception cref="ArgumentNullException"></exception>
5454
public HubConnection ConfigureSignalRCallbacks(string relativeHubPath, params ISignalRCallbackDescriptor[] descriptors)
5555
{
56-
if (descriptors == null) throw new ArgumentNullException(nameof(descriptors));
56+
ArgumentNullException.ThrowIfNull(descriptors);
5757

5858
var signalRHubUri = new Uri(Server.BaseAddress, relativeHubPath);
5959
IHubConnectionBuilder builder = new HubConnectionBuilder()
@@ -80,7 +80,7 @@ public HubConnection ConfigureSignalRCallbacks(string relativeHubPath, params IS
8080
/// <returns></returns>
8181
public async Task RunAsUser(string userName, Func<HttpClient, Task> testCode)
8282
{
83-
if (testCode == null) throw new ArgumentNullException(nameof(testCode));
83+
ArgumentNullException.ThrowIfNull(testCode);
8484

8585
HttpClient client = CreateClient();
8686
client.DefaultRequestHeaders.Add(AuthConstants.TestUserNameHeaderName, userName);
@@ -99,7 +99,7 @@ private IEnumerable<WebAppConfigurationValue> BuildConfigurations()
9999
/// <inheritdoc />
100100
protected override void ConfigureWebHost(IWebHostBuilder builder)
101101
{
102-
if (builder == null) throw new ArgumentNullException(nameof(builder));
102+
ArgumentNullException.ThrowIfNull(builder);
103103
builder.UseEnvironment(_options.EnvironmentName);
104104

105105
foreach ((string key, string value) in BuildConfigurations())

0 commit comments

Comments
 (0)