diff --git a/src/BuiltInTools/dotnet-watch/CommandLineOptions.cs b/src/BuiltInTools/dotnet-watch/CommandLineOptions.cs index e49c07ba48e2..497fb41c3b66 100644 --- a/src/BuiltInTools/dotnet-watch/CommandLineOptions.cs +++ b/src/BuiltInTools/dotnet-watch/CommandLineOptions.cs @@ -34,7 +34,7 @@ internal sealed class CommandLineOptions "restore", "run", "sdk", - "sln", + "solution", "store", "test", "tool", @@ -179,7 +179,7 @@ internal sealed class CommandLineOptions BuildProperties = ParseBuildProperties(parseResult.GetValue(propertyOption) ?? []).ToArray(), }; - // Parses name=value pairs passed to --property. Skips invalid input. + // Parses name=value pairs passed to --property. Skips invalid input. // We don't report error here as it will be reported by dotnet run. static IEnumerable<(string key, string value)> ParseBuildProperties(string[] properties) => from property in properties @@ -240,7 +240,7 @@ private static IReadOnlyList GetCommandArguments( { explicitCommand = token; } - else + else { if (!dashDashInserted && i >= unmatchedTokensBeforeDashDash) { diff --git a/src/Cli/dotnet-new3/Dotnet.cs b/src/Cli/dotnet-new3/Dotnet.cs index 6a3a63f48172..a9f244daffb4 100644 --- a/src/Cli/dotnet-new3/Dotnet.cs +++ b/src/Cli/dotnet-new3/Dotnet.cs @@ -72,7 +72,7 @@ internal static Dotnet AddProjectsToSolution(string solutionFile, IReadOnlyList< { List allArgs = new() { - "sln", + "solution", solutionFile, "add" }; diff --git a/src/Cli/dotnet/ReleasePropertyProjectLocator.cs b/src/Cli/dotnet/ReleasePropertyProjectLocator.cs index 6e08a281c671..803a44b0e442 100644 --- a/src/Cli/dotnet/ReleasePropertyProjectLocator.cs +++ b/src/Cli/dotnet/ReleasePropertyProjectLocator.cs @@ -138,7 +138,7 @@ public IEnumerable GetCustomDefaultConfigurationValueIfSpecified() } } } - return null; // If nothing can be found: that's caught by MSBuild XMake::ProcessProjectSwitch -- don't change the behavior by failing here. + return null; // If nothing can be found: that's caught by MSBuild XMake::ProcessProjectSwitch -- don't change the behavior by failing here. } /// An arbitrary existant project in a solution file. Returns null if no projects exist. @@ -205,7 +205,7 @@ public IEnumerable GetCustomDefaultConfigurationValueIfSpecified() /// /// Returns an arbitrary project for the solution. Relies on the .NET SDK PrepareForPublish or _VerifyPackReleaseConfigurations MSBuild targets to catch conflicting values of a given property, like PublishRelease or PackRelease. /// - /// The solution to get an arbitrary project from. + /// The solution to get an arbitrary project from. /// The global properties to load into the project. /// null if no project exists in the solution that can be evaluated properly. Else, the first project in the solution that can be. private ProjectInstance? GetSingleProjectFromSolution(SlnFile sln, Dictionary globalProps) @@ -253,13 +253,13 @@ private bool IsUnanalyzableProjectInSolution(SlnProject project, string projectF return null; } - /// Returns true if the path exists and is a project file type. + /// Returns true if the path exists and is a project file type. private bool IsValidProjectFilePath(string path) { return File.Exists(path) && Path.GetExtension(path).EndsWith("proj"); } - /// Returns true if the path exists and is a sln file type. + /// Returns true if the path exists and is a sln file type. private bool IsValidSlnFilePath(string path) { return File.Exists(path) && Path.GetExtension(path).EndsWith("sln"); @@ -271,7 +271,7 @@ private Dictionary GetUserSpecifiedExplicitMSBuildProperties() Dictionary globalProperties = new(StringComparer.OrdinalIgnoreCase); string[]? globalPropEnumerable = _parseResult.GetValue(CommonOptions.PropertiesOption); - + if ( globalPropEnumerable != null ) { foreach (var keyEqValString in globalPropEnumerable) diff --git a/src/Cli/dotnet/Telemetry/TelemetryFilter.cs b/src/Cli/dotnet/Telemetry/TelemetryFilter.cs index 997e34b43476..d0990bd3652b 100644 --- a/src/Cli/dotnet/Telemetry/TelemetryFilter.cs +++ b/src/Cli/dotnet/Telemetry/TelemetryFilter.cs @@ -84,7 +84,7 @@ public IEnumerable Filter(object objectToFilter) private static List ParseResultLogRules => new() { new AllowListToSendFirstArgument(new HashSet {"new", "help"}), - new AllowListToSendFirstAppliedOptions(new HashSet {"add", "remove", "list", "sln", "nuget"}), + new AllowListToSendFirstAppliedOptions(new HashSet {"add", "remove", "list", "solution", "nuget"}), new TopLevelCommandNameAndOptionToLog ( topLevelCommandName: new HashSet {"build", "publish"}, diff --git a/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs b/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs index 5b9f6e028abe..983a73b439f5 100644 --- a/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs +++ b/src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs @@ -50,7 +50,7 @@ internal static class HelpUsageText restore {LocalizableStrings.RestoreDefinition} run {LocalizableStrings.RunDefinition} sdk {LocalizableStrings.SdkDefinition} - sln {LocalizableStrings.SlnDefinition} + solution {LocalizableStrings.SlnDefinition} store {LocalizableStrings.StoreDefinition} test {LocalizableStrings.TestDefinition} tool {LocalizableStrings.ToolDefinition} diff --git a/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs b/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs index 61f85961af19..ea41a6182efb 100644 --- a/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs +++ b/src/Cli/dotnet/commands/dotnet-new/DotnetCommandCallbacks.cs @@ -46,7 +46,7 @@ internal static bool AddProjectsToSolution(string solutionPath, IReadOnlyList commandArgs = new[] { "sln", solutionPath, "add" }.Concat(projectsToAdd); + IEnumerable commandArgs = new[] { "solution", solutionPath, "add" }.Concat(projectsToAdd); if (!string.IsNullOrWhiteSpace(solutionFolder)) { commandArgs = commandArgs.Append(SlnAddParser.SolutionFolderOption.Name).Append(solutionFolder); diff --git a/src/Cli/dotnet/commands/dotnet-sln/SlnArgumentValidator.cs b/src/Cli/dotnet/commands/dotnet-sln/SlnArgumentValidator.cs index b1b1ebbb861e..5ebab9458a60 100644 --- a/src/Cli/dotnet/commands/dotnet-sln/SlnArgumentValidator.cs +++ b/src/Cli/dotnet/commands/dotnet-sln/SlnArgumentValidator.cs @@ -52,7 +52,7 @@ public static void ParseAndValidateArguments(string _fileOrDirectory, IReadOnlyC { string.Format(CommonLocalizableStrings.SolutionArgumentMisplaced, slnFile), CommonLocalizableStrings.DidYouMean, - $" dotnet sln {slnFile} {command} {args}{projectArgs}" + $" dotnet solution {slnFile} {command} {args}{projectArgs}" }); } } diff --git a/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 927b2d05b940..dc5693470b86 100644 --- a/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using NuGet.Packaging; using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings; namespace Microsoft.DotNet.Cli @@ -10,6 +11,8 @@ internal static class SlnCommandParser { public static readonly string DocsLink = "https://aka.ms/dotnet-sln"; + public static readonly string CommandName = "solution"; + public static readonly string CommandAlias = "sln"; public static readonly CliArgument SlnArgument = new CliArgument(LocalizableStrings.SolutionArgumentName) { HelpName = LocalizableStrings.SolutionArgumentName, @@ -26,7 +29,9 @@ public static CliCommand GetCommand() private static CliCommand ConstructCommand() { - DocumentedCommand command = new("sln", DocsLink, LocalizableStrings.AppFullName); + DocumentedCommand command = new(CommandName, DocsLink, LocalizableStrings.AppFullName); + + command.Aliases.Add(CommandAlias); command.Arguments.Add(SlnArgument); command.Subcommands.Add(SlnAddParser.GetCommand()); diff --git a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs index 0a0992944554..665671557b0b 100644 --- a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs +++ b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs @@ -52,7 +52,7 @@ remove Remove a package or reference from a .NET project. restore Restore dependencies specified in a .NET project. run Build and run a .NET project output. sdk Manage .NET SDK installation. - sln Modify Visual Studio solution files. + solution Modify Visual Studio solution files. store Store the specified assemblies in the runtime package store. test Run unit tests using the test runner specified in a .NET project. tool Install or manage tools that extend the .NET experience. diff --git a/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs index d26273805b53..8c13d746f746 100644 --- a/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs @@ -14,7 +14,7 @@ public class GivenDotnetSlnAdd : SdkTest Add one or more projects to a solution file. Usage: - dotnet sln add [...] [options] + dotnet solution add [...] [options] Arguments: The solution file to operate on. If not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}] @@ -408,76 +408,93 @@ public GivenDotnetSlnAdd(ITestOutputHelper log) : base(log) "; [Theory] - [InlineData("--help")] - [InlineData("-h")] - [InlineData("-?")] - [InlineData("/?")] - public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg) + [InlineData("sln", "--help")] + [InlineData("sln", "-h")] + [InlineData("sln", "-?")] + [InlineData("sln", "/?")] + [InlineData("solution", "--help")] + [InlineData("solution", "-h")] + [InlineData("solution", "-?")] + [InlineData("solution", "/?")] + public void WhenHelpOptionIsPassedItPrintsUsage(string solutionCommand, string helpArg) { var cmd = new DotnetCommand(Log) - .Execute($"sln", "add", helpArg); + .Execute(solutionCommand, "add", helpArg); cmd.Should().Pass(); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText(Directory.GetCurrentDirectory())); } [Theory] - [InlineData("")] - [InlineData("unknownCommandName")] - public void WhenNoCommandIsPassedItPrintsError(string commandName) + [InlineData("sln", "")] + [InlineData("sln", "unknownCommandName")] + [InlineData("solution", "")] + [InlineData("solution", "unknownCommandName")] + public void WhenNoCommandIsPassedItPrintsError(string solutionCommand, string commandName) { var cmd = new DotnetCommand(Log) - .Execute($"sln {commandName}".Trim().Split()); + .Execute($"{solutionCommand} {commandName}".Trim().Split()); cmd.Should().Fail(); cmd.StdErr.Should().Be(CommonLocalizableStrings.RequiredCommandNotPassed); } - [Fact] - public void WhenTooManyArgumentsArePassedItPrintsError() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenTooManyArgumentsArePassedItPrintsError(string solutionCommand) { var cmd = new DotnetCommand(Log) - .Execute("sln", "one.sln", "two.sln", "three.sln", "add"); + .Execute(solutionCommand, "one.sln", "two.sln", "three.sln", "add"); cmd.Should().Fail(); cmd.StdErr.Should().BeVisuallyEquivalentTo($@"{string.Format(CommandLineValidation.LocalizableStrings.UnrecognizedCommandOrArgument, "two.sln")} {string.Format(CommandLineValidation.LocalizableStrings.UnrecognizedCommandOrArgument, "three.sln")}"); } [Theory] - [InlineData("idontexist.sln")] - [InlineData("ihave?invalidcharacters")] - [InlineData("ihaveinv@lidcharacters")] - [InlineData("ihaveinvalid/characters")] - [InlineData("ihaveinvalidchar\\acters")] - public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solutionName) + [InlineData("sln", "idontexist.sln")] + [InlineData("sln", "ihave?invalidcharacters")] + [InlineData("sln", "ihaveinv@lidcharacters")] + [InlineData("sln", "ihaveinvalid/characters")] + [InlineData("sln", "ihaveinvalidchar\\acters")] + [InlineData("solution", "idontexist.sln")] + [InlineData("solution", "ihave?invalidcharacters")] + [InlineData("solution", "ihaveinv@lidcharacters")] + [InlineData("solution", "ihaveinvalid/characters")] + [InlineData("solution", "ihaveinvalidchar\\acters")] + public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solutionCommand, string solutionName) { var cmd = new DotnetCommand(Log) - .Execute($"sln", solutionName, "add", "p.csproj"); + .Execute(solutionCommand, solutionName, "add", "p.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindSolutionOrDirectory, solutionName)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("InvalidSolution", identifier: "GivenDotnetSlnAdd") + .CopyTestAsset("InvalidSolution", identifier: $"{solutionCommand}") .WithSource() .Path; var projectToAdd = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "InvalidSolution.sln", "add", projectToAdd); + .Execute(solutionCommand, "InvalidSolution.sln", "add", projectToAdd); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", LocalizableStrings.FileHeaderMissingError)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenInvalidSolutionIsFoundAddPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenInvalidSolutionIsFoundAddPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("InvalidSolution") + .CopyTestAsset("InvalidSolution", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -485,47 +502,53 @@ public void WhenInvalidSolutionIsFoundAddPrintsErrorAndUsage() var projectToAdd = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "add", projectToAdd); + .Execute(solutionCommand, "add", projectToAdd); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, solutionPath, LocalizableStrings.FileHeaderMissingError)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenNoProjectIsPassedItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNoProjectIsPassedItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: "GivenDotnetSlnAdd") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute(@"sln", "App.sln", "add"); + .Execute(solutionCommand, "App.sln", "add"); cmd.Should().Fail(); cmd.StdErr.Should().Be(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenNoSolutionExistsInTheDirectoryAddPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNoSolutionExistsInTheDirectoryAddPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; var solutionPath = Path.Combine(projectDirectory, "App"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(solutionPath) - .Execute(@"sln", "add", "App.csproj"); + .Execute(solutionCommand, "add", "App.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.SolutionDoesNotExist, solutionPath + Path.DirectorySeparatorChar)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager .CopyTestAsset("TestAppWithMultipleSlnFiles", identifier: "GivenDotnetSlnAdd") @@ -535,14 +558,16 @@ public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage() var projectToAdd = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "add", projectToAdd); + .Execute(solutionCommand, "add", projectToAdd); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.MoreThanOneSolutionInDirectory, projectDirectory + Path.DirectorySeparatorChar)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenNestedProjectIsAddedSolutionFoldersAreCreated() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNestedProjectIsAddedSolutionFoldersAreCreated(string solutionCommand) { var projectDirectory = _testAssetsManager .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir") @@ -552,7 +577,7 @@ public void WhenNestedProjectIsAddedSolutionFoldersAreCreated() var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); var slnPath = Path.Combine(projectDirectory, "App.sln"); @@ -567,12 +592,14 @@ public void WhenNestedProjectIsAddedSolutionFoldersAreCreated() } [Theory] - [InlineData(true)] - [InlineData(false)] - public void WhenNestedProjectIsAddedSolutionFoldersAreCreatedBuild(bool fooFirst) + [InlineData("sln", true)] + [InlineData("sln", false)] + [InlineData("solution", true)] + [InlineData("solution", false)] + public void WhenNestedProjectIsAddedSolutionFoldersAreCreatedBuild(string solutionCommand, bool fooFirst) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojInSubDirVS") + .CopyTestAsset("TestAppWithSlnAndCsprojInSubDirVS", identifier: $"{solutionCommand}{fooFirst}") .WithSource() .Path; string projectToAdd; @@ -583,14 +610,14 @@ public void WhenNestedProjectIsAddedSolutionFoldersAreCreatedBuild(bool fooFirst projectToAdd = "foo"; cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); } projectToAdd = Path.Combine("foo", "bar"); cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); if (!fooFirst) @@ -598,7 +625,7 @@ public void WhenNestedProjectIsAddedSolutionFoldersAreCreatedBuild(bool fooFirst projectToAdd = "foo"; cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); } @@ -609,46 +636,50 @@ public void WhenNestedProjectIsAddedSolutionFoldersAreCreatedBuild(bool fooFirst } - [Fact] - public void WhenNestedDuplicateProjectIsAddedToASolutionFolder() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNestedDuplicateProjectIsAddedToASolutionFolder(string solutionCommand) { - var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojInSubDirVSErrors") - .WithSource() - .Path; + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppWithSlnAndCsprojInSubDirVSErrors", identifier: $"{solutionCommand}") + .WithSource() + .Path; string projectToAdd; CommandResult cmd; projectToAdd = Path.Combine("Base", "Second", "TestCollision.csproj"); cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Fail() .And.HaveStdErrContaining("TestCollision") .And.HaveStdErrContaining("Base"); - projectToAdd = Path.Combine("Base", "Second", "Third", "Second.csproj"); + projectToAdd = Path.Combine("Base", "Second", "Third", "Second.csproj"); cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Fail() .And.HaveStdErrContaining("Second") .And.HaveStdErrContaining("Base"); } [Theory] - [InlineData("TestAppWithSlnAndCsprojFiles")] - [InlineData("TestAppWithSlnAnd472CsprojFiles")] - public void WhenDirectoryContainingProjectIsGivenProjectIsAdded(string testAsset) + [InlineData("sln", "TestAppWithSlnAndCsprojFiles")] + [InlineData("sln", "TestAppWithSlnAnd472CsprojFiles")] + [InlineData("solution", "TestAppWithSlnAndCsprojFiles")] + [InlineData("solution", "TestAppWithSlnAnd472CsprojFiles")] + public void WhenDirectoryContainingProjectIsGivenProjectIsAdded(string solutionCommand, string testAsset) { var projectDirectory = _testAssetsManager - .CopyTestAsset(testAsset) + .CopyTestAsset(testAsset, identifier: $"{solutionCommand}{testAsset}") .WithSource() .Path; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "add", "Lib"); + .Execute(solutionCommand, "add", "Lib"); cmd.Should().Pass(); var slnPath = Path.Combine(projectDirectory, "App.sln"); @@ -657,11 +688,13 @@ public void WhenDirectoryContainingProjectIsGivenProjectIsAdded(string testAsset .Should().BeVisuallyEquivalentTo(expectedSlnContents); } - [Fact] - public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -671,7 +704,7 @@ public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "add", directoryToAdd); + .Execute(solutionCommand, "add", directoryToAdd); cmd.Should().Fail(); cmd.StdErr.Should().Be( string.Format( @@ -682,11 +715,13 @@ public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation() .Should().BeVisuallyEquivalentTo(contentBefore); } - [Fact] - public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -696,7 +731,7 @@ public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "add", directoryToAdd); + .Execute(solutionCommand, "add", directoryToAdd); cmd.Should().Fail(); cmd.StdErr.Should().Be( string.Format( @@ -707,18 +742,20 @@ public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation() .Should().BeVisuallyEquivalentTo(contentBefore); } - [Fact] - public void WhenProjectDirectoryIsAddedSolutionFoldersAreNotCreated() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectDirectoryIsAddedSolutionFoldersAreNotCreated(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; var projectToAdd = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); var slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln")); @@ -728,18 +765,20 @@ public void WhenProjectDirectoryIsAddedSolutionFoldersAreNotCreated() slnFile.Sections.GetSection("NestedProjects").Should().BeNull(); } - [Fact] - public void WhenSharedProjectAddedShouldStillBuild() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSharedProjectAddedShouldStillBuild(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", $"{solutionCommand}") .WithSource() .Path; var projectToAdd = Path.Combine("Shared", "Shared.shproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); cmd.StdErr.Should().BeEmpty(); @@ -750,19 +789,21 @@ public void WhenSharedProjectAddedShouldStillBuild() } [Theory] - [InlineData(".")] - [InlineData("")] - public void WhenSolutionFolderExistsItDoesNotGetAdded(string firstComponent) + [InlineData("sln", ".")] + [InlineData("sln", "")] + [InlineData("solution", ".")] + [InlineData("solution", "")] + public void WhenSolutionFolderExistsItDoesNotGetAdded(string solutionCommand, string firstComponent) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndSolutionFolders", identifier: firstComponent) + .CopyTestAsset("TestAppWithSlnAndSolutionFolders", identifier: $"{solutionCommand}{firstComponent}") .WithSource() .Path; var projectToAdd = Path.Combine($"{firstComponent}", "src", "src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); var slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln")); @@ -788,23 +829,27 @@ public void WhenSolutionFolderExistsItDoesNotGetAdded(string firstComponent) } [Theory] - [InlineData("TestAppWithSlnAndCsprojFiles", ExpectedSlnFileAfterAddingLibProj, "")] - [InlineData("TestAppWithSlnAndCsprojProjectGuidFiles", ExpectedSlnFileAfterAddingLibProj, "{84A45D44-B677-492D-A6DA-B3A71135AB8E}")] - [InlineData("TestAppWithEmptySln", ExpectedSlnFileAfterAddingLibProjToEmptySln, "")] + [InlineData("sln", "TestAppWithSlnAndCsprojFiles", ExpectedSlnFileAfterAddingLibProj, "")] + [InlineData("sln", "TestAppWithSlnAndCsprojProjectGuidFiles", ExpectedSlnFileAfterAddingLibProj, "{84A45D44-B677-492D-A6DA-B3A71135AB8E}")] + [InlineData("sln", "TestAppWithEmptySln", ExpectedSlnFileAfterAddingLibProjToEmptySln, "")] + [InlineData("solution", "TestAppWithSlnAndCsprojFiles", ExpectedSlnFileAfterAddingLibProj, "")] + [InlineData("solution", "TestAppWithSlnAndCsprojProjectGuidFiles", ExpectedSlnFileAfterAddingLibProj, "{84A45D44-B677-492D-A6DA-B3A71135AB8E}")] + [InlineData("solution", "TestAppWithEmptySln", ExpectedSlnFileAfterAddingLibProjToEmptySln, "")] public void WhenValidProjectIsPassedBuildConfigsAreAdded( + string solutionCommand, string testAsset, string expectedSlnContentsTemplate, string expectedProjectGuid) { var projectDirectory = _testAssetsManager - .CopyTestAsset(testAsset) + .CopyTestAsset(testAsset, $"{solutionCommand}{testAsset}") .WithSource() .Path; var projectToAdd = "Lib/Lib.csproj"; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); var slnPath = Path.Combine(projectDirectory, "App.sln"); @@ -819,13 +864,16 @@ public void WhenValidProjectIsPassedBuildConfigsAreAdded( } [Theory] - [InlineData("TestAppWithSlnAndCsprojFiles")] - [InlineData("TestAppWithSlnAndCsprojProjectGuidFiles")] - [InlineData("TestAppWithEmptySln")] - public void WhenValidProjectIsPassedItGetsAdded(string testAsset) + [InlineData("sln", "TestAppWithSlnAndCsprojFiles")] + [InlineData("sln", "TestAppWithSlnAndCsprojProjectGuidFiles")] + [InlineData("sln", "TestAppWithEmptySln")] + [InlineData("solution", "TestAppWithSlnAndCsprojFiles")] + [InlineData("solution", "TestAppWithSlnAndCsprojProjectGuidFiles")] + [InlineData("solution", "TestAppWithEmptySln")] + public void WhenValidProjectIsPassedItGetsAdded(string solutionCommand, string testAsset) { var projectDirectory = _testAssetsManager - .CopyTestAsset(testAsset) + .CopyTestAsset(testAsset, identifier: $"{solutionCommand}{testAsset}") .WithSource() .Path; @@ -833,24 +881,26 @@ public void WhenValidProjectIsPassedItGetsAdded(string testAsset) var projectPath = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, projectPath)); cmd.StdErr.Should().BeEmpty(); } - [Fact] - public void WhenProjectIsAddedSolutionHasUTF8BOM() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectIsAddedSolutionHasUTF8BOM(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithEmptySln") + .CopyTestAsset("TestAppWithEmptySln", $"{solutionCommand}") .WithSource() .Path; var projectToAdd = "Lib/Lib.csproj"; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); var preamble = Encoding.UTF8.GetPreamble(); @@ -866,13 +916,16 @@ public void WhenProjectIsAddedSolutionHasUTF8BOM() } [Theory] - [InlineData("TestAppWithSlnAndCsprojFiles")] - [InlineData("TestAppWithSlnAndCsprojProjectGuidFiles")] - [InlineData("TestAppWithEmptySln")] - public void WhenInvalidProjectIsPassedItDoesNotGetAdded(string testAsset) + [InlineData("sln", "TestAppWithSlnAndCsprojFiles")] + [InlineData("sln", "TestAppWithSlnAndCsprojProjectGuidFiles")] + [InlineData("sln", "TestAppWithEmptySln")] + [InlineData("solution", "TestAppWithSlnAndCsprojFiles")] + [InlineData("solution", "TestAppWithSlnAndCsprojProjectGuidFiles")] + [InlineData("solution", "TestAppWithEmptySln")] + public void WhenInvalidProjectIsPassedItDoesNotGetAdded(string solutionCommand, string testAsset) { var projectDirectory = _testAssetsManager - .CopyTestAsset(testAsset) + .CopyTestAsset(testAsset, $"{solutionCommand}{testAsset}") .WithSource() .Path; @@ -881,8 +934,8 @@ public void WhenInvalidProjectIsPassedItDoesNotGetAdded(string testAsset) var expectedNumberOfProjects = slnFile.Projects.Count(); var cmd = new DotnetCommand(Log) - .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .WithWorkingDirectory(projectDirectory) + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); cmd.StdOut.Should().BeEmpty(); cmd.StdErr.Should().Match(string.Format(CommonLocalizableStrings.InvalidProjectWithExceptionMessage, '*', '*')); @@ -892,19 +945,22 @@ public void WhenInvalidProjectIsPassedItDoesNotGetAdded(string testAsset) } [Theory] - [InlineData("TestAppWithSlnAndCsprojFiles")] - [InlineData("TestAppWithSlnAndCsprojProjectGuidFiles")] - [InlineData("TestAppWithEmptySln")] - public void WhenValidProjectIsPassedTheSlnBuilds(string testAsset) + [InlineData("sln", "TestAppWithSlnAndCsprojFiles")] + [InlineData("sln", "TestAppWithSlnAndCsprojProjectGuidFiles")] + [InlineData("sln", "TestAppWithEmptySln")] + [InlineData("solution", "TestAppWithSlnAndCsprojFiles")] + [InlineData("solution", "TestAppWithSlnAndCsprojProjectGuidFiles")] + [InlineData("solution", "TestAppWithEmptySln")] + public void WhenValidProjectIsPassedTheSlnBuilds(string solutionCommand, string testAsset) { var projectDirectory = _testAssetsManager - .CopyTestAsset(testAsset) + .CopyTestAsset(testAsset, identifier: $"{solutionCommand}{testAsset}") .WithSource() .Path; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute(@"sln", "App.sln", "add", "App/App.csproj", "Lib/Lib.csproj"); + .Execute(solutionCommand, "App.sln", "add", "App/App.csproj", "Lib/Lib.csproj"); cmd.Should().Pass(); var slnPath = Path.Combine(projectDirectory, "App.sln"); @@ -933,12 +989,14 @@ public void WhenValidProjectIsPassedTheSlnBuilds(string testAsset) } [Theory] - [InlineData("TestAppWithSlnAndExistingCsprojReferences")] - [InlineData("TestAppWithSlnAndExistingCsprojReferencesWithEscapedDirSep")] - public void WhenSolutionAlreadyContainsProjectItDoesntDuplicate(string testAsset) + [InlineData("sln", "TestAppWithSlnAndExistingCsprojReferences")] + [InlineData("sln", "TestAppWithSlnAndExistingCsprojReferencesWithEscapedDirSep")] + [InlineData("solution", "TestAppWithSlnAndExistingCsprojReferences")] + [InlineData("solution", "TestAppWithSlnAndExistingCsprojReferencesWithEscapedDirSep")] + public void WhenSolutionAlreadyContainsProjectItDoesntDuplicate(string solutionCommand, string testAsset) { var projectDirectory = _testAssetsManager - .CopyTestAsset(testAsset) + .CopyTestAsset(testAsset, identifier: $"{solutionCommand}{testAsset}") .WithSource() .Path; @@ -946,17 +1004,19 @@ public void WhenSolutionAlreadyContainsProjectItDoesntDuplicate(string testAsset var projectToAdd = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.SolutionAlreadyContainsProject, solutionPath, projectToAdd)); cmd.StdErr.Should().BeEmpty(); } - [Fact] - public void WhenPassedMultipleProjectsAndOneOfthemDoesNotExistItCancelsWholeOperation() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenPassedMultipleProjectsAndOneOfthemDoesNotExistItCancelsWholeOperation(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -966,7 +1026,7 @@ public void WhenPassedMultipleProjectsAndOneOfthemDoesNotExistItCancelsWholeOper var projectToAdd = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd, "idonotexist.csproj"); + .Execute(solutionCommand, "App.sln", "add", projectToAdd, "idonotexist.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindProjectOrDirectory, "idonotexist.csproj")); @@ -974,11 +1034,13 @@ public void WhenPassedMultipleProjectsAndOneOfthemDoesNotExistItCancelsWholeOper .Should().BeVisuallyEquivalentTo(contentBefore); } - [Fact(Skip = "https://github.com/dotnet/sdk/issues/522")] - public void WhenPassedAnUnknownProjectTypeItFails() + [Theory(Skip = "https://github.com/dotnet/sdk/issues/522")] + [InlineData("sln")] + [InlineData("solution")] + public void WhenPassedAnUnknownProjectTypeItFails(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("SlnFileWithNoProjectReferencesAndUnknownProject") + .CopyTestAsset("SlnFileWithNoProjectReferencesAndUnknownProject", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -988,7 +1050,7 @@ public void WhenPassedAnUnknownProjectTypeItFails() var projectToAdd = Path.Combine("UnknownProject", "UnknownProject.unknownproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Fail(); cmd.StdErr.Should().BeVisuallyEquivalentTo("has an unknown project type and cannot be added to the solution file. Contact your SDK provider for support."); @@ -997,26 +1059,32 @@ public void WhenPassedAnUnknownProjectTypeItFails() } [Theory] - [InlineData("SlnFileWithNoProjectReferencesAndCSharpProject", "CSharpProject", "CSharpProject.csproj", ProjectTypeGuids.CSharpProjectTypeGuid)] - [InlineData("SlnFileWithNoProjectReferencesAndFSharpProject", "FSharpProject", "FSharpProject.fsproj", ProjectTypeGuids.FSharpProjectTypeGuid)] - [InlineData("SlnFileWithNoProjectReferencesAndVBProject", "VBProject", "VBProject.vbproj", ProjectTypeGuids.VBProjectTypeGuid)] - [InlineData("SlnFileWithNoProjectReferencesAndUnknownProjectWithSingleProjectTypeGuid", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")] - [InlineData("SlnFileWithNoProjectReferencesAndUnknownProjectWithMultipleProjectTypeGuids", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")] + [InlineData("sln", "SlnFileWithNoProjectReferencesAndCSharpProject", "CSharpProject", "CSharpProject.csproj", ProjectTypeGuids.CSharpProjectTypeGuid)] + [InlineData("sln", "SlnFileWithNoProjectReferencesAndFSharpProject", "FSharpProject", "FSharpProject.fsproj", ProjectTypeGuids.FSharpProjectTypeGuid)] + [InlineData("sln", "SlnFileWithNoProjectReferencesAndVBProject", "VBProject", "VBProject.vbproj", ProjectTypeGuids.VBProjectTypeGuid)] + [InlineData("sln", "SlnFileWithNoProjectReferencesAndUnknownProjectWithSingleProjectTypeGuid", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")] + [InlineData("sln", "SlnFileWithNoProjectReferencesAndUnknownProjectWithMultipleProjectTypeGuids", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")] + [InlineData("solution", "SlnFileWithNoProjectReferencesAndCSharpProject", "CSharpProject", "CSharpProject.csproj", ProjectTypeGuids.CSharpProjectTypeGuid)] + [InlineData("solution", "SlnFileWithNoProjectReferencesAndFSharpProject", "FSharpProject", "FSharpProject.fsproj", ProjectTypeGuids.FSharpProjectTypeGuid)] + [InlineData("solution", "SlnFileWithNoProjectReferencesAndVBProject", "VBProject", "VBProject.vbproj", ProjectTypeGuids.VBProjectTypeGuid)] + [InlineData("solution", "SlnFileWithNoProjectReferencesAndUnknownProjectWithSingleProjectTypeGuid", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")] + [InlineData("solution", "SlnFileWithNoProjectReferencesAndUnknownProjectWithMultipleProjectTypeGuids", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")] public void WhenPassedAProjectItAddsCorrectProjectTypeGuid( + string solutionCommand, string testAsset, string projectDir, string projectName, string expectedTypeGuid) { var projectDirectory = _testAssetsManager - .CopyTestAsset(testAsset) + .CopyTestAsset(testAsset, identifier: $"{solutionCommand}{testAsset}") .WithSource() .Path; var projectToAdd = Path.Combine(projectDir, projectName); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); cmd.StdErr.Should().BeEmpty(); cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, projectToAdd)); @@ -1028,11 +1096,13 @@ public void WhenPassedAProjectItAddsCorrectProjectTypeGuid( nonSolutionFolderProjects.Single().TypeGuid.Should().Be(expectedTypeGuid); } - [Fact] - public void WhenPassedAProjectWithoutATypeGuidItErrors() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenPassedAProjectWithoutATypeGuidItErrors(string solutionCommand) { var solutionDirectory = _testAssetsManager - .CopyTestAsset("SlnFileWithNoProjectReferencesAndUnknownProjectType") + .CopyTestAsset("SlnFileWithNoProjectReferencesAndUnknownProjectType", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1042,7 +1112,7 @@ public void WhenPassedAProjectWithoutATypeGuidItErrors() var projectToAdd = Path.Combine("UnknownProject", "UnknownProject.unknownproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(solutionDirectory) - .Execute($"sln", "add", projectToAdd); + .Execute(solutionCommand, "add", projectToAdd); cmd.Should().Pass(); cmd.StdErr.Should().Be( string.Format( @@ -1055,18 +1125,20 @@ public void WhenPassedAProjectWithoutATypeGuidItErrors() .BeVisuallyEquivalentTo(contentBefore); } - [Fact] - private void WhenSlnContainsSolutionFolderWithDifferentCasingItDoesNotCreateDuplicate() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + private void WhenSlnContainsSolutionFolderWithDifferentCasingItDoesNotCreateDuplicate(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCaseSensitiveSolutionFolders") + .CopyTestAsset("TestAppWithSlnAndCaseSensitiveSolutionFolders", identifier: $"{solutionCommand}") .WithSource() .Path; var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", projectToAdd); cmd.Should().Pass(); var slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln")); @@ -1075,11 +1147,13 @@ private void WhenSlnContainsSolutionFolderWithDifferentCasingItDoesNotCreateDupl solutionFolderProjects.Count().Should().Be(1); } - [Fact] - public void WhenProjectWithoutMatchingConfigurationsIsAddedSolutionMapsToFirstAvailable() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectWithoutMatchingConfigurationsIsAddedSolutionMapsToFirstAvailable(string solutionCommand) { var slnDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndProjectConfigs") + .CopyTestAsset("TestAppWithSlnAndProjectConfigs", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1087,18 +1161,20 @@ public void WhenProjectWithoutMatchingConfigurationsIsAddedSolutionMapsToFirstAv var result = new DotnetCommand(Log) .WithWorkingDirectory(slnDirectory) - .Execute($"sln", "add", "ProjectWithoutMatchingConfigs"); + .Execute(solutionCommand, "add", "ProjectWithoutMatchingConfigs"); result.Should().Pass(); File.ReadAllText(slnFullPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnFileAfterAddingProjectWithoutMatchingConfigs); } - [Fact] - public void WhenProjectWithMatchingConfigurationsIsAddedSolutionMapsAll() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectWithMatchingConfigurationsIsAddedSolutionMapsAll(string solutionCommand) { var slnDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndProjectConfigs") + .CopyTestAsset("TestAppWithSlnAndProjectConfigs", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1106,18 +1182,20 @@ public void WhenProjectWithMatchingConfigurationsIsAddedSolutionMapsAll() var result = new DotnetCommand(Log) .WithWorkingDirectory(slnDirectory) - .Execute($"sln", "add", "ProjectWithMatchingConfigs"); + .Execute(solutionCommand, "add", "ProjectWithMatchingConfigs"); result.Should().Pass(); File.ReadAllText(slnFullPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnFileAfterAddingProjectWithMatchingConfigs); } - [Fact] - public void WhenProjectWithAdditionalConfigurationsIsAddedSolutionDoesNotMapThem() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectWithAdditionalConfigurationsIsAddedSolutionDoesNotMapThem(string solutionCommand) { var slnDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndProjectConfigs") + .CopyTestAsset("TestAppWithSlnAndProjectConfigs", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1125,18 +1203,20 @@ public void WhenProjectWithAdditionalConfigurationsIsAddedSolutionDoesNotMapThem var result = new DotnetCommand(Log) .WithWorkingDirectory(slnDirectory) - .Execute($"sln", "add", "ProjectWithAdditionalConfigs"); + .Execute(solutionCommand, "add", "ProjectWithAdditionalConfigs"); result.Should().Pass(); File.ReadAllText(slnFullPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnFileAfterAddingProjectWithAdditionalConfigs); } - [Fact] - public void ItAddsACSharpProjectThatIsMultitargeted() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void ItAddsACSharpProjectThatIsMultitargeted(string solutionCommand) { var solutionDirectory = _testAssetsManager - .CopyTestAsset("TestAppsWithSlnAndMultitargetedProjects") + .CopyTestAsset("TestAppsWithSlnAndMultitargetedProjects", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1144,18 +1224,20 @@ public void ItAddsACSharpProjectThatIsMultitargeted() new DotnetCommand(Log) .WithWorkingDirectory(solutionDirectory) - .Execute($"sln", "add", projectToAdd) + .Execute(solutionCommand, "add", projectToAdd) .Should() .Pass() .And .HaveStdOutContaining(string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, projectToAdd)); } - [Fact] - public void ItAddsAVisualBasicProjectThatIsMultitargeted() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void ItAddsAVisualBasicProjectThatIsMultitargeted(string solutionCommand) { var solutionDirectory = _testAssetsManager - .CopyTestAsset("TestAppsWithSlnAndMultitargetedProjects") + .CopyTestAsset("TestAppsWithSlnAndMultitargetedProjects", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1163,18 +1245,20 @@ public void ItAddsAVisualBasicProjectThatIsMultitargeted() new DotnetCommand(Log) .WithWorkingDirectory(solutionDirectory) - .Execute($"sln", "add", projectToAdd) + .Execute(solutionCommand, "add", projectToAdd) .Should() .Pass() .And .HaveStdOutContaining(string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, projectToAdd)); } - [Fact] - public void ItAddsAnFSharpProjectThatIsMultitargeted() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void ItAddsAnFSharpProjectThatIsMultitargeted(string solutionCommand) { var solutionDirectory = _testAssetsManager - .CopyTestAsset("TestAppsWithSlnAndMultitargetedProjects") + .CopyTestAsset("TestAppsWithSlnAndMultitargetedProjects", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1183,25 +1267,27 @@ public void ItAddsAnFSharpProjectThatIsMultitargeted() new DotnetCommand(Log) .WithWorkingDirectory(solutionDirectory) - .Execute($"sln", "add", projectToAdd) + .Execute(solutionCommand, "add", projectToAdd) .Should() .Pass() .And .HaveStdOutContaining(string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, projectToAdd)); } - [Fact] - public void WhenNestedProjectIsAddedAndInRootOptionIsPassedNoSolutionFoldersAreCreated() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNestedProjectIsAddedAndInRootOptionIsPassedNoSolutionFoldersAreCreated(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir") + .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir", identifier: $"{solutionCommand}") .WithSource() .Path; var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", "--in-root", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", "--in-root", projectToAdd); cmd.Should().Pass(); var slnPath = Path.Combine(projectDirectory, "App.sln"); @@ -1210,18 +1296,20 @@ public void WhenNestedProjectIsAddedAndInRootOptionIsPassedNoSolutionFoldersAreC .Should().BeVisuallyEquivalentTo(expectedSlnContents); } - [Fact] - public void WhenSolutionFolderIsPassedProjectsAreAddedThere() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSolutionFolderIsPassedProjectsAreAddedThere(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir") + .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir", identifier: $"{solutionCommand}") .WithSource() .Path; var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", "--solution-folder", "TestFolder", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", "--solution-folder", "TestFolder", projectToAdd); cmd.Should().Pass(); var slnPath = Path.Combine(projectDirectory, "App.sln"); @@ -1230,11 +1318,13 @@ public void WhenSolutionFolderIsPassedProjectsAreAddedThere() .Should().BeVisuallyEquivalentTo(expectedSlnContents); } - [Fact] - public void WhenSolutionFolderAndInRootIsPassedItFails() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSolutionFolderAndInRootIsPassedItFails(string solutionCommand) { var solutionDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir") + .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -1244,7 +1334,7 @@ public void WhenSolutionFolderAndInRootIsPassedItFails() var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(solutionDirectory) - .Execute($"sln", "App.sln", "add", "--solution-folder", "blah", "--in-root", projectToAdd); + .Execute(solutionCommand, "App.sln", "add", "--solution-folder", "blah", "--in-root", projectToAdd); cmd.Should().Fail(); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); cmd.StdErr.Should().Be(Tools.Sln.LocalizableStrings.SolutionFolderAndInRootMutuallyExclusive); @@ -1256,19 +1346,21 @@ public void WhenSolutionFolderAndInRootIsPassedItFails() } [Theory] - [InlineData("/TestFolder//", "ForwardSlash")] - [InlineData("\\TestFolder\\\\", "BackwardSlash")] - public void WhenSolutionFolderIsPassedWithDirectorySeparatorFolderStructureIsCorrect(string solutionFolder, string testIdentifier) + [InlineData("sln", "/TestFolder//", "ForwardSlash")] + [InlineData("sln", "\\TestFolder\\\\", "BackwardSlash")] + [InlineData("solution", "/TestFolder//", "ForwardSlash")] + [InlineData("solution", "\\TestFolder\\\\", "BackwardSlash")] + public void WhenSolutionFolderIsPassedWithDirectorySeparatorFolderStructureIsCorrect(string solutionCommand, string solutionFolder, string testIdentifier) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir", identifier: testIdentifier) + .CopyTestAsset("TestAppWithSlnAndCsprojInSubDir", identifier: $"{solutionCommand}{testIdentifier}") .WithSource() .Path; var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "add", "--solution-folder", solutionFolder, projectToAdd); + .Execute(solutionCommand, "App.sln", "add", "--solution-folder", solutionFolder, projectToAdd); cmd.Should().Pass(); var slnPath = Path.Combine(projectDirectory, "App.sln"); @@ -1315,39 +1407,45 @@ private string GetExpectedSlnContents( return slnContents; } - [Fact] - public void WhenSolutionIsPassedAsProjectItPrintsSuggestionAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSolutionIsPassedAsProjectItPrintsSuggestionAndUsage(string solutionCommand) { - VerifySuggestionAndUsage(""); + VerifySuggestionAndUsage(solutionCommand, ""); } - [Fact] - public void WhenSolutionIsPassedAsProjectWithInRootItPrintsSuggestionAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSolutionIsPassedAsProjectWithInRootItPrintsSuggestionAndUsage(string solutionCommand) { - VerifySuggestionAndUsage("--in-root"); + VerifySuggestionAndUsage(solutionCommand, "--in-root"); } - [Fact] - public void WhenSolutionIsPassedAsProjectWithSolutionFolderItPrintsSuggestionAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSolutionIsPassedAsProjectWithSolutionFolderItPrintsSuggestionAndUsage(string solutionCommand) { - VerifySuggestionAndUsage("--solution-folder"); + VerifySuggestionAndUsage(solutionCommand, "--solution-folder"); } - private void VerifySuggestionAndUsage(string arguments) + private void VerifySuggestionAndUsage(string solutionCommand, string arguments) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}{arguments}") .WithSource() .Path; var projectArg = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "add", arguments, "Lib", "App.sln", projectArg); + .Execute(solutionCommand, "add", arguments, "Lib", "App.sln", projectArg); cmd.Should().Fail(); cmd.StdErr.Should().BeVisuallyEquivalentTo( string.Format(CommonLocalizableStrings.SolutionArgumentMisplaced, "App.sln") + Environment.NewLine + CommonLocalizableStrings.DidYouMean + Environment.NewLine - + $" dotnet sln App.sln add {arguments} Lib {projectArg}" + + $" dotnet solution App.sln add {arguments} Lib {projectArg}" ); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } diff --git a/test/dotnet-sln.Tests/GivenDotnetSlnList.cs b/test/dotnet-sln.Tests/GivenDotnetSlnList.cs index edc2c390cd8e..77670963b1ad 100644 --- a/test/dotnet-sln.Tests/GivenDotnetSlnList.cs +++ b/test/dotnet-sln.Tests/GivenDotnetSlnList.cs @@ -14,7 +14,7 @@ public class GivenDotnetSlnList : SdkTest List all projects in a solution file. Usage: - dotnet sln list [options] + dotnet solution list [options] Arguments: The solution file to operate on. If not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}] @@ -29,54 +29,67 @@ public GivenDotnetSlnList(ITestOutputHelper log) : base(log) } [Theory] - [InlineData("--help")] - [InlineData("-h")] - public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg) + [InlineData("sln", "--help")] + [InlineData("sln", "-h")] + [InlineData("solution", "--help")] + [InlineData("solution", "-h")] + public void WhenHelpOptionIsPassedItPrintsUsage(string solutionCommand, string helpArg) { var cmd = new DotnetCommand(Log) - .Execute($"sln", "list", helpArg); + .Execute(solutionCommand, "list", helpArg); cmd.Should().Pass(); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText(Directory.GetCurrentDirectory())); } [Theory] - [InlineData("")] - [InlineData("unknownCommandName")] - public void WhenNoCommandIsPassedItPrintsError(string commandName) + [InlineData("sln", "")] + [InlineData("sln", "unknownCommandName")] + [InlineData("solution", "")] + [InlineData("solution", "unknownCommandName")] + public void WhenNoCommandIsPassedItPrintsError(string solutionCommand, string commandName) { var cmd = new DotnetCommand(Log) - .Execute($"sln", commandName); + .Execute(solutionCommand, commandName); cmd.Should().Fail(); cmd.StdErr.Should().Be(CommonLocalizableStrings.RequiredCommandNotPassed); } - [Fact] - public void WhenTooManyArgumentsArePassedItPrintsError() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenTooManyArgumentsArePassedItPrintsError(string solutionCommand) { var cmd = new DotnetCommand(Log) - .Execute("sln", "one.sln", "two.sln", "three.sln", "list"); + .Execute(solutionCommand, "one.sln", "two.sln", "three.sln", "list"); cmd.Should().Fail(); cmd.StdErr.Should().BeVisuallyEquivalentTo($@"{string.Format(CommandLineValidation.LocalizableStrings.UnrecognizedCommandOrArgument, "two.sln")} {string.Format(CommandLineValidation.LocalizableStrings.UnrecognizedCommandOrArgument, "three.sln")}"); } [Theory] - [InlineData("idontexist.sln")] - [InlineData("ihave?invalidcharacters.sln")] - [InlineData("ihaveinv@lidcharacters.sln")] - [InlineData("ihaveinvalid/characters")] - [InlineData("ihaveinvalidchar\\acters")] - public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solutionName) + [InlineData("sln", "idontexist.sln")] + [InlineData("sln", "ihave?invalidcharacters.sln")] + [InlineData("sln", "ihaveinv@lidcharacters.sln")] + [InlineData("sln", "ihaveinvalid/characters")] + [InlineData("sln", "ihaveinvalidchar\\acters")] + [InlineData("solution", "idontexist.sln")] + [InlineData("solution", "ihave?invalidcharacters.sln")] + [InlineData("solution", "ihaveinv@lidcharacters.sln")] + [InlineData("solution", "ihaveinvalid/characters")] + [InlineData("solution", "ihaveinvalidchar\\acters")] + public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solutionCommand, string solutionName) { var cmd = new DotnetCommand(Log) - .Execute($"sln", solutionName, "list"); + .Execute(solutionCommand, solutionName, "list"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindSolutionOrDirectory, solutionName)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager .CopyTestAsset("InvalidSolution", identifier: "GivenDotnetSlnList") @@ -85,14 +98,16 @@ public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "InvalidSolution.sln", "list"); + .Execute(solutionCommand, "InvalidSolution.sln", "list"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", LocalizableStrings.FileHeaderMissingError)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenInvalidSolutionIsFoundListPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenInvalidSolutionIsFoundListPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager .CopyTestAsset("InvalidSolution") @@ -102,14 +117,16 @@ public void WhenInvalidSolutionIsFoundListPrintsErrorAndUsage() var solutionFullPath = Path.Combine(projectDirectory, "InvalidSolution.sln"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "list"); + .Execute(solutionCommand, "list"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, solutionFullPath, LocalizableStrings.FileHeaderMissingError)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenNoSolutionExistsInTheDirectoryListPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNoSolutionExistsInTheDirectoryListPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager .CopyTestAsset("TestAppWithSlnAndCsprojFiles") @@ -119,14 +136,16 @@ public void WhenNoSolutionExistsInTheDirectoryListPrintsErrorAndUsage() var solutionDir = Path.Combine(projectDirectory, "App"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(solutionDir) - .Execute("sln", "list"); + .Execute(solutionCommand, "list"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.SolutionDoesNotExist, solutionDir + Path.DirectorySeparatorChar)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager .CopyTestAsset("TestAppWithMultipleSlnFiles", identifier: "GivenDotnetSlnList") @@ -135,14 +154,16 @@ public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "list"); + .Execute(solutionCommand, "list"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.MoreThanOneSolutionInDirectory, projectDirectory + Path.DirectorySeparatorChar)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenNoProjectsArePresentInTheSolutionItPrintsANoProjectMessage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNoProjectsArePresentInTheSolutionItPrintsANoProjectMessage(string solutionCommand) { var projectDirectory = _testAssetsManager .CopyTestAsset("TestAppWithEmptySln") @@ -151,13 +172,15 @@ public void WhenNoProjectsArePresentInTheSolutionItPrintsANoProjectMessage() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "list"); + .Execute(solutionCommand, "list"); cmd.Should().Pass(); cmd.StdOut.Should().Be(CommonLocalizableStrings.NoProjectsFound); } - [Fact] - public void WhenProjectsPresentInTheSolutionItListsThem() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectsPresentInTheSolutionItListsThem(string solutionCommand) { var expectedOutput = $@"{CommandLocalizableStrings.ProjectsHeader} {new string('-', CommandLocalizableStrings.ProjectsHeader.Length)} @@ -171,13 +194,15 @@ public void WhenProjectsPresentInTheSolutionItListsThem() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "list"); + .Execute(solutionCommand, "list"); cmd.Should().Pass(); cmd.StdOut.Should().BeVisuallyEquivalentTo(expectedOutput); } - [Fact] - public void WhenProjectsPresentInTheReadonlySolutionItListsThem() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectsPresentInTheReadonlySolutionItListsThem(string solutionCommand) { var expectedOutput = $@"{CommandLocalizableStrings.ProjectsHeader} {new string('-', CommandLocalizableStrings.ProjectsHeader.Length)} @@ -195,13 +220,15 @@ public void WhenProjectsPresentInTheReadonlySolutionItListsThem() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "list"); + .Execute(solutionCommand, "list"); cmd.Should().Pass(); cmd.StdOut.Should().BeVisuallyEquivalentTo(expectedOutput); } - [Fact] - public void WhenProjectsInSolutionFoldersPresentInTheSolutionItListsSolutionFolderPaths() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectsInSolutionFoldersPresentInTheSolutionItListsSolutionFolderPaths(string solutionCommand) { string[] expectedOutput = { $"{CommandLocalizableStrings.SolutionFolderHeader}", $"{new string('-', CommandLocalizableStrings.SolutionFolderHeader.Length)}", @@ -214,7 +241,7 @@ public void WhenProjectsInSolutionFoldersPresentInTheSolutionItListsSolutionFold var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "list", "--solution-folders"); + .Execute(solutionCommand, "list", "--solution-folders"); cmd.Should().Pass(); cmd.StdOut.Should().ContainAll(expectedOutput); } diff --git a/test/dotnet-sln.Tests/GivenDotnetSlnRemove.cs b/test/dotnet-sln.Tests/GivenDotnetSlnRemove.cs index ff1f95711c00..b54349830c48 100644 --- a/test/dotnet-sln.Tests/GivenDotnetSlnRemove.cs +++ b/test/dotnet-sln.Tests/GivenDotnetSlnRemove.cs @@ -13,7 +13,7 @@ public class GivenDotnetSlnRemove : SdkTest Remove one or more projects from a solution file. Usage: - dotnet sln remove [...] [options] + dotnet solution remove [...] [options] Arguments: The solution file to operate on. If not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}] @@ -242,74 +242,89 @@ public GivenDotnetSlnRemove(ITestOutputHelper log) : base(log) } [Theory] - [InlineData("--help")] - [InlineData("-h")] - public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg) + [InlineData("sln", "--help")] + [InlineData("sln", "-h")] + [InlineData("solution", "--help")] + [InlineData("solution", "-h")] + public void WhenHelpOptionIsPassedItPrintsUsage(string solutionCommand, string helpArg) { var cmd = new DotnetCommand(Log) - .Execute($"sln", "remove", helpArg); + .Execute(solutionCommand, "remove", helpArg); cmd.Should().Pass(); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText(Directory.GetCurrentDirectory())); } - [Fact] - public void WhenTooManyArgumentsArePassedItPrintsError() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenTooManyArgumentsArePassedItPrintsError(string solutionCommand) { var cmd = new DotnetCommand(Log) - .Execute("sln", "one.sln", "two.sln", "three.sln", "remove"); + .Execute(solutionCommand, "one.sln", "two.sln", "three.sln", "remove"); cmd.Should().Fail(); cmd.StdErr.Should().BeVisuallyEquivalentTo($@"{string.Format(CommandLineValidation.LocalizableStrings.UnrecognizedCommandOrArgument, "two.sln")} {string.Format(CommandLineValidation.LocalizableStrings.UnrecognizedCommandOrArgument, "three.sln")}"); } [Theory] - [InlineData("")] - [InlineData("unknownCommandName")] - public void WhenNoCommandIsPassedItPrintsError(string commandName) + [InlineData("sln", "")] + [InlineData("sln", "unknownCommandName")] + [InlineData("solution", "")] + [InlineData("solution", "unknownCommandName")] + public void WhenNoCommandIsPassedItPrintsError(string solutionCommand, string commandName) { var cmd = new DotnetCommand(Log) - .Execute($"sln", commandName); + .Execute(solutionCommand, commandName); cmd.Should().Fail(); cmd.StdErr.Should().Be(CommonLocalizableStrings.RequiredCommandNotPassed); } [Theory] - [InlineData("idontexist.sln")] - [InlineData("ihave?invalidcharacters")] - [InlineData("ihaveinv@lidcharacters")] - [InlineData("ihaveinvalid/characters")] - [InlineData("ihaveinvalidchar\\acters")] - public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solutionName) + [InlineData("sln", "idontexist.sln")] + [InlineData("sln", "ihave?invalidcharacters")] + [InlineData("sln", "ihaveinv@lidcharacters")] + [InlineData("sln", "ihaveinvalid/characters")] + [InlineData("sln", "ihaveinvalidchar\\acters")] + [InlineData("solution", "idontexist.sln")] + [InlineData("solution", "ihave?invalidcharacters")] + [InlineData("solution", "ihaveinv@lidcharacters")] + [InlineData("solution", "ihaveinvalid/characters")] + [InlineData("solution", "ihaveinvalidchar\\acters")] + public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solutionCommand, string solutionName) { var cmd = new DotnetCommand(Log) - .Execute($"sln", solutionName, "remove", "p.csproj"); + .Execute(solutionCommand, solutionName, "remove", "p.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindSolutionOrDirectory, solutionName)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("InvalidSolution", identifier: "GivenDotnetSlnRemove") + .CopyTestAsset("InvalidSolution", identifier: $"{solutionCommand}GivenDotnetSlnRemove") .WithSource() .Path; var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "InvalidSolution.sln", "remove", projectToRemove); + .Execute(solutionCommand, "InvalidSolution.sln", "remove", projectToRemove); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", LocalizableStrings.FileHeaderMissingError)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenInvalidSolutionIsFoundRemovePrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenInvalidSolutionIsFoundRemovePrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("InvalidSolution") + .CopyTestAsset("InvalidSolution", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -317,67 +332,75 @@ public void WhenInvalidSolutionIsFoundRemovePrintsErrorAndUsage() var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, solutionPath, LocalizableStrings.FileHeaderMissingError)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenNoProjectIsPassedItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNoProjectIsPassedItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: "GivenDotnetSlnRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}GivenDotnetSlnRemove") .WithSource() .Path; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute(@"sln", "App.sln", "remove"); + .Execute(solutionCommand, "App.sln", "remove"); cmd.Should().Fail(); cmd.StdErr.Should().Be(CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenNoSolutionExistsInTheDirectoryRemovePrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNoSolutionExistsInTheDirectoryRemovePrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; var solutionPath = Path.Combine(projectDirectory, "App"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(solutionPath) - .Execute(@"sln", "remove", "App.csproj"); + .Execute(solutionCommand, "remove", "App.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.SolutionDoesNotExist, solutionPath + Path.DirectorySeparatorChar)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithMultipleSlnFiles", identifier: "GivenDotnetSlnRemove") + .CopyTestAsset("TestAppWithMultipleSlnFiles", identifier: $"{solutionCommand}GivenDotnetSlnRemove") .WithSource() .Path; var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Fail(); cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.MoreThanOneSolutionInDirectory, projectDirectory + Path.DirectorySeparatorChar)); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenPassedAReferenceNotInSlnItPrintsStatus() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenPassedAReferenceNotInSlnItPrintsStatus(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndExistingCsprojReferences") + .CopyTestAsset("TestAppWithSlnAndExistingCsprojReferences", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -385,18 +408,20 @@ public void WhenPassedAReferenceNotInSlnItPrintsStatus() var contentBefore = File.ReadAllText(solutionPath); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "remove", "referenceDoesNotExistInSln.csproj"); + .Execute(solutionCommand, "remove", "referenceDoesNotExistInSln.csproj"); cmd.Should().Pass(); cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectNotFoundInTheSolution, "referenceDoesNotExistInSln.csproj")); File.ReadAllText(solutionPath) .Should().BeVisuallyEquivalentTo(contentBefore); } - [Fact] - public void WhenPassedAReferenceItRemovesTheReferenceButNotOtherReferences() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenPassedAReferenceItRemovesTheReferenceButNotOtherReferences(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndExistingCsprojReferences") + .CopyTestAsset("TestAppWithSlnAndExistingCsprojReferences", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -407,7 +432,7 @@ public void WhenPassedAReferenceItRemovesTheReferenceButNotOtherReferences() var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectRemovedFromTheSolution, projectToRemove)); @@ -416,11 +441,13 @@ public void WhenPassedAReferenceItRemovesTheReferenceButNotOtherReferences() slnFile.Projects[0].FilePath.Should().Be(Path.Combine("App", "App.csproj")); } - [Fact] - public void WhenSolutionItemsExistInFolderParentFoldersAreNotRemoved() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSolutionItemsExistInFolderParentFoldersAreNotRemoved(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("SlnFileWithSolutionItemsInNestedFolders") + .CopyTestAsset("SlnFileWithSolutionItemsInNestedFolders", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -430,7 +457,7 @@ public void WhenSolutionItemsExistInFolderParentFoldersAreNotRemoved() var projectToRemove = Path.Combine("ConsoleApp1", "ConsoleApp1.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectRemovedFromTheSolution, projectToRemove)); @@ -440,11 +467,13 @@ public void WhenSolutionItemsExistInFolderParentFoldersAreNotRemoved() .BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemoveProjectInSolutionWithNestedSolutionItems); } - [Fact] - public void WhenDuplicateReferencesArePresentItRemovesThemAll() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenDuplicateReferencesArePresentItRemovesThemAll(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndDuplicateProjectReferences") + .CopyTestAsset("TestAppWithSlnAndDuplicateProjectReferences", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -455,7 +484,7 @@ public void WhenDuplicateReferencesArePresentItRemovesThemAll() var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); string outputText = string.Format(CommonLocalizableStrings.ProjectRemovedFromTheSolution, projectToRemove); @@ -467,11 +496,13 @@ public void WhenDuplicateReferencesArePresentItRemovesThemAll() slnFile.Projects[0].FilePath.Should().Be(Path.Combine("App", "App.csproj")); } - [Fact] - public void WhenPassedMultipleReferencesAndOneOfThemDoesNotExistItRemovesTheOneThatExists() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenPassedMultipleReferencesAndOneOfThemDoesNotExistItRemovesTheOneThatExists(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndExistingCsprojReferences") + .CopyTestAsset("TestAppWithSlnAndExistingCsprojReferences", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -482,7 +513,7 @@ public void WhenPassedMultipleReferencesAndOneOfThemDoesNotExistItRemovesTheOneT var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", "idontexist.csproj", projectToRemove, "idontexisteither.csproj"); + .Execute(solutionCommand, "remove", "idontexist.csproj", projectToRemove, "idontexisteither.csproj"); cmd.Should().Pass(); string outputText = $@"{string.Format(CommonLocalizableStrings.ProjectNotFoundInTheSolution, "idontexist.csproj")} @@ -496,11 +527,13 @@ public void WhenPassedMultipleReferencesAndOneOfThemDoesNotExistItRemovesTheOneT slnFile.Projects[0].FilePath.Should().Be(Path.Combine("App", "App.csproj")); } - [Fact] - public void WhenReferenceIsRemovedBuildConfigsAreAlsoRemoved() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenReferenceIsRemovedBuildConfigsAreAlsoRemoved(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -511,18 +544,20 @@ public void WhenReferenceIsRemovedBuildConfigsAreAlsoRemoved() var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); File.ReadAllText(solutionPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemove); } - [Fact] - public void WhenDirectoryContainingProjectIsGivenProjectIsRemoved() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenDirectoryContainingProjectIsGivenProjectIsRemoved(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -532,25 +567,27 @@ public void WhenDirectoryContainingProjectIsGivenProjectIsRemoved() var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "remove", "Lib"); + .Execute(solutionCommand, "remove", "Lib"); cmd.Should().Pass(); File.ReadAllText(solutionPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemove); } - [Fact] - public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; var directoryToRemove = "Empty"; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", directoryToRemove); + .Execute(solutionCommand, "remove", directoryToRemove); cmd.Should().Fail(); cmd.StdErr.Should().Be( string.Format( @@ -559,18 +596,20 @@ public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation() cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; var directoryToRemove = "Multiple"; var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", directoryToRemove); + .Execute(solutionCommand, "remove", directoryToRemove); cmd.Should().Fail(); cmd.StdErr.Should().Be( string.Format( @@ -579,11 +618,13 @@ public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation() cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } - [Fact] - public void WhenReferenceIsRemovedSlnBuilds() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenReferenceIsRemovedSlnBuilds(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -594,7 +635,7 @@ public void WhenReferenceIsRemovedSlnBuilds() var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); new DotnetCommand(Log) @@ -618,18 +659,20 @@ public void WhenReferenceIsRemovedSlnBuilds() outputDirectory.Should().HaveFile("App.dll"); } - [Fact] - public void WhenProjectIsRemovedSolutionHasUTF8BOM() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectIsRemovedSolutionHasUTF8BOM(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; var projectToRemove = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "App.sln", "remove", projectToRemove); + .Execute(solutionCommand, "App.sln", "remove", projectToRemove); cmd.Should().Pass(); var preamble = Encoding.UTF8.GetPreamble(); @@ -644,11 +687,13 @@ public void WhenProjectIsRemovedSolutionHasUTF8BOM() } } - [Fact] - public void WhenFinalReferenceIsRemovedEmptySectionsAreRemoved() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenFinalReferenceIsRemovedEmptySectionsAreRemoved(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -660,7 +705,7 @@ public void WhenFinalReferenceIsRemovedEmptySectionsAreRemoved() var libPath = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", libPath, appPath); + .Execute(solutionCommand, "remove", libPath, appPath); cmd.Should().Pass(); var solutionContents = File.ReadAllText(solutionPath); @@ -668,11 +713,13 @@ public void WhenFinalReferenceIsRemovedEmptySectionsAreRemoved() solutionContents.Should().BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemoveAllProjects); } - [Fact] - public void WhenNestedProjectIsRemovedItsSolutionFoldersAreRemoved() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenNestedProjectIsRemovedItsSolutionFoldersAreRemoved(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojInSubDirToRemove") + .CopyTestAsset("TestAppWithSlnAndCsprojInSubDirToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -681,18 +728,20 @@ public void WhenNestedProjectIsRemovedItsSolutionFoldersAreRemoved() var projectToRemove = Path.Combine("src", "NotLastProjInSrc", "NotLastProjInSrc.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); File.ReadAllText(solutionPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemoveNestedProj); } - [Fact] - public void WhenFinalNestedProjectIsRemovedSolutionFoldersAreRemoved() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenFinalNestedProjectIsRemovedSolutionFoldersAreRemoved(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndLastCsprojInSubDirToRemove") + .CopyTestAsset("TestAppWithSlnAndLastCsprojInSubDirToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -701,18 +750,20 @@ public void WhenFinalNestedProjectIsRemovedSolutionFoldersAreRemoved() var projectToRemove = Path.Combine("src", "Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); File.ReadAllText(solutionPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemoveLastNestedProj); } - [Fact] - public void WhenProjectIsRemovedThenDependenciesOnProjectAreAlsoRemoved() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenProjectIsRemovedThenDependenciesOnProjectAreAlsoRemoved(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnProjectDependencyToRemove") + .CopyTestAsset("TestAppWithSlnProjectDependencyToRemove", identifier: $"{solutionCommand}") .WithSource() .Path; @@ -721,30 +772,32 @@ public void WhenProjectIsRemovedThenDependenciesOnProjectAreAlsoRemoved() var projectToRemove = Path.Combine("Second", "Second.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute($"sln", "remove", projectToRemove); + .Execute(solutionCommand, "remove", projectToRemove); cmd.Should().Pass(); File.ReadAllText(solutionPath) .Should().BeVisuallyEquivalentTo(ExpectedSlnContentsAfterRemoveProjectWithDependencies); } - [Fact] - public void WhenSolutionIsPassedAsProjectItPrintsSuggestionAndUsage() + [Theory] + [InlineData("sln")] + [InlineData("solution")] + public void WhenSolutionIsPassedAsProjectItPrintsSuggestionAndUsage(string solutionCommand) { var projectDirectory = _testAssetsManager - .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .CopyTestAsset("TestAppWithSlnAndCsprojFiles", identifier: $"{solutionCommand}") .WithSource() .Path; var projectArg = Path.Combine("Lib", "Lib.csproj"); var cmd = new DotnetCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute("sln", "remove", "App.sln", projectArg); + .Execute(solutionCommand, "remove", "App.sln", projectArg); cmd.Should().Fail(); cmd.StdErr.Should().BeVisuallyEquivalentTo( string.Format(CommonLocalizableStrings.SolutionArgumentMisplaced, "App.sln") + Environment.NewLine + CommonLocalizableStrings.DidYouMean + Environment.NewLine - + $" dotnet sln App.sln remove {projectArg}" + + $" dotnet solution App.sln remove {projectArg}" ); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } diff --git a/test/dotnet-watch.Tests/CommandLineOptionsTests.cs b/test/dotnet-watch.Tests/CommandLineOptionsTests.cs index 1ac5b5e49470..00b40547dcc5 100644 --- a/test/dotnet-watch.Tests/CommandLineOptionsTests.cs +++ b/test/dotnet-watch.Tests/CommandLineOptionsTests.cs @@ -99,7 +99,7 @@ public void ImplicitCommand() [InlineData("restore")] [InlineData("run")] [InlineData("sdk")] - [InlineData("sln")] + [InlineData("solution")] [InlineData("store")] [InlineData("test")] [InlineData("tool")] @@ -183,7 +183,7 @@ public void RunOptions_NoProfile_Both() public void RemainingOptions() { var options = VerifyOptions(["-watchArg", "--verbose", "run", "-runArg"]); - + Assert.True(options.GlobalOptions.Verbose); Assert.Equal("run", options.Command); Assert.Equal(["-watchArg", "-runArg"], options.CommandArguments); diff --git a/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs b/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs index 88ee00d47099..28737029377c 100644 --- a/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/CompleteCommandTests.cs @@ -46,6 +46,7 @@ public void GivenOnlyDotnetItSuggestsTopLevelCommandsAndOptions() "restore", "run", "sln", + "solution", "store", "test", "tool", diff --git a/test/dotnet.Tests/TelemetryCommandTest.cs b/test/dotnet.Tests/TelemetryCommandTest.cs index e7fc9a77bab5..39cb9ed6882a 100644 --- a/test/dotnet.Tests/TelemetryCommandTest.cs +++ b/test/dotnet.Tests/TelemetryCommandTest.cs @@ -213,7 +213,7 @@ public void DotnetSlnCommandFirstArgumentShouldBeSentToTelemetry() e.Properties.ContainsKey("argument") && e.Properties["argument"] == Sha256Hasher.Hash(argumentToSend.ToUpper()) && e.Properties.ContainsKey("verb") && - e.Properties["verb"] == Sha256Hasher.Hash("SLN")); + e.Properties["verb"] == Sha256Hasher.Hash("SOLUTION")); } [Fact]