예제 #1
0
        public ToolInstallCommandTests()
        {
            _reporter            = new BufferedReporter();
            _fileSystem          = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _temporaryDirectory  = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _pathToPlaceShim     = Path.Combine(_temporaryDirectory, "pathToPlace");
            _pathToPlacePackages = _pathToPlaceShim + "Packages";
            var toolPackageStoreMock = new ToolPackageStoreMock(new DirectoryPath(_pathToPlacePackages), _fileSystem);

            _toolPackageStore          = toolPackageStoreMock;
            _toolPackageStoreQuery     = toolPackageStoreMock;
            _createShellShimRepository =
                (nonGlobalLocation) => new ShellShimRepository(
                    new DirectoryPath(_pathToPlaceShim),
                    fileSystem: _fileSystem,
                    appHostShellShimMaker: new AppHostShellShimMakerMock(_fileSystem),
                    filePermissionSetter: new NoOpFilePermissionSetter());
            _environmentPathInstructionMock =
                new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim);
            _createToolPackageStoreAndInstaller = (_) => (_toolPackageStore, _toolPackageStoreQuery, CreateToolPackageInstaller());

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

            _appliedCommand = result["dotnet"]["tool"]["install"];
            var parser = Parser.Instance;

            _parseResult = parser.ParseFrom("dotnet tool", new[] { "install", "-g", PackageId });
        }
예제 #2
0
        public ToolInstallGlobalOrToolPathCommandTests()
        {
            _reporter           = new BufferedReporter();
            _fileSystem         = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _temporaryDirectory = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _pathToPlaceShim    = Path.Combine(_temporaryDirectory, "pathToPlace");
            _fileSystem.Directory.CreateDirectory(_pathToPlaceShim);
            _pathToPlacePackages = _pathToPlaceShim + "Packages";
            var toolPackageStoreMock = new ToolPackageStoreMock(new DirectoryPath(_pathToPlacePackages), _fileSystem);

            _toolPackageStore          = toolPackageStoreMock;
            _toolPackageStoreQuery     = toolPackageStoreMock;
            _createShellShimRepository =
                (_, nonGlobalLocation) => new ShellShimRepository(
                    new DirectoryPath(_pathToPlaceShim),
                    string.Empty,
                    fileSystem: _fileSystem,
                    appHostShellShimMaker: new AppHostShellShimMakerMock(_fileSystem),
                    filePermissionSetter: new NoOpFilePermissionSetter());
            _environmentPathInstructionMock =
                new EnvironmentPathInstructionMock(_reporter, _pathToPlaceShim);
            _createToolPackageStoreAndInstaller = (location, forwardArguments) => (_toolPackageStore, _toolPackageStoreQuery, CreateToolPackageInstaller());

            _parseResult = Parser.Instance.Parse($"dotnet tool install -g {PackageId}");
        }
예제 #3
0
        public ToolRestoreCommandTests()
        {
            _packageVersionA = NuGetVersion.Parse("1.0.4");
            _packageVersionWithCommandNameCollisionWithA = NuGetVersion.Parse("1.0.9");
            _packageVersionB = NuGetVersion.Parse("1.0.4");

            _reporter   = new BufferedReporter();
            _fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _nugetGlobalPackagesFolder = new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
            _temporaryDirectory        = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _pathToPlacePackages       = Path.Combine(_temporaryDirectory, "pathToPlacePackage");
            ToolPackageStoreMock toolPackageStoreMock =
                new ToolPackageStoreMock(new DirectoryPath(_pathToPlacePackages), _fileSystem);

            _toolPackageStore         = toolPackageStoreMock;
            _toolPackageInstallerMock = new ToolPackageInstallerMock(
                _fileSystem,
                _toolPackageStore,
                new ProjectRestorerMock(
                    _fileSystem,
                    _reporter,
                    new List <MockFeed>
            {
                new MockFeed
                {
                    Type     = MockFeedType.ImplicitAdditionalFeed,
                    Packages = new List <MockFeedPackage>
                    {
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdA.ToString(),
                            Version         = _packageVersionA.ToNormalizedString(),
                            ToolCommandName = _toolCommandNameA.ToString()
                        },
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdB.ToString(),
                            Version         = _packageVersionB.ToNormalizedString(),
                            ToolCommandName = _toolCommandNameB.ToString()
                        },
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdWithCommandNameCollisionWithA.ToString(),
                            Version         = _packageVersionWithCommandNameCollisionWithA.ToNormalizedString(),
                            ToolCommandName = "A"
                        }
                    }
                }
            }),
                installCallback: () => _installCalledCount++);

            _parseResult = Parser.Instance.Parse("dotnet tool restore");

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(_temporaryDirectory, "cache")),
                      1);
        }
