public void GivenManifestFileConflictItShouldNotAddToCache() { _toolManifestEditor.Add( new FilePath(_manifestFilePath), _packageIdA, new NuGetVersion(1, 1, 1), new[] { _toolCommandNameA }); var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand(); Action a = () => toolInstallLocalCommand.Execute(); a.ShouldThrow <GracefulException>(); _localToolsResolverCache.TryLoad(new RestoredCommandIdentifier( _packageIdA, _packageVersionA, NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()), Constants.AnyRid, _toolCommandNameA), _nugetGlobalPackagesFolder, out RestoredCommand restoredCommand ).Should().BeFalse("it should not add to cache if add to manifest failed. " + "But restore do not need to 'revert' since it just set in nuget global directory"); }
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); }
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"" ] } } }"); }
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 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"" ] } } }"); }
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); }