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); }
public void GivenNoManifestFileItThrows() { var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should().Contain(string.Format(LocalizableStrings.CannotFindAnyManifestsFileSearched, "")); }
public void WhenCalledWithNonExistsFilePathItThrows() { var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); Action a = () => toolManifest.Find(new FilePath(Path.Combine(_testDirectoryRoot, "non-exists"))); a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should().Contain(string.Format(LocalizableStrings.CannotFindAnyManifestsFileSearched, "")); }
public void GivenConflictedManifestFileInDifferentFieldsItReturnMergedContent() { var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub"); _fileSystem.Directory.CreateDirectory(subdirectoryOfTestRoot); _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentInParentDirectory); _fileSystem.File.WriteAllText(Path.Combine(subdirectoryOfTestRoot, _manifestFilename), _jsonContentInCurrentDirectory); var toolManifest = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem); var manifestResult = toolManifest.Find(); manifestResult.Should().Contain( p => p == new ToolManifestPackage( new PackageId("t-rex"), NuGetVersion.Parse("1.0.49"), new[] { new ToolCommandName("t-rex") }, new DirectoryPath(subdirectoryOfTestRoot)), because: "when different manifest file has the same package id, " + "only keep entry that is in the manifest close to current directory"); manifestResult.Should().Contain( p => p == new ToolManifestPackage( new PackageId("dotnetsay2"), NuGetVersion.Parse("4.0.0"), new[] { new ToolCommandName("dotnetsay2") }, new DirectoryPath(_testDirectoryRoot))); manifestResult.Should().Contain( p => p == new ToolManifestPackage( new PackageId("dotnetsay"), NuGetVersion.Parse("2.1.4"), new[] { new ToolCommandName("dotnetsay") }, new DirectoryPath(subdirectoryOfTestRoot)), because: "combine both content in different manifests"); }
public void GivenInvalidFieldsManifestFileItReturnError() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithInvalidField); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>().And.Message.Should().Contain(string.Format(LocalizableStrings.VersionIsInvalid, "1.*")); }
public void GivenManifestFileOnSameDirectoryItGetContent() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContent); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); var manifestResult = toolManifest.Find(); AssertToolManifestPackageListEqual(_defaultExpectedResult, manifestResult); }
public void MissingIsRootInManifestFileItShouldThrow() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentIsRootMissing); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>().And.Message.Should().Contain(LocalizableStrings.ManifestMissingIsRoot); }
public void GivenManifestFileOnParentDirectoryItGetContent() { var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub"); _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContent); var toolManifest = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem); var manifestResult = toolManifest.Find(); manifestResult.ShouldBeEquivalentTo(_defaultExpectedResult); }
public void RequireRootAndVersionIs1() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithNonRoot); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>() .And.Message.Should() .Contain(" isRoot is false is not supported." + Environment.NewLine + " Tools manifest format version 2 is not supported."); }
public void DifferentVersionOfManifestFileItShouldThrow() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentHigherVersion); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>().And.Message.Should().Contain(string.Format( LocalizableStrings.ManifestVersionHigherThanSupported, 99, 1)); }
public void GivenManifestFileInDotConfigDirectoryItGetContent() { var dotnetconfigDirectory = Path.Combine(_testDirectoryRoot, ".config"); _fileSystem.Directory.CreateDirectory(dotnetconfigDirectory); _fileSystem.File.WriteAllText(Path.Combine(dotnetconfigDirectory, _manifestFilename), _jsonContent); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); var manifestResult = toolManifest.Find(); AssertToolManifestPackageListEqual(_defaultExpectedResult, manifestResult); }
public void WhenCalledWithFilePathItGetContent() { string customFileName = "customname.file"; _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, customFileName), _jsonContent); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); var manifestResult = toolManifest.Find(new FilePath(Path.Combine(_testDirectoryRoot, customFileName))); AssertToolManifestPackageListEqual(_defaultExpectedResult, manifestResult); }
public void GivenMissingFieldManifestFileItReturnError() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithMissingField); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>().And.Message.Should().Contain( LocalizableStrings.InvalidManifestFilePrefix + Environment.NewLine + " " + string.Format(LocalizableStrings.InPackage, "t-rex") + Environment.NewLine + " " + LocalizableStrings.MissingVersion + Environment.NewLine + " " + LocalizableStrings.FieldCommandsIsMissing); }
public void GivenConflictedManifestFileInDifferentFieldsWhenFindByCommandNameItOnlyConsiderTheFirstIsRoot() { var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub"); _fileSystem.Directory.CreateDirectory(subdirectoryOfTestRoot); _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentInParentDirectory); _fileSystem.File.WriteAllText(Path.Combine(subdirectoryOfTestRoot, _manifestFilename), _jsonContentInCurrentDirectoryIsRootTrue); var toolManifest = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem); var manifestResult = toolManifest.Find(); toolManifest.TryFind(new ToolCommandName("dotnetsay2"), out var result).Should().BeFalse(); }
public void GivenConflictedManifestFileInDifferentFieldsItOnlyConsiderTheFirstIsRoot() { var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub"); _fileSystem.Directory.CreateDirectory(subdirectoryOfTestRoot); _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentInParentDirectory); _fileSystem.File.WriteAllText(Path.Combine(subdirectoryOfTestRoot, _manifestFilename), _jsonContentInCurrentDirectoryIsRootTrue); var toolManifest = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem); var manifestResult = toolManifest.Find(); manifestResult.Count.Should().Be(2, "only content in the current directory manifest file is considered"); }
public void GivenInvalidJsonIntergerManifestFileItThrows() { _fileSystem.File.WriteAllText( Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonInvalidJsonInterger); var toolManifest = new ToolManifestFinder( new DirectoryPath(_testDirectoryRoot), _fileSystem, new FakeDangerousFileDetector()); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>(); }
// https://github.com/JamesNK/Newtonsoft.Json/issues/931#issuecomment-224104005 // Due to a limitation of newtonsoft json public void GivenManifestWithDuplicatedPackageIdItReturnsTheLastValue() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithDuplicatedPackagedId); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem); var manifestResult = toolManifest.Find(); manifestResult.Should() .Contain( new ToolManifestPackage( new PackageId("t-rex"), NuGetVersion.Parse("2.1.4"), new[] { new ToolCommandName("t-rex") })); }
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 parseResult = Parser.Instance.Parse( $"dotnet tool install {_packageIdA.ToString()} --tool-manifest {explicitManifestFilePath}"); var installLocalCommand = new ToolInstallLocalCommand( parseResult, _toolPackageInstallerMock, _toolManifestFinder, _toolManifestEditor, _localToolsResolverCache, _reporter); installLocalCommand.Execute().Should().Be(0); _toolManifestFinder.Find(new FilePath(explicitManifestFilePath)).Should().HaveCount(1); }
public void GivenManifestFileOnParentDirectoryItGetContent() { var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub"); _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContent); var toolManifest = new ToolManifestFinder( new DirectoryPath(subdirectoryOfTestRoot), _fileSystem, new FakeDangerousFileDetector()); var manifestResult = toolManifest.Find(); AssertToolManifestPackageListEqual(_defaultExpectedResult, manifestResult); }
public void GivenInvalidTypeManifestFileItThrows() { _fileSystem.File.WriteAllText( Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithInvalidType); var toolManifest = new ToolManifestFinder( new DirectoryPath(_testDirectoryRoot), _fileSystem, new FakeDangerousFileDetector()); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>() .And.Message.Should().Contain(string.Format(LocalizableStrings.UnexpectedTypeInJson, "True|False", "isRoot")); }
public void GivenNoManifestFileItThrows() { var toolManifest = new ToolManifestFinder( new DirectoryPath(_testDirectoryRoot), _fileSystem, new FakeDangerousFileDetector()); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should() .Contain(LocalizableStrings.CannotFindAManifestFile); a.ShouldThrow <ToolManifestCannotBeFoundException>().And.VerboseMessage.Should() .Contain(string.Format(LocalizableStrings.ListOfSearched, "")); }
public void GivenManifestWithDuplicatedPackageIdItReturnsTheLastValue() { _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithDuplicatedPackagedId); var toolManifest = new ToolManifestFinder( new DirectoryPath(_testDirectoryRoot), _fileSystem, new FakeDangerousFileDetector()); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>().And.Message.Should() .Contain(string.Format(string.Format(LocalizableStrings.MultipleSamePackageId, string.Join(", ", "t-rex")), "")); }
public void GivenManifestFileOnSameDirectoryWithMarkOfTheWebDetectorItThrows() { string manifestFilePath = Path.Combine(_testDirectoryRoot, _manifestFilename); _fileSystem.File.WriteAllText(manifestFilePath, _jsonContent); var fakeMarkOfTheWebDetector = new FakeDangerousFileDetector(manifestFilePath); var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem, fakeMarkOfTheWebDetector); Action a = () => toolManifest.Find(); a.ShouldThrow <ToolManifestException>() .And.Message .Should().Contain( string.Format(LocalizableStrings.ManifestHasMarkOfTheWeb, manifestFilePath), "The message is similar to Windows file property page"); }
public void WhenCalledWithNonExistsFilePathItThrows() { var toolManifest = new ToolManifestFinder( new DirectoryPath(_testDirectoryRoot), _fileSystem, new FakeDangerousFileDetector()); Action a = () => toolManifest.Find(new FilePath(Path.Combine(_testDirectoryRoot, "non-exists"))); a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should() .Contain(LocalizableStrings.CannotFindAManifestFile); a.ShouldThrow <ToolManifestCannotBeFoundException>().And.VerboseMessage.Should() .Contain(string.Format(LocalizableStrings.ListOfSearched, "")) .And.Contain( Path.Combine(_testDirectoryRoot, "non-exists"), "the specificied manifest file name is in the 'searched list'"); }
private void AssertUpdateSuccess(FilePath?manifestFile = null, NuGetVersion packageVersion = null) { packageVersion ??= _packageNewVersionA; IReadOnlyCollection <ToolManifestPackage> manifestPackages = _toolManifestFinder.Find(manifestFile); manifestPackages.Should().HaveCount(1); ToolManifestPackage addedPackage = manifestPackages.Single(); addedPackage.Version.Should().Be(packageVersion); _localToolsResolverCache.TryLoad(new RestoredCommandIdentifier( addedPackage.PackageId, addedPackage.Version, NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()), Constants.AnyRid, addedPackage.CommandNames.Single()), out RestoredCommand restoredCommand ).Should().BeTrue(); _fileSystem.File.Exists(restoredCommand.Executable.Value); }