diff --git a/src/Adapter/MSTestAdapter.PlatformServices/AssemblyResolver.cs b/src/Adapter/MSTestAdapter.PlatformServices/AssemblyResolver.cs index 06d9a359a4..fb5d8d0983 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/AssemblyResolver.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/AssemblyResolver.cs @@ -101,10 +101,7 @@ class AssemblyResolver : /// public AssemblyResolver(IList directories) { - if (directories == null || directories.Count == 0) - { - throw new ArgumentNullException(nameof(directories)); - } + Guard.NotNullOrEmpty(directories); _searchDirectories = [.. directories]; _directoryList = new Queue(); diff --git a/src/TestFramework/TestFramework.Extensions/PrivateType.cs b/src/TestFramework/TestFramework.Extensions/PrivateType.cs index 9df8604261..c9733d65cb 100644 --- a/src/TestFramework/TestFramework.Extensions/PrivateType.cs +++ b/src/TestFramework/TestFramework.Extensions/PrivateType.cs @@ -407,7 +407,7 @@ public object GetStaticProperty(string name, BindingFlags bindingFlags, Type[]? /// Arguments to pass to the member to invoke. public void SetStaticProperty(string name, BindingFlags bindingFlags, object value, Type[]? parameterTypes, object?[]? args) { - _ = name ?? throw new ArgumentNullException(nameof(name)); + Guard.NotNull(name); if (parameterTypes != null) { diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/ProjectSystem.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/ProjectSystem.cs index a82479eafe..8be5485cfc 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/ProjectSystem.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/ProjectSystem.cs @@ -5,6 +5,8 @@ using System.Text; using System.Xml.Linq; +using Polyfills; + namespace Microsoft.Testing.TestInfrastructure; public class VSSolution : Folder @@ -42,15 +44,8 @@ public class VSSolution : Folder public VSSolution(string? solutionFolder, string? solutionName) : base(solutionFolder) { - if (string.IsNullOrEmpty(solutionFolder)) - { - throw new ArgumentNullException(nameof(solutionFolder)); - } - - if (string.IsNullOrEmpty(solutionName)) - { - throw new ArgumentNullException(nameof(solutionName)); - } + Guard.NotNullOrWhiteSpace(solutionFolder); + Guard.NotNullOrWhiteSpace(solutionName); _solutionFileName = $"{solutionName}.sln"; SolutionFile = Path.Combine(FolderPath, _solutionFileName); @@ -93,20 +88,9 @@ public class CSharpProject : Project public CSharpProject(string solutionFolder, string projectName, params string[]? tfms) : base(Path.Combine(solutionFolder, projectName)) { - if (string.IsNullOrEmpty(solutionFolder)) - { - throw new ArgumentNullException(nameof(solutionFolder)); - } - - if (string.IsNullOrEmpty(projectName)) - { - throw new ArgumentNullException(nameof(projectName)); - } - - if (tfms is null || tfms.Length == 0) - { - throw new ArgumentException("Invalid tfm", nameof(tfms)); - } + Guard.NotNullOrWhiteSpace(solutionFolder); + Guard.NotNullOrWhiteSpace(projectName); + Guard.NotEmpty(tfms); _projectFileName = $"{projectName}.csproj"; ProjectFile = Path.Combine(FolderPath, _projectFileName);