Exemplo n.º 1
0
        public void GivenNoManifestFileItThrows()
        {
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should()
            .Contain(string.Format(LocalizableStrings.CannotFindAnyManifestsFileSearched, ""));
        }
Exemplo n.º 2
0
        public void GivenManifestFileOnSameDirectoryWhenFindByCommandNameWithDifferentCasingItGetContent()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContent);
            var toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem);

            toolManifest.TryFind(new ToolCommandName("dotnetSay"), out var result).Should().BeTrue();

            result.Should().Be(new ToolManifestPackage(
                                   new PackageId("dotnetsay"),
                                   NuGetVersion.Parse("2.1.4"),
                                   new[] { new ToolCommandName("dotnetsay") },
                                   new DirectoryPath(_testDirectoryRoot)));
        }
Exemplo n.º 3
0
        public void WhenCalledWithNonExistsFilePathItThrows()
        {
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find(new FilePath(Path.Combine(_testDirectoryRoot, "non-exists")));

            a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should()
            .Contain(string.Format(LocalizableStrings.CannotFindAnyManifestsFileSearched, ""));
        }
Exemplo n.º 4
0
        public void GivenManifestFileOnSameDirectoryItGetContent()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContent);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            var manifestResult = toolManifest.Find();

            AssertToolManifestPackageListEqual(_defaultExpectedResult, manifestResult);
        }
Exemplo n.º 5
0
        public void GivenInvalidJsonManifestFileWhenFindByCommandNameItThrows()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentInvalidJson);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.TryFind(new ToolCommandName("dotnetSay"), out var result);

            a.ShouldThrow <ToolManifestException>();
        }
Exemplo n.º 6
0
        public void MissingIsRootInManifestFileItShouldThrow()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentIsRootMissing);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>().And.Message.Should().Contain(LocalizableStrings.ManifestMissingIsRoot);
        }
Exemplo n.º 7
0
        public void GivenMissingFieldManifestFileItReturnError()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithMissingField);
            var    toolManifest = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem);
            Action a            = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>().And.Message.Should().Contain(
                string.Format(LocalizableStrings.InvalidManifestFilePrefix,
                              Path.Combine(_testDirectoryRoot, _manifestFilename),
                              "\t" + string.Format(LocalizableStrings.InPackage, "t-rex",
                                                   ("\t\t" + LocalizableStrings.ToolMissingVersion + Environment.NewLine +
                                                    "\t\t" + LocalizableStrings.FieldCommandsIsMissing))));
        }
Exemplo n.º 8
0
        public void GivenManifestFileOnParentDirectoryWhenFindByCommandNameItGetContent()
        {
            var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub");

            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContent);
            var toolManifest = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem);

            toolManifest.TryFind(new ToolCommandName("dotnetsay"), out var result).Should().BeTrue();

            result.ShouldBeEquivalentTo(new ToolManifestPackage(
                                            new PackageId("dotnetsay"),
                                            NuGetVersion.Parse("2.1.4"),
                                            new[] { new ToolCommandName("dotnetsay") }));
        }
Exemplo n.º 9
0
        public void GivenConflictedManifestFileInDifferentFieldsWhenFindByCommandNameItOnlyConsiderTheFirstIsRoot()
        {
            var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub");

            _fileSystem.Directory.CreateDirectory(subdirectoryOfTestRoot);
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename),
                                          _jsonContentInParentDirectory);
            _fileSystem.File.WriteAllText(Path.Combine(subdirectoryOfTestRoot, _manifestFilename),
                                          _jsonContentInCurrentDirectoryIsRootTrue);
            var toolManifest   = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem);
            var manifestResult = toolManifest.Find();

            toolManifest.TryFind(new ToolCommandName("dotnetsay2"), out var result).Should().BeFalse();
        }
Exemplo n.º 10
0
        public void GivenInvalidJsonIntergerManifestFileItThrows()
        {
            _fileSystem.File.WriteAllText(
                Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonInvalidJsonInterger);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>();
        }
Exemplo n.º 11
0
        // https://github.com/JamesNK/Newtonsoft.Json/issues/931#issuecomment-224104005
        // Due to a limitation of newtonsoft json
        public void GivenManifestWithDuplicatedPackageIdItReturnsTheLastValue()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename),
                                          _jsonWithDuplicatedPackagedId);
            var toolManifest   = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem);
            var manifestResult = toolManifest.Find();

            manifestResult.Should()
            .Contain(
                new ToolManifestPackage(
                    new PackageId("t-rex"),
                    NuGetVersion.Parse("2.1.4"),
                    new[] { new ToolCommandName("t-rex") }));
        }
