Exemple #1
0
        public void GivenAnRunnerOrEntryPointItCanCreateConfig(string entryPointPath, string runner)
        {
            var entryPoint = new FilePath(entryPointPath);

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            var cleanFolderUnderTempRoot = GetNewCleanFolderUnderTempRoot();
            var shellShimMaker           = new ShellShimMaker(cleanFolderUnderTempRoot);

            var tmpFile = new FilePath(Path.Combine(cleanFolderUnderTempRoot, Path.GetRandomFileName()));

            shellShimMaker.CreateConfigFile(tmpFile, entryPoint, runner);

            new FileInfo(tmpFile.Value).Should().Exist();

            var generated = XDocument.Load(tmpFile.Value);

            generated.Descendants("appSettings")
            .Descendants("add")
            .Should()
            .Contain(e => e.Attribute("key").Value == "runner" && e.Attribute("value").Value == (runner ?? string.Empty))
            .And
            .Contain(e => e.Attribute("key").Value == "entryPoint" && e.Attribute("value").Value == entryPoint.Value);
        }
Exemple #2
0
        public void GivenAnExecutablePathWithExistingSameNameShimItRollsBack(bool testMockBehaviorIsInSync)
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            var pathToShim = GetNewCleanFolderUnderTempRoot();

            MakeNameConflictingCommand(pathToShim, shellCommandName);

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(pathToShim);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(pathToShim);
            }

            Action a = () =>
            {
                using (var t = new TransactionScope())
                {
                    shellShimMaker.CreateShim(new FilePath("dummy.dll"), shellCommandName);

                    t.Complete();
                }
            };

            a.ShouldThrow <GracefulException>();

            Directory.GetFiles(pathToShim).Should().HaveCount(1, "there is only intent conflicted command");
        }
Exemple #3
0
        public void GivenAnExecutablePathErrorHappensItRollsBack(bool testMockBehaviorIsInSync)
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            var pathToShim = GetNewCleanFolderUnderTempRoot();

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(pathToShim);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(pathToShim);
            }

            Action intendedError = () => throw new PackageObtainException();

            Action a = () =>
            {
                using (var t = new TransactionScope())
                {
                    shellShimMaker.CreateShim(new FilePath("dummy.dll"), shellCommandName);

                    intendedError();
                    t.Complete();
                }
            };

            a.ShouldThrow <PackageObtainException>();

            Directory.GetFiles(pathToShim).Should().BeEmpty();
        }
Exemple #4
0
        public override int Execute()
        {
            var executablePackagePath = new DirectoryPath(new CliFolderPathCalculator().ExecutablePackagesPath);

            var toolConfigurationAndExecutableDirectory = ObtainPackage(executablePackagePath);

            DirectoryPath executable = toolConfigurationAndExecutableDirectory
                                       .ExecutableDirectory
                                       .WithSubDirectories(
                toolConfigurationAndExecutableDirectory
                .Configuration
                .ToolAssemblyEntryPoint);

            var shellShimMaker = new ShellShimMaker(executablePackagePath.Value);
            var commandName    = toolConfigurationAndExecutableDirectory.Configuration.CommandName;

            shellShimMaker.EnsureCommandNameUniqueness(commandName);

            shellShimMaker.CreateShim(
                executable.Value,
                commandName);

            EnvironmentPathFactory
            .CreateEnvironmentPathInstruction()
            .PrintAddPathInstructionIfPathDoesNotExist();

            Reporter.Output.WriteLine(
                string.Format(LocalizableStrings.InstallationSucceeded, commandName));

            return(0);
        }
Exemple #5
0
        public void GivenAnExecutablePathWithExistingSameNameShimItThrows(bool testMockBehaviorIsInSync)
        {
            var shellCommandName         = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
            var cleanFolderUnderTempRoot = GetNewCleanFolderUnderTempRoot();

            MakeNameConflictingCommand(cleanFolderUnderTempRoot, shellCommandName);

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(cleanFolderUnderTempRoot);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(cleanFolderUnderTempRoot);
            }

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldThrow <GracefulException>()
            .And.Message
            .Should().Contain(
                $"Failed to install tool {shellCommandName}. A command with the same name already exists.");
        }
Exemple #6
0
        public void GivenAnExecutablePathWithExistingSameNameShimItThrows(bool testMockBehaviorIsInSync)
        {
            var shellCommandName         = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
            var cleanFolderUnderTempRoot = GetNewCleanFolderUnderTempRoot();

            MakeNameConflictingCommand(cleanFolderUnderTempRoot, shellCommandName);

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(cleanFolderUnderTempRoot);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(cleanFolderUnderTempRoot);
            }

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldThrow <GracefulException>()
            .And.Message
            .Should().Contain(
                string.Format(CommonLocalizableStrings.FailInstallToolSameName, shellCommandName));
        }
Exemple #7
0
        public override int Execute()
        {
            if (!_global)
            {
                throw new GracefulException(LocalizableStrings.InstallToolCommandOnlySupportGlobal);
            }

            var cliFolderPathCalculator = new CliFolderPathCalculator();
            var executablePackagePath   = new DirectoryPath(cliFolderPathCalculator.ExecutablePackagesPath);
            var offlineFeedPath         = new DirectoryPath(cliFolderPathCalculator.CliFallbackFolderPath);

            var toolConfigurationAndExecutablePath = ObtainPackage(executablePackagePath, offlineFeedPath);

            var shellShimMaker = new ShellShimMaker(executablePackagePath.Value);
            var commandName    = toolConfigurationAndExecutablePath.Configuration.CommandName;

            shellShimMaker.EnsureCommandNameUniqueness(commandName);

            shellShimMaker.CreateShim(
                toolConfigurationAndExecutablePath.Executable.Value,
                commandName);

            EnvironmentPathFactory
            .CreateEnvironmentPathInstruction()
            .PrintAddPathInstructionIfPathDoesNotExist();

            Reporter.Output.WriteLine(
                string.Format(LocalizableStrings.InstallationSucceeded, commandName));

            return(0);
        }
