Пример #1
0
        public void GivenManifestFileWhenAddingTheSamePackageIdToolItThrows()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            PackageId    packageId    = new PackageId("dotnetsay");
            NuGetVersion nuGetVersion = NuGetVersion.Parse("3.0.0");
            Action       a            = () => toolManifestFileEditor.Add(new FilePath(manifestFile),
                                                                         packageId,
                                                                         nuGetVersion,
                                                                         new[] { new ToolCommandName("dotnetsay") });


            var expectedString = string.Format(
                LocalizableStrings.ManifestPackageIdCollision,
                packageId.ToString(),
                nuGetVersion.ToNormalizedString(),
                manifestFile,
                packageId.ToString(),
                "2.1.4");

            a.ShouldThrow <ToolManifestException>()
            .And.Message.Should().Contain(expectedString);

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(_jsonContent);
        }
Пример #2
0
        public void GivenManifestFileItCanRemoveEntryFromIt()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            toolManifestFileEditor.Remove(new FilePath(manifestFile),
                                          new PackageId("dotnetsay"));

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(
                @"{
  ""version"": 1,
  ""isRoot"": true,
  ""tools"": {
    ""t-rex"": {
      ""version"": ""1.0.53"",
      ""commands"": [
        ""t-rex""
      ]
    }
  }
}");
        }
Пример #3
0
        public void GivenManifestFileWithoutToolsEntryItCanAddEntryToIt()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContentWithoutToolsEntry);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem, new FakeDangerousFileDetector());

            toolManifestFileEditor.Add(new FilePath(manifestFile),
                                       new PackageId("new-tool"),
                                       NuGetVersion.Parse("3.0.0"),
                                       new[] { new ToolCommandName("newtool") });

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(
                @"{
  ""isRoot"": true,
  ""tools"": {
    ""new-tool"": {
      ""version"": ""3.0.0"",
      ""commands"": [
        ""newtool""
      ]
    }
  }
}");
        }
Пример #4
0
        public void GivenManifestFileItCanEditEntry()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem, new FakeDangerousFileDetector());

            toolManifestFileEditor.Edit(new FilePath(manifestFile),
                                        new PackageId("t-rex"),
                                        NuGetVersion.Parse("3.0.0"),
                                        new[] { new ToolCommandName("t-rex3") });

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(
                @"{
  ""version"": 1,
  ""isRoot"": true,
  ""tools"": {
    ""t-rex"": {
      ""version"": ""3.0.0"",
      ""commands"": [
        ""t-rex3""
      ]
    },
    ""dotnetsay"": {
      ""version"": ""2.1.4"",
      ""commands"": [
        ""dotnetsay""
      ]
    }
  }
}", "And original tools entry order is preserved.");
        }
Пример #5
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);
        }
Пример #6
0
        public void GivenAnMissingManifestFileVersionItShouldNotThrow()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContentMissingVersion);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem, new FakeDangerousFileDetector());

            Action a = () => toolManifestFileEditor.Read(new FilePath(manifestFile), new DirectoryPath(_testDirectoryRoot));

            a.ShouldNotThrow <ToolManifestException>();
        }
Пример #7
0
        public void GivenManifestFileWhenEditNonExistPackageIdItThrows()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem, new FakeDangerousFileDetector());

            Action a = () => toolManifestFileEditor.Edit(new FilePath(manifestFile),
                                                         new PackageId("non-exist"),
                                                         NuGetVersion.Parse("3.0.0"),
                                                         new[] { new ToolCommandName("t-rex3") });

            a.ShouldThrow <ArgumentException>().And.Message.Should()
            .Contain($"Manifest {manifestFile} does not contain package id 'non-exist'.");
        }
Пример #8
0
        public void GivenManifestFileWhenRemoveNonExistPackageIdToolItThrows()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            Action a = () => toolManifestFileEditor.Remove(
                new FilePath(manifestFile),
                new PackageId("non-exist"));

            a.ShouldThrow <ToolManifestException>()
            .And.Message.Should().Contain(string.Format(
                                              LocalizableStrings.CannotFindPackageIdInManifest, "non-exist"));

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(_jsonContent);
        }
Пример #9
0
        public void GivenManifestFileWhenAddingTheSamePackageIdSameVersionSameCommandsItDoesNothing()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            PackageId    packageId    = new PackageId("dotnetsay");
            NuGetVersion nuGetVersion = NuGetVersion.Parse("2.1.4");
            Action       a            = () => toolManifestFileEditor.Add(new FilePath(manifestFile),
                                                                         packageId,
                                                                         nuGetVersion,
                                                                         new[] { new ToolCommandName("dotnetsay") });

            a.ShouldNotThrow();

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(_jsonContent);
        }
        public ToolUninstallLocalCommandTests()
        {
            _reporter   = new BufferedReporter();
            _fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _temporaryDirectoryParent = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _temporaryDirectory       = Path.Combine(_temporaryDirectoryParent, "sub");
            _fileSystem.Directory.CreateDirectory(_temporaryDirectory);

            _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 uninstall {_packageIdDotnsay.ToString()}");
            _defaultToolUninstallLocalCommand = new ToolUninstallLocalCommand(
                _parseResult,
                _toolManifestFinder,
                _toolManifestEditor,
                _reporter);
        }
Пример #11
0
        public void GivenAnInvalidManifestFileWhenRemoveItThrows()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonWithInvalidField);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            Action a = () => toolManifestFileEditor.Remove(
                new FilePath(manifestFile),
                new PackageId("dotnetsay"));

            a.ShouldThrow <ToolManifestException>()
            .And.Message.Should().Contain(
                string.Format(LocalizableStrings.InvalidManifestFilePrefix,
                              manifestFile,
                              string.Empty));

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(_jsonWithInvalidField);
        }
Пример #12
0
        public void GivenManifestFileItCanAddEntryToIt()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            toolManifestFileEditor.Add(new FilePath(manifestFile),
                                       new PackageId("new-tool"),
                                       NuGetVersion.Parse("3.0.0"),
                                       new[] { new ToolCommandName("newtool") });

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(
                @"{
  ""version"": 1,
  ""isRoot"": true,
  ""tools"": {
    ""t-rex"": {
      ""version"": ""1.0.53"",
      ""commands"": [
        ""t-rex""
      ]
    },
    ""dotnetsay"": {
      ""version"": ""2.1.4"",
      ""commands"": [
        ""dotnetsay""
      ]
    },
    ""new-tool"": {
      ""version"": ""3.0.0"",
      ""commands"": [
        ""newtool""
      ]
    }
  }
}");
        }
Пример #13
0
        public void GivenAnInvalidManifestFileWhenAddItThrows()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonWithInvalidField);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            PackageId    packageId    = new PackageId("dotnetsay");
            NuGetVersion nuGetVersion = NuGetVersion.Parse("3.0.0");
            Action       a            = () => toolManifestFileEditor.Add(new FilePath(manifestFile),
                                                                         packageId,
                                                                         nuGetVersion,
                                                                         new[] { new ToolCommandName("dotnetsay") });

            a.ShouldThrow <ToolManifestException>()
            .And.Message.Should().Contain(
                string.Format(LocalizableStrings.InvalidManifestFilePrefix,
                              manifestFile,
                              string.Empty));

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(_jsonWithInvalidField);
        }
Пример #14
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);
        }