diff --git a/src/TestFramework/TestFramework.Extensions/PrivateObject.cs b/src/TestFramework/TestFramework.Extensions/PrivateObject.cs index a379f5118d..3272b3c5d8 100644 --- a/src/TestFramework/TestFramework.Extensions/PrivateObject.cs +++ b/src/TestFramework/TestFramework.Extensions/PrivateObject.cs @@ -96,7 +96,7 @@ public PrivateObject(string assemblyName, string typeName, Type[]? parameterType public PrivateObject(Type type, params object?[]? args) : this(type, null, args) { - Helper.CheckParameterNotNull(type, "type", string.Empty); + Guard.IsNotNull(type, "type", string.Empty); } /// @@ -108,7 +108,7 @@ public PrivateObject(Type type, params object?[]? args) /// Arguments to pass to the constructor. public PrivateObject(Type type, Type[]? parameterTypes, object?[]? args) { - Helper.CheckParameterNotNull(type, "type", string.Empty); + Guard.IsNotNull(type, "type", string.Empty); object? o; if (parameterTypes != null) { diff --git a/src/TestFramework/TestFramework/Internal/Guard.cs b/src/TestFramework/TestFramework/Internal/Guard.cs new file mode 100644 index 0000000000..3b41e1f123 --- /dev/null +++ b/src/TestFramework/TestFramework/Internal/Guard.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Microsoft.VisualStudio.TestTools.UnitTesting; + +/// +/// A guard helper class to help validate preconditions. +/// +internal static class Guard +{ + internal static void IsNotNull(object? param, string parameterName, string? message) + { + if (param is not null) + { + return; + } + + if (message is null) + { + throw new ArgumentNullException(parameterName); + } + + throw new ArgumentNullException(parameterName, message); + } + + internal static void IsNotNullOrEmpty(string? argument, string parameterName, string message) + { + if (StringEx.IsNullOrEmpty(argument)) + { + throw new ArgumentException(message, parameterName); + } + } +} diff --git a/src/TestFramework/TestFramework/Internal/Helper.cs b/src/TestFramework/TestFramework/Internal/Helper.cs deleted file mode 100644 index 8427a04e2b..0000000000 --- a/src/TestFramework/TestFramework/Internal/Helper.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; - -namespace Microsoft.VisualStudio.TestTools.UnitTesting; - -/// -/// The helper. -/// -internal static class Helper -{ - /// - /// The check parameter not null. - /// - /// - /// The parameter. - /// - /// - /// The parameter name. - /// - /// - /// The message. - /// - /// Throws argument null exception when parameter is null. - internal static void CheckParameterNotNull(object param, string parameterName, string message) - { - _ = param ?? throw new ArgumentNullException(nameof(param)); - } - - /// - /// The check parameter not null or empty. - /// - /// - /// The parameter. - /// - /// - /// The parameter name. - /// - /// - /// The message. - /// - /// Throws ArgumentException when parameter is null. - internal static void CheckParameterNotNullOrEmpty(string param, string parameterName, string message) - { - if (StringEx.IsNullOrEmpty(param)) - { - throw new ArgumentException(message, parameterName); - } - } -}