Exemple #8
0
        public void GivenAnExecutablePathWithoutExistingSameNameShimItShouldNotThrow()
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            var shellShimMaker = new ShellShimMaker(_pathToPlaceShim);

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldNotThrow();
        }
Exemple #9
0
        public void GivenAnExecutablePathDirectoryThatDoesNotExistItCanGenerateShimFile()
        {
            var outputDll = MakeHelloWorldExecutableDll();
            var extraNonExistDirectory = Path.GetRandomFileName();
            var shellShimMaker         = new ShellShimMaker(Path.Combine(TempRoot.Root, extraNonExistDirectory));
            var shellCommandName       = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            Action a = () => shellShimMaker.CreateShim(outputDll, shellCommandName);

            a.ShouldNotThrow <DirectoryNotFoundException>();
        }
Exemple #10
0
        public void GivenAnExecutablePathItCanGenerateShimFile()
        {
            var outputDll = MakeHelloWorldExecutableDll();

            var cleanFolderUnderTempRoot = GetNewCleanFolderUnderTempRoot();
            var shellShimMaker           = new ShellShimMaker(cleanFolderUnderTempRoot);
            var shellCommandName         = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            shellShimMaker.CreateShim(outputDll, shellCommandName);

            var stdOut = ExecuteInShell(shellCommandName, cleanFolderUnderTempRoot);

            stdOut.Should().Contain("Hello World");
        }
Exemple #11
0
        public void GivenAnExecutablePathItCanGenerateShimFile()
        {
            var outputDll = MakeHelloWorldExecutableDll();

            var shellShimMaker   = new ShellShimMaker(_pathToPlaceShim);
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            shellShimMaker.CreateShim(
                outputDll.FullName,
                shellCommandName);
            var stdOut = ExecuteInShell(shellCommandName);

            stdOut.Should().Contain("Hello World");
        }
Exemple #12
0
        public void GivenAnExecutablePathWithExistingSameNameShimItThrows()
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            MakeNameConflictingCommand(_pathToPlaceShim, shellCommandName);

            var shellShimMaker = new ShellShimMaker(_pathToPlaceShim);

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldThrow <GracefulException>()
            .And.Message
            .Should().Contain(
                $"Failed to install tool {shellCommandName}. A command with the same name already exists.");
        }
Exemple #13
0
        public void GivenAShimItPassesThroughArguments(string arguments, string[] expectedPassThru)
        {
            var outputDll = MakeHelloWorldExecutableDll();

            var cleanFolderUnderTempRoot = GetNewCleanFolderUnderTempRoot();
            var shellShimMaker           = new ShellShimMaker(cleanFolderUnderTempRoot);
            var shellCommandName         = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            shellShimMaker.CreateShim(outputDll, shellCommandName);

            var stdOut = ExecuteInShell(shellCommandName, cleanFolderUnderTempRoot, arguments);

            for (int i = 0; i < expectedPassThru.Length; i++)
            {
                stdOut.Should().Contain($"{i} = {expectedPassThru[i]}");
            }
        }
Exemple #14
0
        public override int Execute()
        {
            FilePath?configFile = null;

            if (_configFilePath != null)
            {
                configFile = new FilePath(_configFilePath);
            }

            var executablePackagePath = new DirectoryPath(new CliFolderPathCalculator().ExecutablePackagesPath);

            var toolConfigurationAndExecutableDirectory = ObtainPackage(
                _packageId,
                _packageVersion,
                configFile,
                _framework,
                executablePackagePath);

            DirectoryPath executable = toolConfigurationAndExecutableDirectory
                                       .ExecutableDirectory
                                       .WithSubDirectories(
                toolConfigurationAndExecutableDirectory
                .Configuration
                .ToolAssemblyEntryPoint);

            var shellShimMaker = new ShellShimMaker(executablePackagePath.Value);
            var commandName    = toolConfigurationAndExecutableDirectory.Configuration.CommandName;

            shellShimMaker.EnsureCommandNameUniqueness(commandName);

            shellShimMaker.CreateShim(
                executable.Value,
                commandName);

            EnvironmentPathFactory
            .CreateEnvironmentPathInstruction()
            .PrintAddPathInstructionIfPathDoesNotExist();

            Reporter.Output.WriteLine(
                $"{Environment.NewLine}The installation succeeded. If there is no other instruction. You can type the following command in shell directly to invoke: {commandName}");

            return(0);
        }
Exemple #15
0
        public void GivenAnExecutablePathWithoutExistingSameNameShimItShouldNotThrow(bool testMockBehaviorIsInSync)
        {
            var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();

            IShellShimMaker shellShimMaker;

            if (testMockBehaviorIsInSync)
            {
                shellShimMaker = new ShellShimMakerMock(TempRoot.Root);
            }
            else
            {
                shellShimMaker = new ShellShimMaker(TempRoot.Root);
            }

            Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName);

            a.ShouldNotThrow();
        }