diff --git a/Source/Boxed.DotnetNewTest/DotnetNew.cs b/Source/Boxed.DotnetNewTest/DotnetNew.cs index 48c54c2b..679566be 100644 --- a/Source/Boxed.DotnetNewTest/DotnetNew.cs +++ b/Source/Boxed.DotnetNewTest/DotnetNew.cs @@ -29,7 +29,11 @@ public static Task InstallAsync(string fileName) => /// The assembly used to find the directory path of the project to install. /// Name of the file. /// A representing the asynchronous operation. - /// The provided assembly was null. + /// + /// is null. + /// - or - + /// is null. + /// /// A file with the specified file name was not found. public static Task InstallAsync(Assembly assembly, string fileName) { @@ -43,12 +47,13 @@ public static Task InstallAsync(Assembly assembly, string fileName) throw new ArgumentNullException(nameof(fileName)); } - var projectFilePath = Path.GetDirectoryName(GetFilePath(assembly, fileName)); - if (projectFilePath is null) + if (fileName.Length == 0) { - throw new FileNotFoundException($"{fileName} not found."); + throw new ArgumentException(nameof(fileName), $"{nameof(fileName)} must not be empty."); } + var projectFilePath = GetProjectFilePath(assembly, fileName); + return InstallAsync(projectFilePath); } @@ -59,12 +64,18 @@ public static Task InstallAsync(Assembly assembly, string fileName) /// The timeout. Defaults to one minute. /// if set to true show the shell window instead of logging to output. /// A representing the asynchronous operation. - /// The provided source was null or empty. + /// The provided was null. + /// The provided was empty. public static async Task InstallAsync(string source, TimeSpan? timeout = null, bool showShellWindow = false) { - if (string.IsNullOrWhiteSpace(source)) + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + + if (source.Length == 0) { - throw new ArgumentException("Empty or null.", nameof(source)); + throw new ArgumentException(nameof(source), $"{nameof(source)} must not be empty."); } await RunDotnetCommandAsync($"new --install \"{source}\"", timeout, showShellWindow).ConfigureAwait(false); @@ -96,7 +107,11 @@ public static Task UninstallAsync(string fileName) => /// The assembly used to find the directory path of the project to install. /// Name of the file. /// A representing the asynchronous operation. - /// The provided assembly was null. + /// + /// is null. + /// - or - + /// is null. + /// /// A file with the specified file name was not found. public static Task UninstallAsync(Assembly assembly, string fileName) { @@ -110,12 +125,13 @@ public static Task UninstallAsync(Assembly assembly, string fileName) throw new ArgumentNullException(nameof(fileName)); } - var projectFilePath = Path.GetDirectoryName(GetFilePath(assembly, fileName)); - if (projectFilePath is null) + if (fileName.Length == 0) { - throw new FileNotFoundException($"{fileName} not found."); + throw new ArgumentException(nameof(fileName), $"{nameof(fileName)} must not be empty."); } + var projectFilePath = GetProjectFilePath(assembly, fileName); + return UninstallAsync(projectFilePath); } @@ -126,17 +142,34 @@ public static Task UninstallAsync(Assembly assembly, string fileName) /// The timeout. Defaults to one minute. /// if set to true show the shell window instead of logging to output. /// A representing the asynchronous operation. - /// The provided source was null or empty. + /// The provided was null. + /// The provided was empty. public static async Task UninstallAsync(string source, TimeSpan? timeout = null, bool showShellWindow = false) { - if (string.IsNullOrWhiteSpace(source)) + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + + if (source.Length == 0) { - throw new ArgumentException("Empty or null.", nameof(source)); + throw new ArgumentException(nameof(source), $"{nameof(source)} must not be empty."); } await RunDotnetCommandAsync($"new --uninstall \"{source}\"", timeout, showShellWindow).ConfigureAwait(false); } + private static string GetProjectFilePath(Assembly assembly, string fileName) + { + var projectFilePath = Path.GetDirectoryName(GetFilePath(assembly, fileName)); + if (projectFilePath is null) + { + throw new FileNotFoundException($"{fileName} not found."); + } + + return projectFilePath; + } + private static string? GetFilePath(Assembly assembly, string projectName) { string? projectFilePath = null;