예제 #4
0
        public ToolInstallLocalCommandTests()
        {
            _packageVersionA = NuGetVersion.Parse("1.0.4");

            _reporter   = new BufferedReporter();
            _fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _nugetGlobalPackagesFolder = new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
            _temporaryDirectory        = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _pathToPlacePackages       = Path.Combine(_temporaryDirectory, "pathToPlacePackage");
            ToolPackageStoreMock toolPackageStoreMock =
                new ToolPackageStoreMock(new DirectoryPath(_pathToPlacePackages), _fileSystem);

            _toolPackageStore         = toolPackageStoreMock;
            _toolPackageInstallerMock = new ToolPackageInstallerMock(
                _fileSystem,
                _toolPackageStore,
                new ProjectRestorerMock(
                    _fileSystem,
                    _reporter,
                    new[]
            {
                new MockFeed
                {
                    Type     = MockFeedType.ImplicitAdditionalFeed,
                    Packages = new List <MockFeedPackage>
                    {
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdA.ToString(),
                            Version         = _packageVersionA.ToNormalizedString(),
                            ToolCommandName = _toolCommandNameA.ToString()
                        }
                    }
                }
            }));

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(_temporaryDirectory, "cache")),
                      1);

            _manifestFilePath = Path.Combine(_temporaryDirectory, "dotnet-tools.json");
            _fileSystem.File.WriteAllText(Path.Combine(_temporaryDirectory, _manifestFilePath), _jsonContent);
            _toolManifestFinder = new ToolManifestFinder(new DirectoryPath(_temporaryDirectory), _fileSystem);
            _toolManifestEditor = new ToolManifestEditor(_fileSystem);

            ParseResult result = Parser.Instance.Parse($"dotnet tool install {_packageIdA.ToString()}");

            _appliedCommand = result["dotnet"]["tool"]["install"];
            Cli.CommandLine.Parser parser = Parser.Instance;
            _parseResult = parser.ParseFrom("dotnet tool", new[] { "install", _packageIdA.ToString() });

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(_temporaryDirectory, "cache")),
                      1);
        }
예제 #5
0
        private ListToolCommand CreateCommand(IToolPackageStore store, string options = "", string expectedToolPath = null)
        {
            ParseResult result = Parser.Instance.Parse("dotnet tool list " + options);

            return(new ListToolCommand(
                       result["dotnet"]["tool"]["list"],
                       result,
                       toolPath => { AssertExpectedToolPath(toolPath, expectedToolPath); return store; },
                       _reporter));
        }
예제 #6
0
        public static (IToolPackageStore, IToolPackageInstaller) CreateToolPackageStoreAndInstaller(
            DirectoryPath?nonGlobalLocation = null)
        {
            IToolPackageStore toolPackageStore = CreateToolPackageStore(nonGlobalLocation);
            var toolPackageInstaller           = new ToolPackageInstaller(
                toolPackageStore,
                new ProjectRestorer());

            return(toolPackageStore, toolPackageInstaller);
        }
예제 #7
0
        private ListToolCommand CreateCommand(IToolPackageStore store, string options = "")
        {
            ParseResult result = Parser.Instance.Parse("dotnet list tool " + options);

            return(new ListToolCommand(
                       result["dotnet"]["list"]["tool"],
                       result,
                       store,
                       _reporter));
        }
예제 #8
0
 public ToolPackageInstallerMock(
     IFileSystem fileSystem,
     IToolPackageStore store,
     IProjectRestorer projectRestorer,
     Action installCallback = null)
 {
     _fileSystem      = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     _store           = store ?? throw new ArgumentNullException(nameof(store));
     _projectRestorer = projectRestorer ?? throw new ArgumentNullException(nameof(projectRestorer));
     _installCallback = installCallback;
 }
예제 #9
0
 public ToolPackageInstaller(
     IToolPackageStore store,
     IProjectRestorer projectRestorer,
     FilePath?tempProject      = null,
     DirectoryPath?offlineFeed = null)
 {
     _store           = store ?? throw new ArgumentNullException(nameof(store));
     _projectRestorer = projectRestorer ?? throw new ArgumentNullException(nameof(projectRestorer));
     _tempProject     = tempProject;
     _offlineFeed     = offlineFeed ?? new DirectoryPath(CliFolderPathCalculator.CliFallbackFolderPath);
 }
