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); }
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"); }
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(); }
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); }
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."); }
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)); }
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); }
public void GivenAnExecutablePathWithoutExistingSameNameShimItShouldNotThrow() { var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName(); var shellShimMaker = new ShellShimMaker(_pathToPlaceShim); Action a = () => shellShimMaker.EnsureCommandNameUniqueness(shellCommandName); a.ShouldNotThrow(); }
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>(); }
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"); }
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"); }
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."); }
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]}"); } }
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); }
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(); }