2018-01-24 18:16:27 +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 System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Microsoft.DotNet.Cli;
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
using Microsoft.DotNet.ToolPackage;
|
2018-01-28 21:35:04 +00:00
|
|
|
using Microsoft.DotNet.Tools;
|
2018-03-22 02:12:32 +00:00
|
|
|
using Microsoft.DotNet.Tools.Tool.Install;
|
2018-01-24 18:16:27 +00:00
|
|
|
using Microsoft.DotNet.Tools.Tests.ComponentMocks;
|
2018-01-18 03:26:52 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2018-01-24 18:16:27 +00:00
|
|
|
using Microsoft.Extensions.DependencyModel.Tests;
|
|
|
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Xunit;
|
|
|
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
2018-02-06 21:38:06 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2018-03-22 02:12:32 +00:00
|
|
|
using LocalizableStrings = Microsoft.DotNet.Tools.Tool.Install.LocalizableStrings;
|
2018-03-06 23:58:05 +00:00
|
|
|
using Microsoft.DotNet.ShellShim;
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-01-28 21:35:04 +00:00
|
|
|
namespace Microsoft.DotNet.Tests.Commands
|
2018-01-24 18:16:27 +00:00
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
public class ToolInstallCommandTests
|
2018-01-24 18:16:27 +00:00
|
|
|
{
|
2018-01-28 21:35:04 +00:00
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
private readonly IToolPackageStore _toolPackageStore;
|
2018-03-06 23:58:05 +00:00
|
|
|
private readonly CreateShellShimRepository _createShellShimRepository;
|
|
|
|
private readonly CreateToolPackageStoreAndInstaller _createToolPackageStoreAndInstaller;
|
2018-01-24 18:16:27 +00:00
|
|
|
private readonly EnvironmentPathInstructionMock _environmentPathInstructionMock;
|
|
|
|
private readonly AppliedOption _appliedCommand;
|
|
|
|
private readonly ParseResult _parseResult;
|
2018-01-18 03:26:52 +00:00
|
|
|
private readonly BufferedReporter _reporter;
|
2018-01-24 18:16:27 +00:00
|
|
|
private const string PathToPlaceShim = "pathToPlace";
|
2018-02-06 21:38:06 +00:00
|
|
|
private const string PathToPlacePackages = PathToPlaceShim + "pkg";
|
|
|
|
private const string PackageId = "global.tool.console.demo";
|
2018-01-28 21:35:04 +00:00
|
|
|
private const string PackageVersion = "1.0.4";
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
public ToolInstallCommandTests()
|
2018-01-24 18:16:27 +00:00
|
|
|
{
|
2018-01-18 03:26:52 +00:00
|
|
|
_reporter = new BufferedReporter();
|
2018-01-28 21:35:04 +00:00
|
|
|
_fileSystem = new FileSystemMockBuilder().Build();
|
|
|
|
_toolPackageStore = new ToolPackageStoreMock(new DirectoryPath(PathToPlacePackages), _fileSystem);
|
2018-03-06 23:58:05 +00:00
|
|
|
_createShellShimRepository =
|
|
|
|
(nonGlobalLocation) => new ShellShimRepositoryMock(new DirectoryPath(PathToPlaceShim), _fileSystem);
|
2018-01-24 18:16:27 +00:00
|
|
|
_environmentPathInstructionMock =
|
2018-01-18 03:26:52 +00:00
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim);
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller = (_) => (_toolPackageStore, CreateToolPackageInstaller());
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId}");
|
|
|
|
_appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-01-24 18:16:27 +00:00
|
|
|
var parser = Parser.Instance;
|
2018-03-22 02:12:32 +00:00
|
|
|
_parseResult = parser.ParseFrom("dotnet tool", new[] {"install", "-g", PackageId});
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithPackageIdItShouldCreateValidShim()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
var installToolCommand = new ToolInstallCommand(_appliedCommand,
|
2018-01-24 18:16:27 +00:00
|
|
|
_parseResult,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-01-28 21:35:04 +00:00
|
|
|
_environmentPathInstructionMock,
|
|
|
|
_reporter);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
installToolCommand.Execute().Should().Be(0);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
|
|
|
// It is hard to simulate shell behavior. Only Assert shim can point to executable dll
|
2018-01-28 21:35:04 +00:00
|
|
|
_fileSystem.File.Exists(ExpectedCommandPath()).Should().BeTrue();
|
|
|
|
var deserializedFakeShim = JsonConvert.DeserializeObject<ShellShimRepositoryMock.FakeShim>(
|
|
|
|
_fileSystem.File.ReadAllText(ExpectedCommandPath()));
|
|
|
|
|
|
|
|
_fileSystem.File.Exists(deserializedFakeShim.ExecutablePath).Should().BeTrue();
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithPackageIdWithSourceItShouldCreateValidShim()
|
|
|
|
{
|
|
|
|
const string sourcePath = "http://mysouce.com";
|
2018-03-22 02:12:32 +00:00
|
|
|
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --source-feed {sourcePath}");
|
|
|
|
AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-01-24 18:16:27 +00:00
|
|
|
ParseResult parseResult =
|
2018-03-22 02:12:32 +00:00
|
|
|
Parser.Instance.ParseFrom("dotnet tool", new[] { "install", "-g", PackageId, "--source-feed", sourcePath });
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-06 23:58:05 +00:00
|
|
|
|
|
|
|
var toolToolPackageInstaller = CreateToolPackageInstaller(
|
|
|
|
feeds: new MockFeed[] {
|
|
|
|
new MockFeed
|
|
|
|
{
|
2018-03-20 05:22:45 +00:00
|
|
|
Type = MockFeedType.ImplicitAdditionalFeed,
|
2018-03-06 23:58:05 +00:00
|
|
|
Uri = sourcePath,
|
|
|
|
Packages = new List<MockFeedPackage>
|
2018-01-24 18:16:27 +00:00
|
|
|
{
|
2018-03-06 23:58:05 +00:00
|
|
|
new MockFeedPackage
|
2018-01-24 18:16:27 +00:00
|
|
|
{
|
2018-03-06 23:58:05 +00:00
|
|
|
PackageId = PackageId,
|
|
|
|
Version = PackageVersion
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-06 23:58:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(appliedCommand,
|
2018-03-06 23:58:05 +00:00
|
|
|
parseResult,
|
|
|
|
(_) => (_toolPackageStore, toolToolPackageInstaller),
|
|
|
|
_createShellShimRepository,
|
2018-01-28 21:35:04 +00:00
|
|
|
_environmentPathInstructionMock,
|
|
|
|
_reporter);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
installCommand.Execute().Should().Be(0);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
|
|
|
// It is hard to simulate shell behavior. Only Assert shim can point to executable dll
|
2018-01-28 21:35:04 +00:00
|
|
|
_fileSystem.File.Exists(ExpectedCommandPath())
|
2018-02-06 21:38:06 +00:00
|
|
|
.Should().BeTrue();
|
2018-01-28 21:35:04 +00:00
|
|
|
var deserializedFakeShim =
|
|
|
|
JsonConvert.DeserializeObject<ShellShimRepositoryMock.FakeShim>(
|
|
|
|
_fileSystem.File.ReadAllText(ExpectedCommandPath()));
|
|
|
|
_fileSystem.File.Exists(deserializedFakeShim.ExecutablePath).Should().BeTrue();
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithPackageIdItShouldShowPathInstruction()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(_appliedCommand,
|
2018-01-24 18:16:27 +00:00
|
|
|
_parseResult,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-01-28 21:35:04 +00:00
|
|
|
_environmentPathInstructionMock,
|
|
|
|
_reporter);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
installCommand.Execute().Should().Be(0);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-06 23:58:05 +00:00
|
|
|
_reporter.Lines.First().Should().Be(EnvironmentPathInstructionMock.MockInstructionText);
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 19:50:09 +00:00
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithPackageIdPackageFormatIsNotFullySupportedItShouldShowPathInstruction()
|
|
|
|
{
|
|
|
|
const string Warning = "WARNING";
|
|
|
|
var injectedWarnings = new Dictionary<PackageId, IEnumerable<string>>()
|
|
|
|
{
|
|
|
|
[new PackageId(PackageId)] = new List<string>() { Warning }
|
|
|
|
};
|
|
|
|
|
|
|
|
var toolPackageInstaller = new ToolPackageInstallerMock(
|
|
|
|
fileSystem: _fileSystem,
|
|
|
|
store: _toolPackageStore,
|
|
|
|
projectRestorer: new ProjectRestorerMock(
|
|
|
|
fileSystem: _fileSystem,
|
|
|
|
reporter: _reporter),
|
|
|
|
warningsMap: injectedWarnings);
|
|
|
|
|
|
|
|
var installToolCommand = new ToolInstallCommand(
|
|
|
|
_appliedCommand,
|
|
|
|
_parseResult,
|
|
|
|
(_) => (_toolPackageStore, toolPackageInstaller),
|
|
|
|
_createShellShimRepository,
|
|
|
|
_environmentPathInstructionMock,
|
|
|
|
_reporter);
|
|
|
|
|
|
|
|
installToolCommand.Execute().Should().Be(0);
|
|
|
|
|
|
|
|
_reporter.Lines.First().Should().Be(Warning.Yellow());
|
|
|
|
_reporter.Lines.Skip(1).First().Should().Be(EnvironmentPathInstructionMock.MockInstructionText);
|
|
|
|
}
|
|
|
|
|
2018-01-24 18:16:27 +00:00
|
|
|
[Fact]
|
2018-01-28 21:35:04 +00:00
|
|
|
public void GivenFailedPackageInstallWhenRunWithPackageIdItShouldFail()
|
2018-01-24 18:16:27 +00:00
|
|
|
{
|
2018-03-06 23:58:05 +00:00
|
|
|
var toolPackageInstaller =
|
|
|
|
CreateToolPackageInstaller(
|
|
|
|
installCallback: () => throw new ToolPackageException("Simulated error"));
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-01-24 18:16:27 +00:00
|
|
|
_appliedCommand,
|
|
|
|
_parseResult,
|
2018-03-06 23:58:05 +00:00
|
|
|
(_) => (_toolPackageStore, toolPackageInstaller),
|
|
|
|
_createShellShimRepository,
|
2018-01-24 18:16:27 +00:00
|
|
|
_environmentPathInstructionMock,
|
2018-01-18 03:26:52 +00:00
|
|
|
_reporter);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
Action a = () => installCommand.Execute();
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-08 23:49:16 +00:00
|
|
|
a.ShouldThrow<GracefulException>().And.Message
|
2018-03-16 02:45:11 +00:00
|
|
|
.Should().Contain(
|
|
|
|
"Simulated error" + Environment.NewLine
|
|
|
|
+ string.Format(LocalizableStrings.ToolInstallationFailed, PackageId));
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-01-28 21:35:04 +00:00
|
|
|
_fileSystem.Directory.Exists(Path.Combine(PathToPlacePackages, PackageId)).Should().BeFalse();
|
2018-02-06 21:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GivenCreateShimItShouldHaveNoBrokenFolderOnDisk()
|
|
|
|
{
|
2018-01-28 21:35:04 +00:00
|
|
|
_fileSystem.File.CreateEmptyFile(ExpectedCommandPath()); // Create conflict shim
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-02-06 21:38:06 +00:00
|
|
|
_appliedCommand,
|
|
|
|
_parseResult,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-02-06 21:38:06 +00:00
|
|
|
_environmentPathInstructionMock,
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
Action a = () => installCommand.Execute();
|
2018-01-28 21:35:04 +00:00
|
|
|
|
2018-03-08 23:49:16 +00:00
|
|
|
a.ShouldThrow<GracefulException>().And.Message
|
|
|
|
.Should().Contain(string.Format(
|
|
|
|
CommonLocalizableStrings.ShellShimConflict,
|
|
|
|
ProjectRestorerMock.FakeCommandName));
|
2018-02-06 21:38:06 +00:00
|
|
|
|
2018-01-28 21:35:04 +00:00
|
|
|
_fileSystem.Directory.Exists(Path.Combine(PathToPlacePackages, PackageId)).Should().BeFalse();
|
2018-02-06 21:38:06 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 18:16:27 +00:00
|
|
|
[Fact]
|
2018-01-18 03:26:52 +00:00
|
|
|
public void GivenInCorrectToolConfigurationWhenRunWithPackageIdItShouldFail()
|
2018-01-24 18:16:27 +00:00
|
|
|
{
|
2018-03-06 23:58:05 +00:00
|
|
|
var toolPackageInstaller =
|
|
|
|
CreateToolPackageInstaller(
|
|
|
|
installCallback: () => throw new ToolConfigurationException("Simulated error"));
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-01-24 18:16:27 +00:00
|
|
|
_appliedCommand,
|
|
|
|
_parseResult,
|
2018-03-06 23:58:05 +00:00
|
|
|
(_) => (_toolPackageStore, toolPackageInstaller),
|
|
|
|
_createShellShimRepository,
|
2018-01-24 18:16:27 +00:00
|
|
|
_environmentPathInstructionMock,
|
2018-01-18 03:26:52 +00:00
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
Action a = () => installCommand.Execute();
|
2018-01-18 03:26:52 +00:00
|
|
|
|
2018-03-08 23:49:16 +00:00
|
|
|
a.ShouldThrow<GracefulException>().And.Message
|
|
|
|
.Should().Contain(
|
2018-01-18 03:26:52 +00:00
|
|
|
string.Format(
|
|
|
|
LocalizableStrings.InvalidToolConfiguration,
|
2018-03-08 23:49:16 +00:00
|
|
|
"Simulated error") + Environment.NewLine +
|
|
|
|
string.Format(LocalizableStrings.ToolInstallationFailedContactAuthor, PackageId)
|
|
|
|
);
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithPackageIdItShouldShowSuccessMessage()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-01-24 18:16:27 +00:00
|
|
|
_appliedCommand,
|
|
|
|
_parseResult,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-01-18 03:26:52 +00:00
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
installCommand.Execute().Should().Be(0);
|
2018-01-24 18:16:27 +00:00
|
|
|
|
2018-01-18 03:26:52 +00:00
|
|
|
_reporter
|
|
|
|
.Lines
|
2018-01-28 21:35:04 +00:00
|
|
|
.Should()
|
2018-02-23 03:13:36 +00:00
|
|
|
.Equal(string.Format(
|
|
|
|
LocalizableStrings.InstallationSucceeded,
|
|
|
|
ProjectRestorerMock.FakeCommandName,
|
|
|
|
PackageId,
|
|
|
|
PackageVersion).Green());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithInvalidVersionItShouldThrow()
|
|
|
|
{
|
|
|
|
const string invalidVersion = "!NotValidVersion!";
|
2018-03-22 02:12:32 +00:00
|
|
|
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version {invalidVersion}");
|
|
|
|
AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-02-23 03:13:36 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-02-23 03:13:36 +00:00
|
|
|
appliedCommand,
|
|
|
|
result,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-02-23 03:13:36 +00:00
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
Action action = () => installCommand.Execute();
|
2018-02-23 03:13:36 +00:00
|
|
|
|
|
|
|
action
|
|
|
|
.ShouldThrow<GracefulException>()
|
|
|
|
.WithMessage(string.Format(
|
|
|
|
LocalizableStrings.InvalidNuGetVersionRange,
|
|
|
|
invalidVersion));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithExactVersionItShouldSucceed()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version {PackageVersion}");
|
|
|
|
AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-02-23 03:13:36 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-02-23 03:13:36 +00:00
|
|
|
appliedCommand,
|
|
|
|
result,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-02-23 03:13:36 +00:00
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
installCommand.Execute().Should().Be(0);
|
2018-02-23 03:13:36 +00:00
|
|
|
|
|
|
|
_reporter
|
|
|
|
.Lines
|
|
|
|
.Should()
|
|
|
|
.Equal(string.Format(
|
|
|
|
LocalizableStrings.InstallationSucceeded,
|
|
|
|
ProjectRestorerMock.FakeCommandName,
|
|
|
|
PackageId,
|
|
|
|
PackageVersion).Green());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithValidVersionRangeItShouldSucceed()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version [1.0,2.0]");
|
|
|
|
AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-02-23 03:13:36 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-02-23 03:13:36 +00:00
|
|
|
appliedCommand,
|
|
|
|
result,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-02-23 03:13:36 +00:00
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
installCommand.Execute().Should().Be(0);
|
2018-02-23 03:13:36 +00:00
|
|
|
|
|
|
|
_reporter
|
|
|
|
.Lines
|
|
|
|
.Should()
|
|
|
|
.Equal(string.Format(
|
|
|
|
LocalizableStrings.InstallationSucceeded,
|
|
|
|
ProjectRestorerMock.FakeCommandName,
|
|
|
|
PackageId,
|
|
|
|
PackageVersion).Green());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithoutAMatchingRangeItShouldFail()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version [5.0,10.0]");
|
|
|
|
AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-02-23 03:13:36 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-02-23 03:13:36 +00:00
|
|
|
appliedCommand,
|
|
|
|
result,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-02-23 03:13:36 +00:00
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
Action a = () => installCommand.Execute();
|
2018-02-23 03:13:36 +00:00
|
|
|
|
2018-03-08 23:49:16 +00:00
|
|
|
a.ShouldThrow<GracefulException>().And.Message
|
|
|
|
.Should().Contain(
|
|
|
|
LocalizableStrings.ToolInstallationRestoreFailed +
|
|
|
|
Environment.NewLine + string.Format(LocalizableStrings.ToolInstallationFailed, PackageId));
|
|
|
|
|
|
|
|
_fileSystem.Directory.Exists(Path.Combine(PathToPlacePackages, PackageId)).Should().BeFalse();
|
2018-02-23 03:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithValidVersionWildcardItShouldSucceed()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version 1.0.*");
|
|
|
|
AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-02-23 03:13:36 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-02-23 03:13:36 +00:00
|
|
|
appliedCommand,
|
|
|
|
result,
|
2018-03-06 23:58:05 +00:00
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
2018-02-23 03:13:36 +00:00
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
installCommand.Execute().Should().Be(0);
|
2018-02-23 03:13:36 +00:00
|
|
|
|
|
|
|
_reporter
|
|
|
|
.Lines
|
|
|
|
.Should()
|
|
|
|
.Equal(string.Format(
|
2018-01-28 21:35:04 +00:00
|
|
|
LocalizableStrings.InstallationSucceeded,
|
|
|
|
ProjectRestorerMock.FakeCommandName,
|
|
|
|
PackageId,
|
2018-02-23 03:13:36 +00:00
|
|
|
PackageVersion).Green());
|
2018-01-28 21:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 23:58:05 +00:00
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithBothGlobalAndToolPathShowErrorMessage()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
var result = Parser.Instance.Parse($"dotnet tool install -g --tool-path /tmp/folder {PackageId}");
|
|
|
|
var appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-03-06 23:58:05 +00:00
|
|
|
var parser = Parser.Instance;
|
2018-03-22 02:12:32 +00:00
|
|
|
var parseResult = parser.ParseFrom("dotnet tool", new[] {"install", "-g", PackageId});
|
2018-03-06 23:58:05 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-03-06 23:58:05 +00:00
|
|
|
appliedCommand,
|
|
|
|
parseResult,
|
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
Action a = () => installCommand.Execute();
|
2018-03-06 23:58:05 +00:00
|
|
|
|
|
|
|
a.ShouldThrow<GracefulException>().And.Message
|
|
|
|
.Should().Contain(LocalizableStrings.InstallToolCommandInvalidGlobalAndToolPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithNeitherOfGlobalNorToolPathShowErrorMessage()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
var result = Parser.Instance.Parse($"dotnet tool install {PackageId}");
|
|
|
|
var appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-03-06 23:58:05 +00:00
|
|
|
var parser = Parser.Instance;
|
2018-03-22 02:12:32 +00:00
|
|
|
var parseResult = parser.ParseFrom("dotnet tool", new[] { "install", "-g", PackageId });
|
2018-03-06 23:58:05 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(
|
2018-03-06 23:58:05 +00:00
|
|
|
appliedCommand,
|
|
|
|
parseResult,
|
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim, true),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
Action a = () => installCommand.Execute();
|
2018-03-06 23:58:05 +00:00
|
|
|
|
|
|
|
a.ShouldThrow<GracefulException>().And.Message
|
|
|
|
.Should().Contain(LocalizableStrings.InstallToolCommandNeedGlobalOrToolPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenRunWithPackageIdAndBinPathItShouldNoteHaveEnvironmentPathInstruction()
|
|
|
|
{
|
2018-03-22 02:12:32 +00:00
|
|
|
var result = Parser.Instance.Parse($"dotnet tool install --tool-path /tmp/folder {PackageId}");
|
|
|
|
var appliedCommand = result["dotnet"]["tool"]["install"];
|
2018-03-06 23:58:05 +00:00
|
|
|
var parser = Parser.Instance;
|
2018-03-22 02:12:32 +00:00
|
|
|
var parseResult = parser.ParseFrom("dotnet tool", new[] {"install", "-g", PackageId});
|
2018-03-06 23:58:05 +00:00
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
var installCommand = new ToolInstallCommand(appliedCommand,
|
2018-03-06 23:58:05 +00:00
|
|
|
parseResult,
|
|
|
|
_createToolPackageStoreAndInstaller,
|
|
|
|
_createShellShimRepository,
|
|
|
|
new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim),
|
|
|
|
_reporter);
|
|
|
|
|
2018-03-22 02:12:32 +00:00
|
|
|
installCommand.Execute().Should().Be(0);
|
2018-03-06 23:58:05 +00:00
|
|
|
|
|
|
|
_reporter.Lines.Should().NotContain(l => l.Contains(EnvironmentPathInstructionMock.MockInstructionText));
|
|
|
|
}
|
|
|
|
|
2018-01-28 21:35:04 +00:00
|
|
|
private IToolPackageInstaller CreateToolPackageInstaller(
|
|
|
|
IEnumerable<MockFeed> feeds = null,
|
|
|
|
Action installCallback = null)
|
|
|
|
{
|
|
|
|
return new ToolPackageInstallerMock(
|
|
|
|
fileSystem: _fileSystem,
|
|
|
|
store: _toolPackageStore,
|
|
|
|
projectRestorer: new ProjectRestorerMock(
|
|
|
|
fileSystem: _fileSystem,
|
|
|
|
reporter: _reporter,
|
|
|
|
feeds: feeds),
|
|
|
|
installCallback: installCallback);
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
2018-02-06 21:38:06 +00:00
|
|
|
|
|
|
|
private static string ExpectedCommandPath()
|
|
|
|
{
|
|
|
|
var extension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
|
|
|
|
return Path.Combine(
|
|
|
|
"pathToPlace",
|
2018-01-28 21:35:04 +00:00
|
|
|
ProjectRestorerMock.FakeCommandName + extension);
|
2018-02-06 21:38:06 +00:00
|
|
|
}
|
2018-01-24 18:16:27 +00:00
|
|
|
}
|
|
|
|
}
|