2016-12-16 16:41:47 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using FluentAssertions;
|
|
|
|
using Microsoft.DotNet.Cli.Sln.Internal;
|
2017-06-14 04:13:47 +00:00
|
|
|
using Microsoft.DotNet.Tools;
|
2016-12-16 16:41:47 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using Xunit;
|
2018-05-09 22:29:51 +00:00
|
|
|
using CommandLocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings;
|
2016-12-16 16:41:47 +00:00
|
|
|
|
2017-01-06 20:58:23 +00:00
|
|
|
namespace Microsoft.DotNet.Cli.Sln.List.Tests
|
2016-12-16 16:41:47 +00:00
|
|
|
{
|
2017-01-06 20:58:23 +00:00
|
|
|
public class GivenDotnetSlnList : TestBase
|
2016-12-16 16:41:47 +00:00
|
|
|
{
|
2017-06-27 00:17:51 +00:00
|
|
|
private const string HelpText = @"Usage: dotnet sln <SLN_FILE> list [options]
|
2016-12-16 16:41:47 +00:00
|
|
|
|
|
|
|
Arguments:
|
2018-04-30 20:42:47 +00:00
|
|
|
<SLN_FILE> The solution file to operate on. If not specified, the command will search the current directory for one.
|
2016-12-16 16:41:47 +00:00
|
|
|
|
|
|
|
Options:
|
2018-04-30 20:42:47 +00:00
|
|
|
-h, --help Show command line help.";
|
2016-12-16 16:41:47 +00:00
|
|
|
|
2017-06-27 00:17:51 +00:00
|
|
|
private const string SlnCommandHelpText = @"Usage: dotnet sln [options] <SLN_FILE> [command]
|
2017-05-03 23:01:35 +00:00
|
|
|
|
|
|
|
Arguments:
|
2018-04-30 20:42:47 +00:00
|
|
|
<SLN_FILE> The solution file to operate on. If not specified, the command will search the current directory for one.
|
2017-05-03 23:01:35 +00:00
|
|
|
|
|
|
|
Options:
|
2018-04-30 20:42:47 +00:00
|
|
|
-h, --help Show command line help.
|
2017-05-03 23:01:35 +00:00
|
|
|
|
|
|
|
Commands:
|
2018-04-30 20:42:47 +00:00
|
|
|
add <PROJECT_PATH> Add one or more projects to a solution file.
|
|
|
|
list List all projects in a solution file.
|
|
|
|
remove <PROJECT_PATH> Remove one or more projects from a solution file.";
|
2017-05-03 23:01:35 +00:00
|
|
|
|
2016-12-16 16:41:47 +00:00
|
|
|
[Theory]
|
|
|
|
[InlineData("--help")]
|
|
|
|
[InlineData("-h")]
|
|
|
|
public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg)
|
|
|
|
{
|
|
|
|
var cmd = new DotnetCommand()
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput($"sln list {helpArg}");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Pass();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("")]
|
|
|
|
[InlineData("unknownCommandName")]
|
|
|
|
public void WhenNoCommandIsPassedItPrintsError(string commandName)
|
|
|
|
{
|
|
|
|
var cmd = new DotnetCommand()
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput($"sln {commandName}");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Fail();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdErr.Should().Be(CommonLocalizableStrings.RequiredCommandNotPassed);
|
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(SlnCommandHelpText);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenTooManyArgumentsArePassedItPrintsError()
|
|
|
|
{
|
|
|
|
var cmd = new DotnetCommand()
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput("sln one.sln two.sln three.sln list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Fail();
|
2017-06-27 20:26:14 +00:00
|
|
|
cmd.StdErr.Should().BeVisuallyEquivalentTo($@"{string.Format(CommandLine.LocalizableStrings.UnrecognizedCommandOrArgument, "two.sln")}
|
|
|
|
{string.Format(CommandLine.LocalizableStrings.UnrecognizedCommandOrArgument, "three.sln")}");
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("idontexist.sln")]
|
|
|
|
[InlineData("ihave?invalidcharacters.sln")]
|
|
|
|
[InlineData("ihaveinv@lidcharacters.sln")]
|
|
|
|
[InlineData("ihaveinvalid/characters")]
|
|
|
|
[InlineData("ihaveinvalidchar\\acters")]
|
|
|
|
public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solutionName)
|
|
|
|
{
|
|
|
|
var cmd = new DotnetCommand()
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput($"sln {solutionName} list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Fail();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindSolutionOrDirectory, solutionName));
|
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage()
|
|
|
|
{
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get("InvalidSolution")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput("sln InvalidSolution.sln list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Fail();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", LocalizableStrings.FileHeaderMissingError));
|
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenInvalidSolutionIsFoundItPrintsErrorAndUsage()
|
|
|
|
{
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get("InvalidSolution")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var solutionFullPath = Path.Combine(projectDirectory, "InvalidSolution.sln");
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput("sln list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Fail();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, solutionFullPath, LocalizableStrings.FileHeaderMissingError));
|
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenNoSolutionExistsInTheDirectoryItPrintsErrorAndUsage()
|
|
|
|
{
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get("TestAppWithSlnAndCsprojFiles")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var solutionDir = Path.Combine(projectDirectory, "App");
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(solutionDir)
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput("sln list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Fail();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.SolutionDoesNotExist, solutionDir + Path.DirectorySeparatorChar));
|
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage()
|
|
|
|
{
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get("TestAppWithMultipleSlnFiles")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput("sln list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Fail();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.MoreThanOneSolutionInDirectory, projectDirectory + Path.DirectorySeparatorChar));
|
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2018-05-09 22:29:51 +00:00
|
|
|
public void WhenNoProjectsArePresentInTheSolutionItPrintsANoProjectMessage()
|
2016-12-16 16:41:47 +00:00
|
|
|
{
|
|
|
|
var projectDirectory = TestAssets
|
2017-01-03 17:18:45 +00:00
|
|
|
.Get("TestAppWithEmptySln")
|
2016-12-16 16:41:47 +00:00
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput("sln list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Pass();
|
2017-06-14 04:13:47 +00:00
|
|
|
cmd.StdOut.Should().Be(CommonLocalizableStrings.NoProjectsFound);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2018-05-09 22:29:51 +00:00
|
|
|
public void WhenProjectsPresentInTheSolutionItListsThem()
|
2016-12-16 16:41:47 +00:00
|
|
|
{
|
2018-05-09 22:29:51 +00:00
|
|
|
var expectedOutput = $@"{CommandLocalizableStrings.ProjectsHeader}
|
|
|
|
{new string('-', CommandLocalizableStrings.ProjectsHeader.Length)}
|
2016-12-20 23:04:01 +00:00
|
|
|
{Path.Combine("App", "App.csproj")}
|
|
|
|
{Path.Combine("Lib", "Lib.csproj")}";
|
2016-12-16 18:23:26 +00:00
|
|
|
|
2016-12-16 16:41:47 +00:00
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get("TestAppWithSlnAndExistingCsprojReferences")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
2017-01-06 20:58:23 +00:00
|
|
|
.ExecuteWithCapturedOutput("sln list");
|
2016-12-16 16:41:47 +00:00
|
|
|
cmd.Should().Pass();
|
2018-05-09 22:29:51 +00:00
|
|
|
cmd.StdOut.Should().BeVisuallyEquivalentTo(expectedOutput);
|
2016-12-16 16:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|