public ToolRestoreCommandWithMultipleNugetConfigTests()
        {
            _packageVersionA = NuGetVersion.Parse("1.0.4");
            _packageVersionB = NuGetVersion.Parse("1.0.4");

            _reporter   = new BufferedReporter();
            _fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _nugetGlobalPackagesFolder = new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
            string temporaryDirectory = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;

            string pathToPlacePackages = Path.Combine(temporaryDirectory, "pathToPlacePackage");
            ToolPackageStoreMock toolPackageStoreMock =
                new ToolPackageStoreMock(new DirectoryPath(pathToPlacePackages), _fileSystem);

            SetupFileLayoutAndFeed(temporaryDirectory, toolPackageStoreMock);

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

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

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(temporaryDirectory, "cache")),
                      1);
        }
Пример #2
0
        public void GivenFailedPackageInstallWhenRunWithPackageIdItShouldNotChangeManifestFile()
        {
            ParseResult result         = Parser.Instance.Parse($"dotnet tool install non-exist");
            var         appliedCommand = result["dotnet"]["tool"]["install"];

            Cli.CommandLine.Parser parser = Parser.Instance;
            var parseResult = parser.ParseFrom("dotnet tool", new[] { "install", "non-exist" });

            var installLocalCommand = new ToolInstallLocalCommand(
                appliedCommand,
                parseResult,
                _toolPackageInstallerMock,
                _toolManifestFinder,
                _toolManifestEditor,
                _localToolsResolverCache,
                _nugetGlobalPackagesFolder,
                _reporter);

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

            a.ShouldThrow <GracefulException>()
            .And.Message.Should()
            .Contain(LocalizableStrings.ToolInstallationRestoreFailed);

            _fileSystem.File.ReadAllText(_manifestFilePath).Should()
            .Be(_jsonContent, "Manifest file should not be changed");
        }
Пример #3
0
        public void WhenRunWithExplicitManifestFileItShouldAddEntryToExplicitManifestFile()
        {
            var explicitManifestFilePath = Path.Combine(_temporaryDirectory, "subdirectory", "dotnet-tools.json");

            _fileSystem.File.Delete(_manifestFilePath);
            _fileSystem.Directory.CreateDirectory(Path.Combine(_temporaryDirectory, "subdirectory"));
            _fileSystem.File.WriteAllText(explicitManifestFilePath, _jsonContent);

            ParseResult result =
                Parser.Instance.Parse(
                    $"dotnet tool install {_packageIdA.ToString()} --tool-manifest {explicitManifestFilePath}");
            var appliedCommand = result["dotnet"]["tool"]["install"];

            Cli.CommandLine.Parser parser = Parser.Instance;
            var parseResult = parser.ParseFrom("dotnet tool",
                                               new[] { "install", _packageIdA.ToString(), "--tool-manifest", explicitManifestFilePath });

            var installLocalCommand = new ToolInstallLocalCommand(
                appliedCommand,
                parseResult,
                _toolPackageInstallerMock,
                _toolManifestFinder,
                _toolManifestEditor,
                _localToolsResolverCache,
                _nugetGlobalPackagesFolder,
                _reporter);

            installLocalCommand.Execute().Should().Be(0);
            _toolManifestFinder.Find(new FilePath(explicitManifestFilePath)).Should().HaveCount(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
        public void WhenRunWithValidVersionRangeItShouldSucceed()
        {
            ParseResult result = Parser.Instance.Parse(
                $"dotnet tool install {_packageIdA.ToString()} --version 1.*");
            var appliedCommand = result["dotnet"]["tool"]["install"];

            Cli.CommandLine.Parser parser = Parser.Instance;
            var parseResult = parser.ParseFrom("dotnet tool",
                                               new[] { "install", _packageIdA.ToString(), "--version", "1.*" });

            var installLocalCommand = new ToolInstallLocalCommand(
                appliedCommand,
                parseResult,
                _toolPackageInstallerMock,
                _toolManifestFinder,
                _toolManifestEditor,
                _localToolsResolverCache,
                _reporter);

            installLocalCommand.Execute().Should().Be(0);
            AssertDefaultInstallSuccess();
        }
Пример #6
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[]
            {
                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 result = Parser.Instance.Parse("dotnet tool restore");

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

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