Exemplo n.º 12
0
        public void GivenInvalidFieldsManifestFileItThrows()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithInvalidField);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>().And.Message.Should()
            .Contain(string.Format(LocalizableStrings.VersionIsInvalid, "1.*"));
        }
Exemplo n.º 13
0
        public void GivenConflictedManifestFileInDifferentFieldsItOnlyConsiderTheFirstIsRoot()
        {
            var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub");

            _fileSystem.Directory.CreateDirectory(subdirectoryOfTestRoot);
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename),
                                          _jsonContentInParentDirectory);
            _fileSystem.File.WriteAllText(Path.Combine(subdirectoryOfTestRoot, _manifestFilename),
                                          _jsonContentInCurrentDirectoryIsRootTrue);
            var toolManifest   = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem);
            var manifestResult = toolManifest.Find();

            manifestResult.Count.Should().Be(2, "only content in the current directory manifest file is considered");
        }
Exemplo n.º 14
0
        public void GivenManifestFileOnSameDirectoryItCanFindTheFirstManifestFile()
        {
            string manifestPath = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestPath, _jsonContent);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            FilePath toolmanifestFilePath = toolManifest.FindFirst();

            toolmanifestFilePath.Value.Should().Be(manifestPath);
        }
Exemplo n.º 15
0
        public void DifferentVersionOfManifestFileItThrows()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename),
                                          _jsonContentHigherVersion);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());


            Action a = () => toolManifest.TryFind(new ToolCommandName("dotnetsay"), out var result);

            a.ShouldThrow <ToolManifestException>();
        }
Exemplo n.º 16
0
        public void DifferentVersionOfManifestFileItShouldThrow()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonContentHigherVersion);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>().And.Message.Should().Contain(string.Format(
                                                                                     LocalizableStrings.ManifestVersionHigherThanSupported,
                                                                                     99, 1));
        }
Exemplo n.º 17
0
        public void GivenInvalidTypeManifestFileItThrows()
        {
            _fileSystem.File.WriteAllText(
                Path.Combine(_testDirectoryRoot, _manifestFilename), _jsonWithInvalidType);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>()
            .And.Message.Should().Contain(string.Format(LocalizableStrings.UnexpectedTypeInJson, "True|False", "isRoot"));
        }
Exemplo n.º 18
0
        public void GivenManifestFileOnSameDirectoryItDoesNotThrowsWhenTheManifestFileIsNotValid()
        {
            string manifestPath = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestPath, _jsonWithMissingField);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            FilePath toolmanifestFilePath = toolManifest.FindFirst();

            toolmanifestFilePath.Value.Should().Be(manifestPath);
        }
Exemplo n.º 19
0
        public void ItCanResolveAmbiguityCausedByPrefixDotnetDash()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, ManifestFilename),
                                          _jsonContentWithDotnetDash);
            ToolManifestFinder toolManifest =
                new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem);

            var fakeExecutableA       = _nugetGlobalPackagesFolder.WithFile("fakeExecutable-a.dll");
            var fakeExecutableDotnetA = _nugetGlobalPackagesFolder.WithFile("fakeExecutable-a.dll");

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

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

            localToolsCommandResolver.Resolve(new CommandResolverArguments()
            {
                CommandName = "dotnet-a",
            }).Args.Trim('"').Should().Be(fakeExecutableA.Value);

            localToolsCommandResolver.Resolve(new CommandResolverArguments()
            {
                CommandName = "dotnet-dotnet-a",
            }).Args.Trim('"').Should().Be(fakeExecutableDotnetA.Value);
        }
Exemplo n.º 20
0
        public void GivenManifestFileOnSameDirectoryItThrowsWhenTheManifestFileCannotBeFound()
        {
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.FindFirst();

            a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should()
            .Contain(LocalizableStrings.CannotFindAManifestFile);

            a.ShouldThrow <ToolManifestCannotBeFoundException>().And.VerboseMessage.Should()
            .Contain(string.Format(LocalizableStrings.ListOfSearched, ""));
        }
Exemplo n.º 21
0
        public void GivenManifestFileInDotConfigDirectoryItGetContent()
        {
            var dotnetconfigDirectory = Path.Combine(_testDirectoryRoot, ".config");

            _fileSystem.Directory.CreateDirectory(dotnetconfigDirectory);
            _fileSystem.File.WriteAllText(Path.Combine(dotnetconfigDirectory, _manifestFilename), _jsonContent);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            var manifestResult = toolManifest.Find();

            AssertToolManifestPackageListEqual(_defaultExpectedResult, manifestResult);
        }