예제 #10
0
 public ToolPackageInstance(
     IToolPackageStore store,
     string packageId,
     string packageVersion,
     DirectoryPath packageDirectory)
 {
     _store           = store ?? throw new ArgumentNullException(nameof(store));
     PackageId        = packageId ?? throw new ArgumentNullException(nameof(packageId));
     PackageVersion   = packageVersion ?? throw new ArgumentNullException(nameof(packageVersion));
     PackageDirectory = packageDirectory;
     _commands        = new Lazy <IReadOnlyList <CommandSettings> >(GetCommands);
 }
예제 #11
0
 public ToolPackageInstallerMock(
     IFileSystem fileSystem,
     IToolPackageStore store,
     IProjectRestorer projectRestorer,
     Action installCallback = null,
     Dictionary <PackageId, IEnumerable <string> > warningsMap = null)
 {
     _fileSystem      = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     _store           = store ?? throw new ArgumentNullException(nameof(store));
     _projectRestorer = projectRestorer ?? throw new ArgumentNullException(nameof(projectRestorer));
     _installCallback = installCallback;
     _warningsMap     = warningsMap ?? new Dictionary <PackageId, IEnumerable <string> >();
 }
예제 #12
0
        public ToolPackageInstance(
            IToolPackageStore store,
            PackageId id,
            NuGetVersion version,
            DirectoryPath packageDirectory)
        {
            _store    = store ?? throw new ArgumentNullException(nameof(store));
            _commands = new Lazy <IReadOnlyList <CommandSettings> >(GetCommands);

            Id               = id;
            Version          = version ?? throw new ArgumentNullException(nameof(version));
            PackageDirectory = packageDirectory;
        }
예제 #13
0
파일: ListToolCommand.cs 프로젝트: wli3/cli
 public ListToolCommand(
     AppliedOption options,
     ParseResult result,
     IToolPackageStore toolPackageStore = null,
     IReporter reporter = null)
     : base(result)
 {
     _options          = options ?? throw new ArgumentNullException(nameof(options));
     _toolPackageStore = toolPackageStore ?? new ToolPackageStore(
         new DirectoryPath(new CliFolderPathCalculator().ToolsPackagePath));
     _reporter      = reporter ?? Reporter.Output;
     _errorReporter = reporter ?? Reporter.Error;
 }
예제 #14
0
        public InstallToolCommandTests()
        {
            _reporter                       = new BufferedReporter();
            _fileSystem                     = new FileSystemMockBuilder().Build();
            _toolPackageStore               = new ToolPackageStoreMock(new DirectoryPath(PathToPlacePackages), _fileSystem);
            _shellShimRepositoryMock        = new ShellShimRepositoryMock(new DirectoryPath(PathToPlaceShim), _fileSystem);
            _environmentPathInstructionMock =
                new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim);

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

            _appliedCommand = result["dotnet"]["install"]["tool"];
            var parser = Parser.Instance;

            _parseResult = parser.ParseFrom("dotnet install", new[] { "tool", PackageId });
        }
예제 #15
0
 public ToolPackageInstallerMock(
     IFileSystem fileSystem,
     IToolPackageStore store,
     ProjectRestorerMock projectRestorer,
     Action installCallback = null,
     Dictionary <PackageId, IEnumerable <string> > warningsMap           = null,
     Dictionary <PackageId, IReadOnlyList <FilePath> > packagedShimsMap  = null,
     Dictionary <PackageId, IEnumerable <NuGetFramework> > frameworksMap = null)
 {
     _fileSystem       = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     _store            = store ?? throw new ArgumentNullException(nameof(store));
     _projectRestorer  = projectRestorer ?? throw new ArgumentNullException(nameof(projectRestorer));
     _installCallback  = installCallback;
     _warningsMap      = warningsMap ?? new Dictionary <PackageId, IEnumerable <string> >();
     _packagedShimsMap = packagedShimsMap ?? new Dictionary <PackageId, IReadOnlyList <FilePath> >();
     _frameworksMap    = frameworksMap ?? new Dictionary <PackageId, IEnumerable <NuGetFramework> >();
 }
