public void WhenRunFromToolInstallRedirectCommandWithPackageIdItShouldSaveToCacheAndAddToManifestFile() { var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand(); var toolInstallCommand = new ToolInstallCommand( _parseResult, toolInstallLocalCommand: toolInstallLocalCommand); toolInstallCommand.Execute().Should().Be(0); AssertDefaultInstallSuccess(); }
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); }
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); }
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")); }
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); }
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(); }
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(); }
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)); }
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); }
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); }
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")); }
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()); }
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(); }
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(); }
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)); }
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); }
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()); }