public void WhenRunFromToolInstallRedirectCommandWithPackageIdItShouldSaveToCacheAndAddToManifestFile()
        {
            var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand();

            var toolInstallCommand = new ToolInstallCommand(
                _parseResult,
                toolInstallLocalCommand: toolInstallLocalCommand);

            toolInstallCommand.Execute().Should().Be(0);
            AssertDefaultInstallSuccess();
        }
Esempio n. 2
0
        public void WhenRunWithGlobalAndToolManifestShowErrorMessage()
        {
            var parseResult = Parser.Instance.Parse(
                new[] { "dotnet", "tool", "install", "-g", "--tool-manifest", "folder/my-manifest.format", "PackageId" });

            var toolInstallCommand = new ToolInstallCommand(
                parseResult);

            Action a = () => toolInstallCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(Tools.Tool.Common.LocalizableStrings.OnlyLocalOptionSupportManifestFileOption);
        }
Esempio n. 3
0
        public void WhenRunWithPackageIdItShouldShowPathInstruction()
        {
            var installCommand = new ToolInstallCommand(_appliedCommand,
                                                        _parseResult,
                                                        _createToolPackageStoreAndInstaller,
                                                        _createShellShimRepository,
                                                        _environmentPathInstructionMock,
                                                        _reporter);

            installCommand.Execute().Should().Be(0);

            _reporter.Lines.First().Should().Be(EnvironmentPathInstructionMock.MockInstructionText);
        }
Esempio n. 4
0
        public void WhenRunWithBothGlobalAndToolPathShowErrorMessage()
        {
            var parseResult = Parser.Instance.Parse($"dotnet tool install -g --tool-path /tmp/folder {PackageId}");

            var toolInstallCommand = new ToolInstallCommand(
                parseResult);

            Action a = () => toolInstallCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(string.Format(
                                  LocalizableStrings.InstallToolCommandInvalidGlobalAndLocalAndToolPath,
                                  "global tool-path"));
        }
Esempio n. 5
0
        public void WhenRunWithLocalAndFrameworkShowErrorMessage()
        {
            var parseResult = Parser.Instance.Parse(
                new[]
            {
                "dotnet", "tool", "install", PackageId, "--framework", "netcoreapp2.1"
            });

            var toolInstallCommand = new ToolInstallCommand(
                parseResult);

            Action a = () => toolInstallCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(LocalizableStrings.LocalOptionDoesNotSupportFrameworkOption);
        }
Esempio n. 6
0
        public void WhenRunFromToolInstallRedirectCommandWithPackageIdItShouldCreateValidShim()
        {
            var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand(
                _parseResult,
                _createToolPackageStoreAndInstaller,
                _createShellShimRepository,
                _environmentPathInstructionMock,
                _reporter);

            var toolInstallCommand = new ToolInstallCommand(
                _parseResult,
                toolInstallGlobalOrToolPathCommand);

            toolInstallCommand.Execute().Should().Be(0);

            _fileSystem.File.Exists(ExpectedCommandPath()).Should().BeTrue();
        }
Esempio n. 7
0
        public void WhenRunWithPackageIdItShouldCreateValidShim()
        {
            var installToolCommand = new ToolInstallCommand(_appliedCommand,
                                                            _parseResult,
                                                            _createToolPackageStoreAndInstaller,
                                                            _createShellShimRepository,
                                                            _environmentPathInstructionMock,
                                                            _reporter);

            installToolCommand.Execute().Should().Be(0);

            // It is hard to simulate shell behavior. Only Assert shim can point to executable dll
            _fileSystem.File.Exists(ExpectedCommandPath()).Should().BeTrue();
            var deserializedFakeShim = JsonConvert.DeserializeObject <AppHostShellShimMakerMock.FakeShim>(
                _fileSystem.File.ReadAllText(ExpectedCommandPath()));

            _fileSystem.File.Exists(deserializedFakeShim.ExecutablePath).Should().BeTrue();
        }
Esempio n. 8
0
        public void WhenRunWithPackageIdAndBinPathItShouldNoteHaveEnvironmentPathInstruction()
        {
            var result         = Parser.Instance.Parse($"dotnet tool install --tool-path /tmp/folder {PackageId}");
            var appliedCommand = result["dotnet"]["tool"]["install"];
            var parser         = Parser.Instance;
            var parseResult    = parser.ParseFrom("dotnet tool", new[] { "install", "-g", PackageId });

            var installCommand = new ToolInstallCommand(appliedCommand,
                                                        parseResult,
                                                        _createToolPackageStoreAndInstaller,
                                                        _createShellShimRepository,
                                                        new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim),
                                                        _reporter);

            installCommand.Execute().Should().Be(0);

            _reporter.Lines.Should().NotContain(l => l.Contains(EnvironmentPathInstructionMock.MockInstructionText));
        }
Esempio n. 9
0
        public void WhenRunWithGlobalAndToolManifestShowErrorMessage()
        {
            var result =
                Parser.Instance.Parse($"dotnet tool install -g --tool-manifest folder/my-manifest.format {PackageId}");
            var appliedCommand = result["dotnet"]["tool"]["install"];
            var parser         = Parser.Instance;
            var parseResult    = parser.ParseFrom(
                "dotnet tool",
                new[] { "install", "-g", "--tool-manifest", "folder/my-manifest.format", "PackageId" });

            var toolInstallCommand = new ToolInstallCommand(
                appliedCommand,
                parseResult);

            Action a = () => toolInstallCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(LocalizableStrings.OnlyLocalOptionSupportManifestFileOption);
        }