예제 #16
0
        private static void AssertPackageInstall(
            BufferedReporter reporter,
            IFileSystem fileSystem,
            IToolPackage package,
            IToolPackageStore store)
        {
            reporter.Lines.Should().BeEmpty();

            package.PackageId.Should().Be(TestPackageId);
            package.PackageVersion.Should().Be(TestPackageVersion);
            package.PackageDirectory.Value.Should().Contain(store.Root.Value);

            store.GetInstalledPackages(TestPackageId).Select(p => p.PackageVersion).Should().Equal(TestPackageVersion);

            package.Commands.Count.Should().Be(1);
            fileSystem.File.Exists(package.Commands[0].Executable.Value).Should().BeTrue($"{package.Commands[0].Executable.Value} should exist");
            package.Commands[0].Executable.Value.Should().Contain(store.Root.Value);
        }
예제 #17
0
        public ToolInstallCommandTests()
        {
            _reporter                  = new BufferedReporter();
            _fileSystem                = new FileSystemMockBuilder().Build();
            _toolPackageStore          = new ToolPackageStoreMock(new DirectoryPath(PathToPlacePackages), _fileSystem);
            _createShellShimRepository =
                (nonGlobalLocation) => new ShellShimRepositoryMock(new DirectoryPath(PathToPlaceShim), _fileSystem);
            _environmentPathInstructionMock =
                new EnvironmentPathInstructionMock(_reporter, PathToPlaceShim);
            _createToolPackageStoreAndInstaller = (_) => (_toolPackageStore, CreateToolPackageInstaller());

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

            _appliedCommand = result["dotnet"]["tool"]["install"];
            var parser = Parser.Instance;

            _parseResult = parser.ParseFrom("dotnet tool", new[] { "install", "-g", PackageId });
        }
예제 #18
0
        public UninstallToolCommand(
            AppliedOption options,
            ParseResult result,
            IToolPackageStore toolPackageStore       = null,
            IShellShimRepository shellShimRepository = null,
            IReporter reporter = null)
            : base(result)
        {
            var pathCalculator = new CliFolderPathCalculator();

            _options          = options ?? throw new ArgumentNullException(nameof(options));
            _toolPackageStore = toolPackageStore ?? new ToolPackageStore(
                new DirectoryPath(pathCalculator.ToolsPackagePath));
            _shellShimRepository = shellShimRepository ?? new ShellShimRepository(
                new DirectoryPath(pathCalculator.ToolsShimPath));
            _reporter      = reporter ?? Reporter.Output;
            _errorReporter = reporter ?? Reporter.Error;
        }
예제 #19
0
        private IEnumerable <string> EnumerateExpectedTableLines(IToolPackageStore store)
        {
            string GetCommandsString(IToolPackage package)
            {
                return(string.Join(ListToolCommand.CommandDelimiter, package.Commands.Select(c => c.Name)));
            }

            var packages        = store.EnumeratePackages().Where(PackageHasCommands).OrderBy(package => package.Id);
            var columnDelimiter = PrintableTable <IToolPackageStore> .ColumnDelimiter;

            int packageIdColumnWidth = LocalizableStrings.PackageIdColumn.Length;
            int versionColumnWidth   = LocalizableStrings.VersionColumn.Length;
            int commandsColumnWidth  = LocalizableStrings.CommandsColumn.Length;

            foreach (var package in packages)
            {
                packageIdColumnWidth = Math.Max(packageIdColumnWidth, package.Id.ToString().Length);
                versionColumnWidth   = Math.Max(versionColumnWidth, package.Version.ToNormalizedString().Length);
                commandsColumnWidth  = Math.Max(commandsColumnWidth, GetCommandsString(package).Length);
            }

            yield return(string.Format(
                             "{0}{1}{2}{3}{4}",
                             LocalizableStrings.PackageIdColumn.PadRight(packageIdColumnWidth),
                             columnDelimiter,
                             LocalizableStrings.VersionColumn.PadRight(versionColumnWidth),
                             columnDelimiter,
                             LocalizableStrings.CommandsColumn.PadRight(commandsColumnWidth)));

            yield return(new string(
                             '-',
                             packageIdColumnWidth + versionColumnWidth + commandsColumnWidth + (columnDelimiter.Length * 2)));

            foreach (var package in packages)
            {
                yield return(string.Format(
                                 "{0}{1}{2}{3}{4}",
                                 package.Id.ToString().PadRight(packageIdColumnWidth),
                                 columnDelimiter,
                                 package.Version.ToNormalizedString().PadRight(versionColumnWidth),
                                 columnDelimiter,
                                 GetCommandsString(package).PadRight(commandsColumnWidth)));
            }
        }
        private static void AssertInstallRollBack(IFileSystem fileSystem, IToolPackageStore store)
        {
            if (!fileSystem.Directory.Exists(store.Root.Value))
            {
                return;
            }

            fileSystem
            .Directory
            .EnumerateFileSystemEntries(store.Root.Value)
            .Should()
            .NotContain(e => Path.GetFileName(e) != ToolPackageStoreAndQuery.StagingDirectory);

            fileSystem
            .Directory
            .EnumerateFileSystemEntries(store.Root.WithSubDirectories(ToolPackageStoreAndQuery.StagingDirectory).Value)
            .Should()
            .BeEmpty();
        }
