public void ItShouldFailWhenPackageCommandNameDoesNotMatchManifestCommands() { ToolCommandName differentCommandNameA = new ToolCommandName("different-command-nameA"); ToolCommandName differentCommandNameB = new ToolCommandName("different-command-nameB"); IToolManifestFinder manifestFinder = new MockManifestFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { differentCommandNameA, differentCommandNameB }, new DirectoryPath(_temporaryDirectory)), }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _nugetGlobalPackagesFolder, _reporter ); toolRestoreCommand.Execute().Should().Be(1); _reporter.Lines.Should() .Contain(l => l.Contains( string.Format(LocalizableStrings.CommandsMismatch, "\"different-command-nameA\" \"different-command-nameB\"", _packageIdA, "\"a\""))); }
public void WhenPackageIsRestoredAlreadyButDllIsRemovedItRestoresAgain() { IToolManifestFinder manifestFinder = new MockManifestFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }, new DirectoryPath(_temporaryDirectory)) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _nugetGlobalPackagesFolder, _reporter ); toolRestoreCommand.Execute(); _fileSystem.Directory.Delete(_nugetGlobalPackagesFolder.Value, true); var installCallCountBeforeTheSecondRestore = _installCalledCount; toolRestoreCommand.Execute(); installCallCountBeforeTheSecondRestore.Should().BeGreaterThan(0); _installCalledCount.Should().Be(installCallCountBeforeTheSecondRestore + 1); }
public void WhenPackageIsRestoredAlreadyItWillNotRestoreItAgain() { IToolManifestFinder manifestFinder = new MockManifestFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }, new DirectoryPath(_temporaryDirectory)) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _reporter ); toolRestoreCommand.Execute(); var installCallCountBeforeTheSecondRestore = _installCalledCount; toolRestoreCommand.Execute(); installCallCountBeforeTheSecondRestore.Should().BeGreaterThan(0); _installCalledCount.Should().Be(installCallCountBeforeTheSecondRestore); }
public void WhenRunItCanSaveCommandsToCacheAndShowSuccessMessage() { IToolManifestFinder manifestFinder = new MockManifestFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }, new DirectoryPath(_temporaryDirectory)), new ToolManifestPackage(_packageIdB, _packageVersionB, new[] { _toolCommandNameB }, new DirectoryPath(_temporaryDirectory)) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _nugetGlobalPackagesFolder, _reporter ); toolRestoreCommand.Execute().Should().Be(0); _reporter.Lines.Should().Contain(l => l.Contains(string.Format( LocalizableStrings.RestoreSuccessful, _packageIdA, _packageVersionA.ToNormalizedString(), _toolCommandNameA))); _reporter.Lines.Should().Contain(l => l.Contains(string.Format( LocalizableStrings.RestoreSuccessful, _packageIdB, _packageVersionB.ToNormalizedString(), _toolCommandNameB))); _reporter.Lines.Should().Contain(l => l.Contains("\x1B[32m"), "ansicolor code for green, message should be green"); }
public void WhenRunItCanSaveCommandsToCache() { IToolManifestFinder manifestFinder = new MockManifestFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }, new DirectoryPath(_temporaryDirectory)), new ToolManifestPackage(_packageIdB, _packageVersionB, new[] { _toolCommandNameB }, new DirectoryPath(_temporaryDirectory)) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _reporter ); toolRestoreCommand.Execute().Should().Be(0); _localToolsResolverCache.TryLoad( new RestoredCommandIdentifier( _packageIdA, _packageVersionA, NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()), Constants.AnyRid, _toolCommandNameA), out RestoredCommand restoredCommand) .Should().BeTrue(); _fileSystem.File.Exists(restoredCommand.Executable.Value) .Should().BeTrue($"Cached command should be found at {restoredCommand.Executable.Value}"); }
public void WhenRestoredCommandHasTheSameCommandNameItThrows() { IToolManifestFinder manifestFileFinder = new MockManifestFileFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }), new ToolManifestPackage(_packageIdWithCommandNameCollisionWithA, _packageVersionWithCommandNameCollisionWithA, new[] { _toolCommandNameA }) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, manifestFileFinder, _localToolsResolverCache, _nugetGlobalPackagesFolder, _reporter ); Action a = () => toolRestoreCommand.Execute(); a.ShouldThrow <ToolPackageException>() .And.Message .Should().Be(string.Format(LocalizableStrings.PackagesCommandNameCollision, "\"local.tool.console.a\" \"command.name.collision.with.package.a\"", "\"a\" \"A\"")); }
public void WhenRestoredCommandHasTheSameCommandNameItThrows() { IToolManifestFinder manifestFinder = new MockManifestFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }, new DirectoryPath(_temporaryDirectory)), new ToolManifestPackage(_packageIdWithCommandNameCollisionWithA, _packageVersionWithCommandNameCollisionWithA, new[] { _toolCommandNameA }, new DirectoryPath(_temporaryDirectory)) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _nugetGlobalPackagesFolder, _reporter ); var allPossibleErrorMessage = new[] { string.Format(LocalizableStrings.PackagesCommandNameCollisionConclusion, string.Join(Environment.NewLine, new[] { "\t" + string.Format(LocalizableStrings.PackagesCommandNameCollisionForOnePackage, _toolCommandNameA.Value, _packageIdA.ToString()), "\t" + string.Format(LocalizableStrings.PackagesCommandNameCollisionForOnePackage, "A", _packageIdWithCommandNameCollisionWithA.ToString()) })), string.Format(LocalizableStrings.PackagesCommandNameCollisionConclusion, string.Join(Environment.NewLine, new[] { "\t" + string.Format(LocalizableStrings.PackagesCommandNameCollisionForOnePackage, "A", _packageIdWithCommandNameCollisionWithA.ToString()), "\t" + string.Format(LocalizableStrings.PackagesCommandNameCollisionForOnePackage, _toolCommandNameA.Value, _packageIdA.ToString()), })), }; Action a = () => toolRestoreCommand.Execute(); a.ShouldThrow <ToolPackageException>() .And.Message .Should().BeOneOf(allPossibleErrorMessage, "Run in parallel, no order guarantee"); }
public void WhenManifestPackageAreFromDifferentDirectoryItCanFindTheRightNugetConfigAndSaveToCache() { IToolManifestFinder manifestFileFinder = new MockManifestFileFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }, new DirectoryPath(Path.GetDirectoryName(_nugetConfigUnderTestRoot))), new ToolManifestPackage(_packageIdB, _packageVersionB, new[] { _toolCommandNameB }, new DirectoryPath(Path.GetDirectoryName(_nugetConfigUnderSubDir))) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, manifestFileFinder, _localToolsResolverCache, _fileSystem, _nugetGlobalPackagesFolder, _reporter ); toolRestoreCommand.Execute().Should() .Be(0, "if nuget probed from sub dir, it will find only the nuget.config under sub dir. " + "And it does not have the feed to package A. However, since package A is set in " + "manifest file under repository root, nuget should prob from manifest file directory " + "and there is another nuget.config set beside the manifest file under repository root"); _localToolsResolverCache.TryLoad( new RestoredCommandIdentifier( _packageIdA, _packageVersionA, NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()), Constants.AnyRid, _toolCommandNameA), _nugetGlobalPackagesFolder, out RestoredCommand _) .Should().BeTrue(); _localToolsResolverCache.TryLoad( new RestoredCommandIdentifier( _packageIdB, _packageVersionB, NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()), Constants.AnyRid, _toolCommandNameB), _nugetGlobalPackagesFolder, out RestoredCommand _) .Should().BeTrue(); }
public void WhenRunWithoutManifestFileItShouldPrintSpecificRestoreErrorMessage() { IToolManifestFinder manifestFinder = new CannotFindManifestFinder(); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _reporter ); toolRestoreCommand.Execute().Should().Be(0); _reporter.Lines.Should().Contain(l => l.Contains(Cli.Utils.AnsiColorExtensions.Yellow(LocalizableStrings.NoToolsWereRestored))); }
public void WhenCannotFindManifestFileItPrintsWarning() { IToolManifestFinder realManifestFinderImplementationWithMockFinderSystem = new ToolManifestFinder(new DirectoryPath(Path.GetTempPath()), _fileSystem, new FakeDangerousFileDetector()); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_parseResult, _toolPackageInstallerMock, realManifestFinderImplementationWithMockFinderSystem, _localToolsResolverCache, _fileSystem, _reporter ); toolRestoreCommand.Execute().Should().Be(0); _reporter.Lines.Should() .Contain(l => l.Contains(ToolManifest.LocalizableStrings.CannotFindAManifestFile)); }
public void WhenCannotFindManifestFileItPrintsWarning() { IToolManifestFinder realManifestFinderImplementationWithMockFileSystem = new ToolManifestFinder(new DirectoryPath(Path.GetTempPath()), _fileSystem); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, realManifestFinderImplementationWithMockFileSystem, _localToolsResolverCache, _nugetGlobalPackagesFolder, _reporter ); toolRestoreCommand.Execute().Should().Be(0); _reporter.Lines.Should() .Contain(l => l.Contains(string.Format(ToolManifest.LocalizableStrings.CannotFindAnyManifestsFileSearched, ""))); }
public void WhenSomePackageFailedToRestoreItCanRestorePartiallySuccessful() { IToolManifestFinder manifestFinder = new MockManifestFinder(new[] { new ToolManifestPackage(_packageIdA, _packageVersionA, new[] { _toolCommandNameA }, new DirectoryPath(_temporaryDirectory)), new ToolManifestPackage(new PackageId("non-exists"), NuGetVersion.Parse("1.0.0"), new[] { new ToolCommandName("non-exists") }, new DirectoryPath(_temporaryDirectory)) }); ToolRestoreCommand toolRestoreCommand = new ToolRestoreCommand(_appliedCommand, _parseResult, _toolPackageInstallerMock, manifestFinder, _localToolsResolverCache, _fileSystem, _nugetGlobalPackagesFolder, _reporter ); int executeResult = toolRestoreCommand.Execute(); _reporter.Lines.Should() .Contain(l => l.Contains(string.Format(LocalizableStrings.PackageFailedToRestore, "non-exists", ""))); _reporter.Lines.Should().Contain(l => l.Contains(LocalizableStrings.RestorePartiallyFailed)); executeResult.Should().Be(1); _localToolsResolverCache.TryLoad( new RestoredCommandIdentifier( _packageIdA, _packageVersionA, NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()), Constants.AnyRid, _toolCommandNameA), _nugetGlobalPackagesFolder, out _) .Should().BeTrue("Existing package will succeed despite other package failed"); }
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); }