Skip to content

Commit 138bc1c

Browse files
Automatically supply 2nd parameter to Guard.Argument calls.
1 parent bc5b7db commit 138bc1c

34 files changed

+97
-97
lines changed

src/NUnitCommon/nunit.agent.core/Communication/Transports/Tcp/TestAgentTcpTransport.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class TestAgentTcpTransport : ITestAgentTransport, ITestEventListener
2525

2626
public TestAgentTcpTransport(RemoteTestAgent agent, string serverUrl)
2727
{
28-
Guard.ArgumentNotNull(agent, nameof(agent));
28+
Guard.ArgumentNotNull(agent);
2929
Agent = agent;
3030

31-
Guard.ArgumentNotNullOrEmpty(serverUrl, nameof(serverUrl));
31+
Guard.ArgumentNotNullOrEmpty(serverUrl);
3232
_agencyUrl = serverUrl;
3333

3434
var parts = serverUrl.Split(PortSeparator);

src/NUnitCommon/nunit.agent.core/Drivers/NUnit3DriverFactory.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public bool IsSupportedTestFramework(AssemblyName reference)
3030
/// <returns>An IFrameworkDriver</returns>
3131
public IFrameworkDriver GetDriver(AppDomain domain, string id, AssemblyName reference)
3232
{
33-
Guard.ArgumentNotNullOrEmpty(id, nameof(id));
33+
Guard.ArgumentNotNullOrEmpty(id);
3434
Guard.ArgumentValid(IsSupportedTestFramework(reference), "Invalid framework", nameof(reference));
3535

3636
log.Info("Using NUnitFrameworkDriver");
@@ -44,7 +44,7 @@ public IFrameworkDriver GetDriver(AppDomain domain, string id, AssemblyName refe
4444
/// <returns></returns>
4545
public IFrameworkDriver GetDriver(string id, AssemblyName reference)
4646
{
47-
Guard.ArgumentNotNullOrEmpty(id, nameof(id));
47+
Guard.ArgumentNotNullOrEmpty(id);
4848
Guard.ArgumentValid(IsSupportedTestFramework(reference), "Invalid framework", nameof(reference));
4949
log.Info("Using NUnitFrameworkDriver");
5050
return new NUnitFrameworkDriver(id, reference);

src/NUnitCommon/nunit.agent.core/Drivers/NUnitFrameworkApi2009.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ internal class NUnitFrameworkApi2009 : NUnitFrameworkApi
3737

3838
public NUnitFrameworkApi2009(AppDomain testDomain, string driverId, AssemblyName nunitRef)
3939
{
40-
Guard.ArgumentNotNull(testDomain, nameof(testDomain));
41-
Guard.ArgumentNotNull(driverId, nameof(driverId));
42-
Guard.ArgumentNotNull(nunitRef, nameof(nunitRef));
40+
Guard.ArgumentNotNull(testDomain);
41+
Guard.ArgumentNotNull(driverId);
42+
Guard.ArgumentNotNull(nunitRef);
4343

4444
_testDomain = testDomain;
4545
_driverId = driverId;

src/NUnitCommon/nunit.agent.core/Drivers/NUnitFrameworkApi2018.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public class NUnitFrameworkApi2018 : NUnitFrameworkApi
4848

4949
public NUnitFrameworkApi2018(string driverId, AssemblyName nunitRef)
5050
{
51-
Guard.ArgumentNotNull(driverId, nameof(driverId));
52-
Guard.ArgumentNotNull(nunitRef, nameof(nunitRef));
51+
Guard.ArgumentNotNull(driverId);
52+
Guard.ArgumentNotNull(nunitRef);
5353

5454
_driverId = driverId;
5555
_nunitRef = nunitRef;
5656
}
5757

5858
public string Load(string testAssemblyPath, IDictionary<string, object> settings)
5959
{
60-
Guard.ArgumentNotNull(testAssemblyPath, nameof(testAssemblyPath));
61-
Guard.ArgumentNotNull(settings, nameof(settings));
60+
Guard.ArgumentNotNull(testAssemblyPath);
61+
Guard.ArgumentNotNull(settings);
6262
Guard.ArgumentValid(File.Exists(testAssemblyPath), "Framework driver called with a file name that doesn't exist.", nameof(testAssemblyPath));
6363
log.Info($"Loading {testAssemblyPath} - see separate log file");
6464

src/NUnitCommon/nunit.agent.core/Drivers/NUnitFrameworkDriver.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public class NUnitFrameworkDriver : IFrameworkDriver
2727
/// <param name="nunitRef">An AssemblyName referring to the test framework.</param>
2828
public NUnitFrameworkDriver(AppDomain testDomain, string id, AssemblyName nunitRef)
2929
{
30-
Guard.ArgumentNotNull(testDomain, nameof(testDomain));
31-
Guard.ArgumentNotNullOrEmpty(id, nameof(id));
32-
Guard.ArgumentNotNull(nunitRef, nameof(nunitRef));
30+
Guard.ArgumentNotNull(testDomain);
31+
Guard.ArgumentNotNullOrEmpty(id);
32+
Guard.ArgumentNotNull(nunitRef);
3333

3434
ID = id;
3535

@@ -60,11 +60,11 @@ public NUnitFrameworkDriver(AppDomain testDomain, string id, AssemblyName nunitR
6060
/// <param name="nunitRef">An AssemblyName referring to the test framework.</param>
6161
internal NUnitFrameworkDriver(AppDomain testDomain, string api, string id, AssemblyName nunitRef)
6262
{
63-
Guard.ArgumentNotNull(testDomain, nameof(testDomain));
64-
Guard.ArgumentNotNull(api, nameof(api));
63+
Guard.ArgumentNotNull(testDomain);
64+
Guard.ArgumentNotNull(api);
6565
Guard.ArgumentValid(api == "2009" || api == "2018", $"Invalid API specified: {api}", nameof(api));
66-
Guard.ArgumentNotNullOrEmpty(id, nameof(id));
67-
Guard.ArgumentNotNull(nunitRef, nameof(nunitRef));
66+
Guard.ArgumentNotNullOrEmpty(id);
67+
Guard.ArgumentNotNull(nunitRef);
6868

6969
ID = id;
7070
API = api;
@@ -90,8 +90,8 @@ internal NUnitFrameworkDriver(AppDomain testDomain, string api, string id, Assem
9090
/// <param name="reference">An AssemblyName referring to the test framework.</param>
9191
public NUnitFrameworkDriver(string id, AssemblyName nunitRef)
9292
{
93-
Guard.ArgumentNotNullOrEmpty(id, nameof(id));
94-
Guard.ArgumentNotNull(nunitRef, nameof(nunitRef));
93+
Guard.ArgumentNotNullOrEmpty(id);
94+
Guard.ArgumentNotNull(nunitRef);
9595

9696
ID = id;
9797
API = "2018";

src/NUnitCommon/nunit.agent.core/Runners/DomainManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private void UnloadOnThread()
169169
/// <returns>The ApplicationBase</returns>
170170
public static string? GetApplicationBase(TestPackage package)
171171
{
172-
Guard.ArgumentNotNull(package, "package");
172+
Guard.ArgumentNotNull(package);
173173

174174
var appBase = package.GetSetting(EnginePackageSettings.BasePath, string.Empty);
175175

@@ -190,8 +190,8 @@ private void UnloadOnThread()
190190

191191
public static string? GetConfigFile(string appBase, TestPackage package)
192192
{
193-
Guard.ArgumentNotNullOrEmpty(appBase, "appBase");
194-
Guard.ArgumentNotNull(package, "package");
193+
Guard.ArgumentNotNullOrEmpty(appBase);
194+
Guard.ArgumentNotNull(package);
195195

196196
// Use provided setting if available
197197
string configFile = package.GetSetting(EnginePackageSettings.ConfigurationFile, string.Empty);

src/NUnitCommon/nunit.agent.core/Runners/TestAgentRunner.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public bool IsPackageLoaded
4747

4848
public TestAgentRunner(TestPackage package)
4949
{
50-
Guard.ArgumentNotNull(package, nameof(package));
50+
Guard.ArgumentNotNull(package);
5151
//Guard.ArgumentValid(package.IsAssemblyPackage(), "TestAgentRunner requires a package with a single assembly", nameof(package));
5252
var assemblyPackages = package.Select(p => !p.HasSubPackages());
5353
Guard.ArgumentValid(assemblyPackages.Count == 1, "TestAgentRunner requires a package with a single assembly", nameof(package));

src/NUnitCommon/nunit.agent.core/TestAssemblyResolver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void Dispose()
9191

9292
private Assembly? OnResolving(AssemblyLoadContext loadContext, AssemblyName assemblyName)
9393
{
94-
Guard.ArgumentNotNull(loadContext, nameof(loadContext));
94+
Guard.ArgumentNotNull(loadContext);
9595

9696
Assembly? loadedAssembly;
9797
foreach (var strategy in ResolutionStrategies)

src/NUnitCommon/nunit.common/FileSystemAccess/Directory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class Directory : IDirectory
2323
/// <exception cref="SIO.PathTooLongException"><paramref name="path"/> exceeds the system-defined maximum length.</exception>
2424
public Directory(string path)
2525
{
26-
Guard.ArgumentNotNull(path, nameof(path));
26+
Guard.ArgumentNotNull(path);
2727

2828
if (path.IndexOfAny(SIO.Path.GetInvalidPathChars()) > -1)
2929
{

src/NUnitCommon/nunit.common/FileSystemAccess/DirectoryFinder.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public DirectoryFinder(IFileSystem fileSystem)
2727
/// <inheritdoc/>
2828
public IEnumerable<IDirectory> GetDirectories(IDirectory startDirectory, string pattern)
2929
{
30-
Guard.ArgumentNotNull(startDirectory, nameof(startDirectory));
31-
Guard.ArgumentNotNull(pattern, nameof(pattern));
30+
Guard.ArgumentNotNull(startDirectory);
31+
Guard.ArgumentNotNull(pattern);
3232

3333
if (Path.DirectorySeparatorChar == '\\')
3434
pattern = pattern.Replace(Path.DirectorySeparatorChar, '/');
@@ -63,8 +63,8 @@ public IEnumerable<IDirectory> GetDirectories(IDirectory startDirectory, string
6363
/// <inheritdoc/>
6464
public IEnumerable<IFile> GetFiles(IDirectory startDirectory, string pattern)
6565
{
66-
Guard.ArgumentNotNull(startDirectory, nameof(startDirectory));
67-
Guard.ArgumentNotNullOrEmpty(pattern, nameof(pattern));
66+
Guard.ArgumentNotNull(startDirectory);
67+
Guard.ArgumentNotNullOrEmpty(pattern);
6868

6969
// If there is no directory path in pattern, delegate to DirectoryInfo
7070
int lastSep = pattern.LastIndexOf('/');

src/NUnitCommon/nunit.common/FileSystemAccess/File.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed class File : IFile
2121
/// <exception cref="System.IO.PathTooLongException">The specified path exceeds the system-defined maximum length.</exception>
2222
public File(string path)
2323
{
24-
Guard.ArgumentNotNull(path, nameof(path));
24+
Guard.ArgumentNotNull(path);
2525

2626
if (string.IsNullOrEmpty(path))
2727
{

src/NUnitCommon/nunit.common/FileSystemAccess/FileSystem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public sealed class FileSystem : IFileSystem
1313
/// <inheritdoc/>
1414
public bool Exists(IDirectory directory)
1515
{
16-
Guard.ArgumentNotNull(directory, nameof(directory));
16+
Guard.ArgumentNotNull(directory);
1717

1818
return SIO.Directory.Exists(directory.FullName);
1919
}
2020

2121
/// <inheritdoc/>
2222
public bool Exists(IFile file)
2323
{
24-
Guard.ArgumentNotNull(file, nameof(file));
24+
Guard.ArgumentNotNull(file);
2525

2626
return SIO.File.Exists(file.FullName);
2727
}

src/NUnitCommon/nunit.common/Guard.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public static class Guard
1616
/// Throws an exception if an argument is null
1717
/// </summary>
1818
/// <param name="value">The value to be tested</param>
19-
/// <param name="name">The name of the argument</param>
20-
public static void ArgumentNotNull(object value, string name)
19+
/// <param name="name">Compiler supplied parameter for the <paramref name="value"/> expression.</param>
20+
public static void ArgumentNotNull<T>(T value, [CallerArgumentExpression(nameof(value))] string name = "")
21+
where T : notnull
2122
{
2223
if (value is null)
2324
throw new ArgumentNullException(name);
@@ -44,8 +45,8 @@ public static T ShouldNotBeNull<T>(this T? result, [CallerArgumentExpression(nam
4445
/// Throws an exception if a string argument is null or empty
4546
/// </summary>
4647
/// <param name="value">The value to be tested</param>
47-
/// <param name="name">The name of the argument</param>
48-
public static void ArgumentNotNullOrEmpty(string value, string name)
48+
/// <param name="name">Compiler supplied parameter for the <paramref name="value"/> expression.</param>
49+
public static void ArgumentNotNullOrEmpty(string value, [CallerArgumentExpression(nameof(value))] string name = "")
4950
{
5051
ArgumentNotNull(value, name);
5152

src/NUnitCommon/nunit.common/Logging/InternalTraceWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal InternalTraceWriter(string logPath)
3030
/// <param name="writer"></param>
3131
public InternalTraceWriter(TextWriter writer)
3232
{
33-
Guard.ArgumentNotNull(writer, nameof(writer));
33+
Guard.ArgumentNotNull(writer);
3434

3535
_writer = writer;
3636
}

src/NUnitCommon/nunit.common/PathUtils.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public static bool IsAssemblyFileType(string path)
4242
/// </summary>
4343
public static string? RelativePath(string from, string to)
4444
{
45-
Guard.ArgumentNotNull(from, nameof(from));
46-
Guard.ArgumentNotNull(to, nameof(to));
45+
Guard.ArgumentNotNull(from);
46+
Guard.ArgumentNotNull(to);
4747

4848
string? toPathRoot = Path.GetPathRoot(to);
4949
if (toPathRoot is null || toPathRoot == string.Empty)
@@ -189,7 +189,7 @@ public static bool IsFullyQualifiedPath(string path)
189189
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
190190
public static bool IsFullyQualifiedWindowsPath(string path)
191191
{
192-
Guard.ArgumentNotNull(path, nameof(path));
192+
Guard.ArgumentNotNull(path);
193193

194194
if (path.Length > 2)
195195
{
@@ -210,7 +210,7 @@ public static bool IsFullyQualifiedWindowsPath(string path)
210210
/// <exception cref="ArgumentNullException"><paramref name="path"/></exception>
211211
public static bool IsFullyQualifiedUnixPath(string path)
212212
{
213-
Guard.ArgumentNotNull(path, nameof(path));
213+
Guard.ArgumentNotNull(path);
214214

215215
return path.Length > 0 && path[0] == '/';
216216
}

src/NUnitCommon/nunit.common/TcpChannelUtils.ObservableServerChannelSinkProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private sealed class ObservableServerChannelSinkProvider : IServerChannelSinkPro
1717

1818
public ObservableServerChannelSinkProvider(CurrentMessageCounter currentMessageCounter)
1919
{
20-
Guard.ArgumentNotNull(currentMessageCounter, nameof(currentMessageCounter));
20+
Guard.ArgumentNotNull(currentMessageCounter);
2121
_currentMessageCounter = currentMessageCounter;
2222
}
2323

@@ -41,7 +41,7 @@ private sealed class ObservableServerChannelSink : IServerChannelSink
4141

4242
public ObservableServerChannelSink(CurrentMessageCounter currentMessageCounter, IServerChannelSink next)
4343
{
44-
Guard.ArgumentNotNull(next, nameof(next));
44+
Guard.ArgumentNotNull(next);
4545
_currentMessageCounter = currentMessageCounter;
4646
_next = next;
4747
}

src/NUnitCommon/nunit.common/TextDisplay/ColorConsoleWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override void WriteLabelLine(string label, object option)
8585
/// <param name="valueStyle">The color to display the value with</param>
8686
public override void WriteLabel(string label, object option, ColorStyle valueStyle)
8787
{
88-
Guard.ArgumentNotNull(option, nameof(option));
88+
Guard.ArgumentNotNull(option);
8989

9090
Write(ColorStyle.Label, label);
9191
Write(valueStyle, option.ToString() ?? string.Empty);

src/NUnitCommon/nunit.extensibility/AddinsFile.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class AddinsFile : List<AddinsFileEntry>
1515
{
1616
public static AddinsFile Read(IFile file)
1717
{
18-
Guard.ArgumentNotNull(file, nameof(file));
18+
Guard.ArgumentNotNull(file);
1919

2020
using (var stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
2121
{

src/NUnitCommon/nunit.extensibility/Wrappers/ProjectLoaderWrapper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public TestPackageWrapper(object wrappedInstance) : base(wrappedInstance)
8282
public T GetSetting<T>(string name, T defaultValue)
8383
where T : notnull
8484
{
85-
Guard.ArgumentNotNull(defaultValue, nameof(defaultValue));
85+
Guard.ArgumentNotNull(defaultValue);
8686

8787
return Invoke<T>(nameof(GetSetting), name, defaultValue);
8888
}

src/NUnitConsole/nunit4-console/ConsoleOptions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ConsoleOptions : OptionSet
2828

2929
internal ConsoleOptions(IFileSystem fileSystem, params string[] args)
3030
{
31-
Guard.ArgumentNotNull(fileSystem, nameof(fileSystem));
31+
Guard.ArgumentNotNull(fileSystem);
3232

3333
_fileSystem = fileSystem;
3434

@@ -426,7 +426,7 @@ private static void CheckOptionCombinations()
426426

427427
public IEnumerable<string> PreParse(IEnumerable<string> args)
428428
{
429-
Guard.ArgumentNotNull(args, nameof(args));
429+
Guard.ArgumentNotNull(args);
430430

431431
if (++_nesting > 3)
432432
{

src/NUnitConsole/nunit4-console/ConsoleRunner.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public class ConsoleRunner
5959

6060
public ConsoleRunner(ITestEngine engine, ConsoleOptions options, ExtendedTextWriter writer)
6161
{
62-
Guard.ArgumentNotNull(_engine = engine, nameof(engine));
63-
Guard.ArgumentNotNull(_options = options, nameof(options));
64-
Guard.ArgumentNotNull(_outWriter = writer, nameof(writer));
62+
Guard.ArgumentNotNull(_engine = engine);
63+
Guard.ArgumentNotNull(_options = options);
64+
Guard.ArgumentNotNull(_outWriter = writer);
6565

6666
// NOTE: Accessing Services triggers the engine to initialize all services
6767
_resultService = _engine.Services.GetService<IResultService>();

src/NUnitConsole/nunit4-console/FileSystem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ internal class FileSystem : IFileSystem
1010
{
1111
public bool FileExists(string fileName)
1212
{
13-
Guard.ArgumentNotNull(fileName, nameof(fileName));
13+
Guard.ArgumentNotNull(fileName);
1414

1515
return File.Exists(fileName);
1616
}
1717

1818
public IEnumerable<string> ReadLines(string fileName)
1919
{
20-
Guard.ArgumentNotNull(fileName, nameof(fileName));
20+
Guard.ArgumentNotNull(fileName);
2121

2222
using (var file = File.OpenText(fileName))
2323
{

0 commit comments

Comments
 (0)