Esempio n. 10
0
        public void WhenRunWithNeitherOfGlobalNorToolPathShowErrorMessage()
        {
            var result         = Parser.Instance.Parse($"dotnet tool install {PackageId}");
            var appliedCommand = result["dotnet"]["tool"]["install"];
            var parser         = Parser.Instance;
            var parseResult    = parser.ParseFrom("dotnet tool", new[] { "install", "-g", PackageId });

            var installCommand = new ToolInstallCommand(
                appliedCommand,
                parseResult,
                _createToolPackageStoreAndInstaller,
                _createShellShimRepository,
                new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true),
                _reporter);

            Action a = () => installCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(LocalizableStrings.InstallToolCommandNeedGlobalOrToolPath);
        }
Esempio n. 11
0
        public void WhenRunWithBothGlobalAndLocalShowErrorMessage()
        {
            var result         = Parser.Instance.Parse($"dotnet tool install --local --tool-path /tmp/folder {PackageId}");
            var appliedCommand = result["dotnet"]["tool"]["install"];
            var parser         = Parser.Instance;
            var parseResult    = parser.ParseFrom(
                "dotnet tool",
                new[] { "install", "--local", "--tool-path", "/tmp/folder", PackageId });

            var toolInstallCommand = new ToolInstallCommand(
                appliedCommand,
                parseResult);

            Action a = () => toolInstallCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(
                string.Format(LocalizableStrings.InstallToolCommandInvalidGlobalAndLocalAndToolPath,
                              "local tool-path"));
        }
Esempio n. 12
0
        public void WhenRunWithPackageIdItShouldShowSuccessMessage()
        {
            var installCommand = new ToolInstallCommand(
                _appliedCommand,
                _parseResult,
                _createToolPackageStoreAndInstaller,
                _createShellShimRepository,
                new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true),
                _reporter);

            installCommand.Execute().Should().Be(0);

            _reporter
            .Lines
            .Should()
            .Equal(string.Format(
                       LocalizableStrings.InstallationSucceeded,
                       ProjectRestorerMock.FakeCommandName,
                       PackageId,
                       PackageVersion).Green());
        }
Esempio n. 13
0
        public void GivenCreateShimItShouldHaveNoBrokenFolderOnDisk()
        {
            _fileSystem.File.CreateEmptyFile(ExpectedCommandPath()); // Create conflict shim

            var installCommand = new ToolInstallCommand(
                _appliedCommand,
                _parseResult,
                _createToolPackageStoreAndInstaller,
                _createShellShimRepository,
                _environmentPathInstructionMock,
                _reporter);

            Action a = () => installCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(string.Format(
                                  CommonLocalizableStrings.ShellShimConflict,
                                  ProjectRestorerMock.FakeCommandName));

            _fileSystem.Directory.Exists(Path.Combine(_pathToPlacePackages, PackageId)).Should().BeFalse();
        }
Esempio n. 14
0
        public void WhenRunWithoutAMatchingRangeItShouldFail()
        {
            ParseResult   result         = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version [5.0,10.0]");
            AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];

            var installCommand = new ToolInstallCommand(
                appliedCommand,
                result,
                _createToolPackageStoreAndInstaller,
                _createShellShimRepository,
                new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true),
                _reporter);

            Action a = () => installCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(
                LocalizableStrings.ToolInstallationRestoreFailed +
                Environment.NewLine + string.Format(LocalizableStrings.ToolInstallationFailedWithRestoreGuidance, PackageId));

            _fileSystem.Directory.Exists(Path.Combine(_pathToPlacePackages, PackageId)).Should().BeFalse();
        }
Esempio n. 15
0
        public void WhenRunWithInvalidVersionItShouldThrow()
        {
            const string  invalidVersion = "!NotValidVersion!";
            ParseResult   result         = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version {invalidVersion}");
            AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];

            var installCommand = new ToolInstallCommand(
                appliedCommand,
                result,
                _createToolPackageStoreAndInstaller,
                _createShellShimRepository,
                new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true),
                _reporter);

            Action action = () => installCommand.Execute();

            action
            .ShouldThrow <GracefulException>()
            .WithMessage(string.Format(
                             LocalizableStrings.InvalidNuGetVersionRange,
                             invalidVersion));
        }
Esempio n. 16
0
        public void WhenRunWithLocalAndFrameworkShowErrorMessage()
        {
            var result =
                Parser.Instance.Parse(
                    $"dotnet tool install {PackageId} --framework netcoreapp2.1");
            var appliedCommand = result["dotnet"]["tool"]["install"];
            var parser         = Parser.Instance;
            var parseResult    = parser.ParseFrom(
                "dotnet tool",
                new[]
            {
                "install", PackageId, "--framework", "netcoreapp2.1"
            });

            var toolInstallCommand = new ToolInstallCommand(
                appliedCommand,
                parseResult);

            Action a = () => toolInstallCommand.Execute();

            a.ShouldThrow <GracefulException>().And.Message
            .Should().Contain(LocalizableStrings.LocalOptionDoesNotSupportFrameworkOption);
        }
Esempio n. 17
0
        public void WhenRunWithValidVersionWildcardItShouldSucceed()
        {
            ParseResult   result         = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version 1.0.*");
            AppliedOption appliedCommand = result["dotnet"]["tool"]["install"];

            var installCommand = new ToolInstallCommand(
                appliedCommand,
                result,
                _createToolPackageStoreAndInstaller,
                _createShellShimRepository,
                new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true),
                _reporter);

            installCommand.Execute().Should().Be(0);

            _reporter
            .Lines
            .Should()
            .Equal(string.Format(
                       LocalizableStrings.InstallationSucceeded,
                       ProjectRestorerMock.FakeCommandName,
                       PackageId,
                       PackageVersion).Green());
        }