Exemplo n.º 22
0
        public void GivenManifestWithDuplicatedPackageIdItReturnsTheLastValue()
        {
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename),
                                          _jsonWithDuplicatedPackagedId);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>().And.Message.Should()
            .Contain(string.Format(string.Format(LocalizableStrings.MultipleSamePackageId,
                                                 string.Join(", ", "t-rex")), ""));
        }
Exemplo n.º 23
0
        public void WhenCalledWithFilePathItGetContent()
        {
            string customFileName = "customname.file";

            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, customFileName), _jsonContent);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(_testDirectoryRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            var manifestResult =
                toolManifest.Find(new FilePath(Path.Combine(_testDirectoryRoot, customFileName)));

            AssertToolManifestPackageListEqual(_defaultExpectedResult, manifestResult);
        }
Exemplo n.º 24
0
        public void GivenManifestFileOnSameDirectoryWithMarkOfTheWebDetectorItThrows()
        {
            string manifestFilePath = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFilePath, _jsonContent);

            var fakeMarkOfTheWebDetector = new FakeDangerousFileDetector(manifestFilePath);
            var toolManifest
                = new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem, fakeMarkOfTheWebDetector);
            Action a = () => toolManifest.Find();

            a.ShouldThrow <ToolManifestException>()
            .And.Message

            .Should().Contain(
                string.Format(LocalizableStrings.ManifestHasMarkOfTheWeb, manifestFilePath),
                "The message is similar to Windows file property page");
        }
Exemplo n.º 25
0
        public void GivenConflictedManifestFileInDifferentFieldsWhenFindByCommandNameItReturnMergedContent()
        {
            var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub");

            _fileSystem.Directory.CreateDirectory(subdirectoryOfTestRoot);
            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, _manifestFilename),
                                          _jsonContentInParentDirectory);
            _fileSystem.File.WriteAllText(Path.Combine(subdirectoryOfTestRoot, _manifestFilename),
                                          _jsonContentInCurrentDirectory);
            var toolManifest = new ToolManifestFinder(new DirectoryPath(subdirectoryOfTestRoot), _fileSystem);

            toolManifest.TryFind(new ToolCommandName("t-rex"), out var result).Should().BeTrue();

            result.ShouldBeEquivalentTo(new ToolManifestPackage(
                                            new PackageId("t-rex"),
                                            NuGetVersion.Parse("1.0.49"),
                                            new[] { new ToolCommandName("t-rex") }));
        }
Exemplo n.º 26
0
        public void ItCanFindToolExecutable()
        {
            var          toolCommand     = "a";
            NuGetVersion packageVersionA = NuGetVersion.Parse("1.0.4");

            _fileSystem.File.WriteAllText(Path.Combine(_testDirectoryRoot, ManifestFilename),
                                          _jsonContent.Replace("$TOOLCOMMAND$", toolCommand));
            ToolManifestFinder toolManifest =
                new ToolManifestFinder(new DirectoryPath(_testDirectoryRoot), _fileSystem);
            ToolCommandName toolCommandNameA = new ToolCommandName(toolCommand);
            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)
            }, _nugetGlobalPackagesFolder);

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

            var result = localToolsCommandResolver.Resolve(new CommandResolverArguments()
            {
                CommandName = "dotnet-a",
            });

            result.Should().NotBeNull();

            var commandPath = result.Args.Trim('"');

            _fileSystem.File.Exists(commandPath).Should().BeTrue("the following path exists: " + commandPath);
            commandPath.Should().Be(fakeExecutable.Value);
        }
Exemplo n.º 27
0
        public void GivenNoManifestFileWhenFindContainPackageIdItThrows()
        {
            var subdirectoryOfTestRoot = Path.Combine(_testDirectoryRoot, "sub");

            _fileSystem.Directory.CreateDirectory(subdirectoryOfTestRoot);
            var toolManifest =
                new ToolManifestFinder(
                    new DirectoryPath(subdirectoryOfTestRoot),
                    _fileSystem,
                    new FakeDangerousFileDetector());

            Action a = () => toolManifest.FindByPackageId(new PackageId("t-rex"));

            a.ShouldThrow <ToolManifestCannotBeFoundException>().And.Message.Should()
            .Contain(LocalizableStrings.CannotFindAManifestFile);

            a.ShouldThrow <ToolManifestCannotBeFoundException>().And.VerboseMessage.Should()
            .Contain(string.Format(LocalizableStrings.ListOfSearched, ""));
        }
Exemplo n.º 28
0
        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));
        }
Exemplo n.º 29
0
        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, "")));
        }
Exemplo n.º 30
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);

            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)
            }, _nugetGlobalPackagesFolder);

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

            _fileSystem.File.Delete(fakeExecutable.Value);

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

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