Пример #1
0
        public override int Execute()
        {
            CommandSpec commandspec = _localToolsCommandResolver.ResolveStrict(new CommandResolverArguments()
            {
                // since LocalToolsCommandResolver is a resolver, and all resolver input have dotnet-
                CommandName      = $"dotnet-{_toolCommandName}",
                CommandArguments = _forwardArgument
            });

            if (commandspec == null)
            {
                throw new GracefulException(
                          new string[] { string.Format(LocalizableStrings.CannotFindCommandName, _toolCommandName) },
                          isUserError: false);
            }

            var result = CommandFactoryUsingResolver.Create(commandspec).Execute();

            return(result.ExitCode);
        }
Пример #2
0
        public void WhenNuGetGlobalPackageLocationIsCleanedAfterRestoreItShowError()
        {
            ToolCommandName toolCommandNameA = new ToolCommandName("a");
            NuGetVersion    packageVersionA  = NuGetVersion.Parse("1.0.4");

            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, ManifestFilename),
                                          _jsonContent.Replace("$TOOLCOMMAND$", toolCommandNameA.Value));
            ToolManifestFinder toolManifest =
                new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem, new FakeDangerousFileDetector());

            var fakeExecutable = _nugetGlobalPackagesFolder.WithFile("fakeExecutable.dll");

            _fileSystem.Directory.CreateDirectory(_nugetGlobalPackagesFolder.Value);
            _fileSystem.File.CreateEmptyFile(fakeExecutable.Value);
            _localToolsResolverCache.Save(
                new Dictionary <RestoredCommandIdentifier, RestoredCommand>
            {
                [new RestoredCommandIdentifier(
                     new PackageId("local.tool.console.a"),
                     packageVersionA,
                     NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()),
                     Constants.AnyRid,
                     toolCommandNameA)]
                    = new RestoredCommand(toolCommandNameA, "dotnet", fakeExecutable)
            });

            var localToolsCommandResolver = new LocalToolsCommandResolver(
                toolManifest,
                _localToolsResolverCache,
                _fileSystem);

            _fileSystem.File.Delete(fakeExecutable.Value);

            Action action = () => localToolsCommandResolver.ResolveStrict(new CommandResolverArguments()
            {
                CommandName = $"dotnet-{toolCommandNameA.ToString()}",
            });

            action.ShouldThrow <GracefulException>(string.Format(CommandFactory.LocalizableStrings.NeedRunToolRestore,
                                                                 toolCommandNameA.ToString()));
        }
Пример #3
0
        public void WhenNuGetGlobalPackageLocationIsNotRestoredItThrowsGracefulException()
        {
            ToolCommandName toolCommandNameA = new ToolCommandName("a");
            NuGetVersion    packageVersionA  = NuGetVersion.Parse("1.0.4");

            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, ManifestFilename),
                                          _jsonContent.Replace("$TOOLCOMMAND$", toolCommandNameA.Value));
            ToolManifestFinder toolManifest =
                new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem);

            var localToolsCommandResolver = new LocalToolsCommandResolver(
                toolManifest,
                _localToolsResolverCache,
                _fileSystem);

            Action action = () => localToolsCommandResolver.ResolveStrict(new CommandResolverArguments()
            {
                CommandName = $"dotnet-{toolCommandNameA.ToString()}",
            });

            action.ShouldThrow <GracefulException>(string.Format(CommandFactory.LocalizableStrings.NeedRunToolRestore,
                                                                 toolCommandNameA.ToString()));
        }