示例#1
0
        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,
                                                                           _reporter
                                                                           );

            toolRestoreCommand.Execute();
            _fileSystem.Directory.Delete(_nugetGlobalPackagesFolder.Value, true);
            var installCallCountBeforeTheSecondRestore = _installCalledCount;

            toolRestoreCommand.Execute();

            installCallCountBeforeTheSecondRestore.Should().BeGreaterThan(0);
            _installCalledCount.Should().Be(installCallCountBeforeTheSecondRestore + 1);
        }
示例#2
0
        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,
                                                                           _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\"")));
        }
示例#3
0
        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,
                                                                           _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");
        }
示例#4
0
        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 manifestFinder =
                new MockManifestFinder(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,
                                                                           manifestFinder,
                                                                           _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();
        }
示例#6
0
        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");
        }
示例#7
0
        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(_appliedCommand,
                                                                           _parseResult,
                                                                           _toolPackageInstallerMock,
                                                                           manifestFinder,
                                                                           _localToolsResolverCache,
                                                                           _fileSystem,
                                                                           _nugetGlobalPackagesFolder,
                                                                           _reporter
                                                                           );

            toolRestoreCommand.Execute().Should().Be(0);

            _localToolsResolverCache.TryLoad(
                new RestoredCommandIdentifier(
                    _packageIdA,
                    _packageVersionA,
                    NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()),
                    Constants.AnyRid,
                    _toolCommandNameA), _nugetGlobalPackagesFolder, out RestoredCommand restoredCommand)
            .Should().BeTrue();

            _fileSystem.File.Exists(restoredCommand.Executable.Value)
            .Should().BeTrue($"Cached command should be found at {restoredCommand.Executable.Value}");
        }