예제 #21
0
        public InstallToolCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageStore toolPackageStore                     = null,
            IToolPackageInstaller toolPackageInstaller             = null,
            IShellShimRepository shellShimRepository               = null,
            IEnvironmentPathInstruction environmentPathInstruction = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId      = new PackageId(appliedCommand.Arguments.Single());
            _packageVersion = appliedCommand.ValueOrDefault <string>("version");
            _configFilePath = appliedCommand.ValueOrDefault <string>("configfile");
            _framework      = appliedCommand.ValueOrDefault <string>("framework");
            _source         = appliedCommand.ValueOrDefault <string>("source");
            _global         = appliedCommand.ValueOrDefault <bool>("global");
            _verbosity      = appliedCommand.SingleArgumentOrDefault("verbosity");

            var cliFolderPathCalculator = new CliFolderPathCalculator();

            _toolPackageStore = toolPackageStore
                                ?? new ToolPackageStore(new DirectoryPath(cliFolderPathCalculator.ToolsPackagePath));

            _toolPackageInstaller = toolPackageInstaller
                                    ?? new ToolPackageInstaller(
                _toolPackageStore,
                new ProjectRestorer(_reporter));

            _environmentPathInstruction = environmentPathInstruction
                                          ?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();

            _shellShimRepository = shellShimRepository
                                   ?? new ShellShimRepository(new DirectoryPath(cliFolderPathCalculator.ToolsShimPath));

            _reporter      = (reporter ?? Reporter.Output);
            _errorReporter = (reporter ?? Reporter.Error);
        }
예제 #22
0
        private static void AssertPackageInstall(
            BufferedReporter reporter,
            IFileSystem fileSystem,
            IToolPackage package,
            IToolPackageStore store,
            IToolPackageStoreQuery storeQuery)
        {
            reporter.Lines.Should().BeEmpty();

            package.Id.Should().Be(TestPackageId);
            package.Version.ToNormalizedString().Should().Be(TestPackageVersion);
            package.PackageDirectory.Value.Should().Contain(store.Root.Value);
            package.Frameworks.Should().BeEquivalentTo(TestFrameworks);

            storeQuery.EnumeratePackageVersions(TestPackageId)
            .Select(p => p.Version.ToNormalizedString())
            .Should()
            .Equal(TestPackageVersion);

            package.Commands.Count.Should().Be(1);
            fileSystem.File.Exists(package.Commands[0].Executable.Value).Should()
            .BeTrue($"{package.Commands[0].Executable.Value} should exist");
            package.Commands[0].Executable.Value.Should().Contain(store.Root.Value);
        }
