Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        private CommandSpec GetPackageCommandSpecUsingMuxer(CommandResolverArguments arguments,
                                                            ToolCommandName toolCommandName)
        {
            if (!_toolManifest.TryFind(toolCommandName, out var toolManifestPackage))
            {
                return(null);
            }

            if (_localToolsResolverCache.TryLoad(
                    new RestoredCommandIdentifier(
                        toolManifestPackage.PackageId,
                        toolManifestPackage.Version,
                        NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()),
                        Constants.AnyRid,
                        toolCommandName),
                    _nugetGlobalPackagesFolder,
                    out var restoredCommand))
            {
                if (!_fileSystem.File.Exists(restoredCommand.Executable.Value))
                {
                    throw new GracefulException(string.Format(LocalizableStrings.NeedRunToolRestore,
                                                              toolCommandName.ToString()));
                }

                return(MuxerCommandSpecMaker.CreatePackageCommandSpecUsingMuxer(
                           restoredCommand.Executable.Value,
                           arguments.CommandArguments));
            }

            return(null);
        }
Exemplo n.º 3
0
        private bool PackageHasBeenRestored(
            ToolManifestPackage package,
            string targetFramework)
        {
            var sampleRestoredCommandIdentifierOfThePackage = new RestoredCommandIdentifier(
                package.PackageId,
                package.Version,
                NuGetFramework.Parse(targetFramework),
                Constants.AnyRid,
                package.CommandNames.First());

            return(_localToolsResolverCache.TryLoad(
                       sampleRestoredCommandIdentifierOfThePackage,
                       out var restoredCommand) &&
                   _fileSystem.File.Exists(restoredCommand.Executable.Value));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        private bool PackageHasBeenRestored(
            ToolManifestPackage package,
            string targetFramework)
        {
            var sampleRestoredCommandIdentifierOfThePackage = new RestoredCommandIdentifier(
                package.PackageId,
                package.Version,
                NuGetFramework.Parse(targetFramework),
                "any",
                package.CommandNames.First());

            if (_localToolsResolverCache.TryLoad(
                    sampleRestoredCommandIdentifierOfThePackage,
                    _nugetGlobalPackagesFolder,
                    out _))
            {
                return(true);
            }

            return(false);
        }