Exemplo n.º 1
0
        public ToolUninstallCommand(
            ParseResult result,
            IReporter reporter = null,
            ToolUninstallGlobalOrToolPathCommand toolUninstallGlobalOrToolPathCommand = null,
            ToolUninstallLocalCommand toolUninstallLocalCommand = null)
            : base(result)
        {
            _toolUninstallLocalCommand
                = toolUninstallLocalCommand ??
                  new ToolUninstallLocalCommand(result);

            _toolUninstallGlobalOrToolPathCommand =
                toolUninstallGlobalOrToolPathCommand
                ?? new ToolUninstallGlobalOrToolPathCommand(result);

            _global   = result.ValueForOption <bool>(ToolUninstallCommandParser.GlobalOption);
            _toolPath = result.ValueForOption <string>(ToolUninstallCommandParser.ToolPathOption);
        }
Exemplo n.º 2
0
        public ToolUninstallCommand(
            AppliedOption options,
            ParseResult result,
            IReporter reporter = null,
            ToolUninstallGlobalOrToolPathCommand toolUninstallGlobalOrToolPathCommand = null,
            ToolUninstallLocalCommand toolUninstallLocalCommand = null)
            : base(result)
        {
            _options = options ?? throw new ArgumentNullException(nameof(options));
            _toolUninstallLocalCommand
                = toolUninstallLocalCommand ??
                  new ToolUninstallLocalCommand(options, result);

            _toolUninstallGlobalOrToolPathCommand =
                toolUninstallGlobalOrToolPathCommand
                ?? new ToolUninstallGlobalOrToolPathCommand(options, result);

            _global   = options.ValueOrDefault <bool>(ToolAppliedOption.GlobalOption);
            _toolPath = options.SingleArgumentOrDefault(ToolAppliedOption.ToolPathOption);
        }
Exemplo n.º 3
0
        public ToolUninstallCommand(
            AppliedOption options,
            ParseResult result,
            IReporter reporter = null,
            ToolUninstallGlobalOrToolPathCommand toolUninstallGlobalOrToolPathCommand = null,
            ToolUninstallLocalCommand toolUninstallLocalCommand = null)
            : base(result)
        {
            _toolUninstallLocalCommand
                = toolUninstallLocalCommand ??
                  new ToolUninstallLocalCommand(options, result);

            _toolUninstallGlobalOrToolPathCommand =
                toolUninstallGlobalOrToolPathCommand
                ?? new ToolUninstallGlobalOrToolPathCommand(options, result);

            _global             = options.ValueOrDefault <bool>(GlobalOption);
            _local              = options.ValueOrDefault <bool>(LocalOption);
            _toolPath           = options.SingleArgumentOrDefault(ToolPathOption);
            _toolManifestOption = options.ValueOrDefault <string>("tool-manifest");
        }
        public void GivenAPackageWhenCallFromUninstallRedirectCommandItUninstalls()
        {
            CreateInstallCommand($"-g {PackageId}").Execute().Should().Be(0);

            _reporter
            .Lines
            .Last()
            .Should()
            .Contain(string.Format(
                         InstallLocalizableStrings.InstallationSucceeded,
                         ProjectRestorerMock.DefaultToolCommandName,
                         PackageId,
                         PackageVersion));

            var packageDirectory = new DirectoryPath(Path.GetFullPath(_toolsDirectory))
                                   .WithSubDirectories(PackageId, PackageVersion);
            var shimPath = Path.Combine(
                _shimsDirectory,
                ProjectRestorerMock.DefaultToolCommandName +
                (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));

            _fileSystem.Directory.Exists(packageDirectory.Value).Should().BeTrue();
            _fileSystem.File.Exists(shimPath).Should().BeTrue();

            _reporter.Lines.Clear();


            ParseResult result = Parser.Instance.Parse("dotnet tool uninstall " + $"-g {PackageId}");

            (IToolPackageStore, IToolPackageStoreQuery, IToolPackageUninstaller) CreateToolPackageStoreAndUninstaller(
                DirectoryPath?directoryPath)
            {
                var store = new ToolPackageStoreMock(
                    new DirectoryPath(_toolsDirectory),
                    _fileSystem);
                var packageUninstaller = new ToolPackageUninstallerMock(_fileSystem, store);

                return(store, store, packageUninstaller);
            }

            var toolUninstallGlobalOrToolPathCommand = new ToolUninstallGlobalOrToolPathCommand(
                result,
                CreateToolPackageStoreAndUninstaller,
                (_) => new ShellShimRepository(
                    new DirectoryPath(_shimsDirectory),
                    fileSystem: _fileSystem,
                    appHostShellShimMaker: new AppHostShellShimMakerMock(_fileSystem)),
                _reporter);

            var uninstallCommand
                = new ToolUninstallCommand(
                      result,
                      toolUninstallGlobalOrToolPathCommand: toolUninstallGlobalOrToolPathCommand);

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

            _reporter
            .Lines
            .Single()
            .Should()
            .Contain(string.Format(
                         LocalizableStrings.UninstallSucceeded,
                         PackageId,
                         PackageVersion));

            _fileSystem.Directory.Exists(packageDirectory.Value).Should().BeFalse();
            _fileSystem.File.Exists(shimPath).Should().BeFalse();
        }