예제 #23
0
        public override int Execute()
        {
            var global   = _options.ValueOrDefault <bool>("global");
            var toolPath = _options.SingleArgumentOrDefault("tool-path");

            if (string.IsNullOrWhiteSpace(toolPath) && !global)
            {
                throw new GracefulException(LocalizableStrings.UninstallToolCommandNeedGlobalOrToolPath);
            }

            if (!string.IsNullOrWhiteSpace(toolPath) && global)
            {
                throw new GracefulException(LocalizableStrings.UninstallToolCommandInvalidGlobalAndToolPath);
            }

            DirectoryPath?toolDirectoryPath = null;

            if (!string.IsNullOrWhiteSpace(toolPath))
            {
                toolDirectoryPath = new DirectoryPath(toolPath);
            }

            IToolPackageStore    toolPackageStore    = _createToolPackageStoreAndInstaller(toolDirectoryPath);
            IShellShimRepository shellShimRepository = _createShellShimRepository(toolDirectoryPath);

            var          packageId = new PackageId(_options.Arguments.Single());
            IToolPackage package   = null;

            try
            {
                package = toolPackageStore.EnumeratePackageVersions(packageId).SingleOrDefault();
                if (package == null)
                {
                    throw new GracefulException(
                              messages: new[]
                    {
                        string.Format(
                            LocalizableStrings.ToolNotInstalled,
                            packageId),
                    },
                              isUserError: false);
                }
            }
            catch (InvalidOperationException)
            {
                throw new GracefulException(
                          messages: new[]
                {
                    string.Format(
                        LocalizableStrings.ToolHasMultipleVersionsInstalled,
                        packageId),
                },
                          isUserError: false);
            }

            try
            {
                using (var scope = new TransactionScope(
                           TransactionScopeOption.Required,
                           TimeSpan.Zero))
                {
                    foreach (var command in package.Commands)
                    {
                        shellShimRepository.RemoveShim(command.Name);
                    }

                    package.Uninstall();

                    scope.Complete();
                }

                _reporter.WriteLine(
                    string.Format(
                        LocalizableStrings.UninstallSucceeded,
                        package.Id,
                        package.Version.ToNormalizedString()).Green());
                return(0);
            }
            catch (ToolPackageException ex)
            {
                throw new GracefulException(
                          messages: new[]
                {
                    ex.Message
                },
                          verboseMessages: new[] { ex.ToString() },
                          isUserError: false);
            }
            catch (Exception ex) when(ex is ToolConfigurationException || ex is ShellShimException)
            {
                throw new GracefulException(
                          messages: new[]
                {
                    string.Format(
                        LocalizableStrings.FailedToUninstallTool,
                        packageId,
                        ex.Message)
                },
                          verboseMessages: new[] { ex.ToString() },
                          isUserError: false);
            }
        }
예제 #24
0
        public ToolUpdateLocalCommandTests()
        {
            _reporter   = new BufferedReporter();
            _fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();

            _temporaryDirectoryParent = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _temporaryDirectory       = Path.Combine(_temporaryDirectoryParent, "sub");
            _fileSystem.Directory.CreateDirectory(_temporaryDirectory);
            _pathToPlacePackages = Path.Combine(_temporaryDirectory, "pathToPlacePackage");

            _packageOriginalVersionA = NuGetVersion.Parse("1.0.0");
            _packageNewVersionA      = NuGetVersion.Parse("2.0.0");

            ToolPackageStoreMock toolPackageStoreMock =
                new ToolPackageStoreMock(new DirectoryPath(_pathToPlacePackages), _fileSystem);

            _toolPackageStore = toolPackageStoreMock;
            _mockFeed         = new MockFeed
            {
                Type     = MockFeedType.ImplicitAdditionalFeed,
                Packages = new List <MockFeedPackage>
                {
                    new MockFeedPackage
                    {
                        PackageId       = _packageIdA.ToString(),
                        Version         = _packageOriginalVersionA.ToNormalizedString(),
                        ToolCommandName = _toolCommandNameA.ToString()
                    }
                }
            };
            _toolPackageInstallerMock = new ToolPackageInstallerMock(
                _fileSystem,
                _toolPackageStore,
                new ProjectRestorerMock(
                    _fileSystem,
                    _reporter,
                    new List <MockFeed>
            {
                _mockFeed
            }));

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(_temporaryDirectory, "cache")),
                      1);

            _manifestFilePath = Path.Combine(_temporaryDirectory, "dotnet-tools.json");
            _fileSystem.File.WriteAllText(Path.Combine(_temporaryDirectory, _manifestFilePath), _jsonContent);
            _toolManifestFinder = new ToolManifestFinder(new DirectoryPath(_temporaryDirectory), _fileSystem,
                                                         new FakeDangerousFileDetector());
            _toolManifestEditor = new ToolManifestEditor(_fileSystem, new FakeDangerousFileDetector());

            _parseResult = Parser.Instance.Parse($"dotnet tool update {_packageIdA.ToString()}");

            _toolRestoreCommand = new ToolRestoreCommand(
                _parseResult,
                _toolPackageInstallerMock,
                _toolManifestFinder,
                _localToolsResolverCache,
                _fileSystem,
                _reporter
                );

            _defaultToolUpdateLocalCommand = new ToolUpdateLocalCommand(
                _parseResult,
                _toolPackageInstallerMock,
                _toolManifestFinder,
                _toolManifestEditor,
                _localToolsResolverCache,
                _reporter);
        }
예제 #25
0
 public ToolPackageUninstaller(IToolPackageStore toolPackageStoreQuery)
 {
     _toolPackageStoreQuery = toolPackageStoreQuery ?? throw new ArgumentException(nameof(toolPackageStoreQuery));
 }