public override int Execute() { ToolAppliedOption.EnsureNoConflictGlobalLocalToolPathOption( _parseResult, LocalizableStrings.InstallToolCommandInvalidGlobalAndLocalAndToolPath); ToolAppliedOption.EnsureToolManifestAndOnlyLocalFlagCombination( _parseResult); if (_global || !string.IsNullOrWhiteSpace(_toolPath)) { return(_toolInstallGlobalOrToolPathCommand.Execute()); } else { if (!string.IsNullOrWhiteSpace(_framework)) { throw new GracefulException( string.Format( LocalizableStrings.LocalOptionDoesNotSupportFrameworkOption)); } return(_toolInstallLocalCommand.Execute()); } }
public override int Execute() { EnsureNoConflictGlobalLocalToolPathOption(); if (_global || !string.IsNullOrWhiteSpace(_toolPath)) { if (!string.IsNullOrWhiteSpace(_toolManifestOption)) { throw new GracefulException( string.Format( LocalizableStrings.OnlyLocalOptionSupportManifestFileOption)); } return(_toolInstallGlobalOrToolPathCommand.Execute()); } else { if (!string.IsNullOrWhiteSpace(_framework)) { throw new GracefulException( string.Format( LocalizableStrings.LocalOptionDoesNotSupportFrameworkOption)); } return(_toolInstallLocalCommand.Execute()); } }
public void WhenRunWithPackageIdItShouldShowPathInstruction() { var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( _parseResult, _createToolPackageStoreAndInstaller, _createShellShimRepository, _environmentPathInstructionMock, _reporter); toolInstallGlobalOrToolPathCommand.Execute().Should().Be(0); _reporter.Lines.First().Should().Be(EnvironmentPathInstructionMock.MockInstructionText); }
public void WhenRunWithPackageIdAndBinPathItShouldNoteHaveEnvironmentPathInstruction() { var result = Parser.Instance.Parse($"dotnet tool install --tool-path /tmp/folder {PackageId}"); var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( result, _createToolPackageStoreAndInstaller, _createShellShimRepository, new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim), _reporter); toolInstallGlobalOrToolPathCommand.Execute().Should().Be(0); _reporter.Lines.Should().NotContain(l => l.Contains(EnvironmentPathInstructionMock.MockInstructionText)); }
public void WhenRunWithArchOptionItErrorsOnInvalidRids() { _reporter.Clear(); var parseResult = Parser.Instance.Parse($"dotnet tool install -g {PackageId} -a invalid"); var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( parseResult, _createToolPackageStoreAndInstaller, _createShellShimRepository, _environmentPathInstructionMock, _reporter); var exceptionThrown = Assert.Throws <AggregateException>(() => toolInstallGlobalOrToolPathCommand.Execute()); exceptionThrown.Message.Should().Contain("-invalid is invalid"); }
public void WhenRunWithArchOptionItDownloadsAppHostTemplate() { var nugetPackageDownloader = new MockNuGetPackageDownloader(); var parseResult = Parser.Instance.Parse($"dotnet tool install -g {PackageId} -a arm64"); var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( parseResult, _createToolPackageStoreAndInstaller, _createShellShimRepository, _environmentPathInstructionMock, _reporter, nugetPackageDownloader); toolInstallGlobalOrToolPathCommand.Execute().Should().Be(0); nugetPackageDownloader.DownloadCallParams.Count.Should().Be(1); nugetPackageDownloader.ExtractCallParams.Count.Should().Be(1); nugetPackageDownloader.DownloadCallParams.First().Item1.Should().Be(new PackageId("microsoft.netcore.app.host.win-arm64")); }
public void WhenRunWithPackageIdItShouldCreateValidShim() { var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( _parseResult, _createToolPackageStoreAndInstaller, _createShellShimRepository, _environmentPathInstructionMock, _reporter); toolInstallGlobalOrToolPathCommand.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 = JsonSerializer.Deserialize <AppHostShellShimMakerMock.FakeShim>( _fileSystem.File.ReadAllText(ExpectedCommandPath())); _fileSystem.File.Exists(deserializedFakeShim.ExecutablePath).Should().BeTrue(); }
public void WhenRunWithoutAMatchingRangeItShouldFail() { ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version [5.0,10.0]"); var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( result, _createToolPackageStoreAndInstaller, _createShellShimRepository, new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true), _reporter); Action a = () => toolInstallGlobalOrToolPathCommand.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}"); var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( result, _createToolPackageStoreAndInstaller, _createShellShimRepository, new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true), _reporter); Action action = () => toolInstallGlobalOrToolPathCommand.Execute(); action .ShouldThrow <GracefulException>() .WithMessage(string.Format( LocalizableStrings.InvalidNuGetVersionRange, invalidVersion)); }
public void WhenRunWithPackageIdItShouldShowSuccessMessage() { var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( _parseResult, _createToolPackageStoreAndInstaller, _createShellShimRepository, new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true), _reporter); toolInstallGlobalOrToolPathCommand.Execute().Should().Be(0); _reporter .Lines .Should() .Equal(string.Format( LocalizableStrings.InstallationSucceeded, ToolCommandName, PackageId, PackageVersion).Green()); }
public void GivenCreateShimItShouldHaveNoBrokenFolderOnDisk() { _fileSystem.File.CreateEmptyFile(ExpectedCommandPath()); // Create conflict shim var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( _parseResult, _createToolPackageStoreAndInstaller, _createShellShimRepository, _environmentPathInstructionMock, _reporter); Action a = () => toolInstallGlobalOrToolPathCommand.Execute(); a.ShouldThrow <GracefulException>().And.Message .Should().Contain(string.Format( CommonLocalizableStrings.ShellShimConflict, ToolCommandName)); _fileSystem.Directory.Exists(Path.Combine(_pathToPlacePackages, PackageId)).Should().BeFalse(); }
public void WhenRunWithValidVersionWildcardItShouldSucceed() { ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version 1.0.*"); var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand( result, _createToolPackageStoreAndInstaller, _createShellShimRepository, new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim, true), _reporter); toolInstallGlobalOrToolPathCommand.Execute().Should().Be(0); _reporter .Lines .Should() .Equal(string.Format( LocalizableStrings.InstallationSucceeded, ToolCommandName, PackageId, PackageVersion).Green()); }