public void GivenAnInstalledShimRemoveCommitsIfTransactionIsCompleted(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().NotBeEmpty(); using (var scope = new TransactionScope( TransactionScopeOption.Required, TimeSpan.Zero)) { shellShimRepository.RemoveShim(shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); scope.Complete(); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }
public void WhenMultipleSameNamePackagedShimProvidedItThrows() { const string tokenToIdentifyCopiedShim = "packagedShim"; var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); var packagedShimFolder = GetNewCleanFolderUnderTempRoot(); var dummyShimPath = Path.Combine(packagedShimFolder, shellCommandName); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { dummyShimPath = dummyShimPath + ".exe"; } File.WriteAllText(dummyShimPath, tokenToIdentifyCopiedShim); ShellShimRepository shellShimRepository = GetShellShimRepositoryWithMockMaker(pathToShim); FilePath[] filePaths = new[] { new FilePath(dummyShimPath), new FilePath("path" + dummyShimPath) }; Action a = () => shellShimRepository.CreateShim( new FilePath("dummy.dll"), new ToolCommandName(shellCommandName), new[] { new FilePath(dummyShimPath), new FilePath("path" + dummyShimPath) }); a.ShouldThrow <ShellShimException>() .And.Message .Should().Contain( string.Format( CommonLocalizableStrings.MoreThanOnePackagedShimAvailable, string.Join(';', filePaths))); }
public void WhenPackagedShimProvidedItCopies() { const string tokenToIdentifyCopiedShim = "packagedShim"; var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); var packagedShimFolder = GetNewCleanFolderUnderTempRoot(); var dummyShimPath = Path.Combine(packagedShimFolder, shellCommandName); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { dummyShimPath = dummyShimPath + ".exe"; } File.WriteAllText(dummyShimPath, tokenToIdentifyCopiedShim); ShellShimRepository shellShimRepository = GetShellShimRepositoryWithMockMaker(pathToShim); shellShimRepository.CreateShim( new FilePath("dummy.dll"), new ToolCommandName(shellCommandName), new[] { new FilePath(dummyShimPath) }); var createdShim = Directory.EnumerateFileSystemEntries(pathToShim).Single(); File.ReadAllText(createdShim).Should().Contain(tokenToIdentifyCopiedShim); }
public void GivenAnInstalledShimRemoveDeletesTheShimFiles(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().NotBeEmpty(); shellShimRepository.RemoveShim(shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }
public void GivenAnExceptionItWillRollback(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); } Action intendedError = () => throw new ToolPackageException("simulated error"); Action a = () => { using (var scope = new TransactionScope( TransactionScopeOption.Required, TimeSpan.Zero)) { shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); intendedError(); scope.Complete(); } }; a.ShouldThrow <ToolPackageException>().WithMessage("simulated error"); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }
public void GivenAnExecutablePathDirectoryThatDoesNotExistItCanGenerateShimFile() { var outputDll = MakeHelloWorldExecutableDll(); var extraNonExistDirectory = Path.GetRandomFileName(); var shellShimRepository = new ShellShimRepository(new DirectoryPath(Path.Combine(TempRoot.Root, extraNonExistDirectory)), GetAppHostTemplateFromStage2()); var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); Action a = () => shellShimRepository.CreateShim(outputDll, shellCommandName); a.ShouldNotThrow <DirectoryNotFoundException>(); }
public void GivenAnExecutablePathDirectoryThatDoesNotExistItCanGenerateShimFile() { var outputDll = _reusedHelloWorldExecutableDll.Value; var testFolder = TestAssets.CreateTestDirectory().FullName; var extraNonExistDirectory = Path.GetRandomFileName(); var shellShimRepository = new ShellShimRepository(new DirectoryPath(Path.Combine(testFolder, extraNonExistDirectory)), GetAppHostTemplateFromStage2()); var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); Action a = () => shellShimRepository.CreateShim(outputDll, new ToolCommandName(shellCommandName)); a.ShouldNotThrow <DirectoryNotFoundException>(); }
public void GivenAnExecutablePathItCanGenerateShimFile() { var outputDll = MakeHelloWorldExecutableDll(); var pathToShim = GetNewCleanFolderUnderTempRoot(); ShellShimRepository shellShimRepository = ConfigBasicTestDependencyShellShimRepository(pathToShim); var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); shellShimRepository.CreateShim(outputDll, new ToolCommandName(shellCommandName)); var stdOut = ExecuteInShell(shellCommandName, pathToShim); stdOut.Should().Contain("Hello World"); }
public void GivenAShimItPassesThroughArguments(string arguments, string[] expectedPassThru) { var outputDll = MakeHelloWorldExecutableDll(); var pathToShim = GetNewCleanFolderUnderTempRoot(); var shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); shellShimRepository.CreateShim(outputDll, shellCommandName); var stdOut = ExecuteInShell(shellCommandName, pathToShim, arguments); for (int i = 0; i < expectedPassThru.Length; i++) { stdOut.Should().Contain($"{i} = {expectedPassThru[i]}"); } }
public void GivenAnExecutableAndRelativePathToShimPathItCanGenerateShimFile() { var outputDll = MakeHelloWorldExecutableDll(); // To reproduce the bug, dll need to be nested under the shim var parentPathAsShimPath = outputDll.GetDirectoryPath().GetParentPath().GetParentPath().Value; var relativePathToShim = Path.GetRelativePath( Directory.GetCurrentDirectory(), parentPathAsShimPath); ShellShimRepository shellShimRepository = ConfigBasicTestDependencyShellShimRepository(relativePathToShim); var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); shellShimRepository.CreateShim(outputDll, new ToolCommandName(shellCommandName)); var stdOut = ExecuteInShell(shellCommandName, relativePathToShim); stdOut.Should().Contain("Hello World"); }
public void GivenAnExecutablePathItCanGenerateShimFileInTransaction() { var outputDll = MakeHelloWorldExecutableDll(); var pathToShim = GetNewCleanFolderUnderTempRoot(); var shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); using (var transactionScope = new TransactionScope( TransactionScopeOption.Required, TimeSpan.Zero)) { shellShimRepository.CreateShim(outputDll, shellCommandName); transactionScope.Complete(); } var stdOut = ExecuteInShell(shellCommandName, pathToShim); stdOut.Should().Contain("Hello World"); }
public void GivenAnRunnerOrEntryPointItCanCreateConfig(string entryPointPath, string runner) { var pathToShim = GetNewCleanFolderUnderTempRoot(); var shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); var tmpFile = new FilePath(Path.Combine(pathToShim, Path.GetRandomFileName())); shellShimRepository.CreateConfigFile(tmpFile, new FilePath(entryPointPath), 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 == entryPointPath); }
public void GivenAShimConflictItWillRollback(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); MakeNameConflictingCommand(pathToShim, shellCommandName); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); } Action a = () => { using (var scope = new TransactionScope( TransactionScopeOption.Required, TimeSpan.Zero)) { shellShimRepository.CreateShim(new FilePath("dummy.dll"), shellCommandName); scope.Complete(); } }; a.ShouldThrow <ShellShimException>().Where( ex => ex.Message == string.Format( CommonLocalizableStrings.ShellShimConflict, shellCommandName)); Directory .EnumerateFileSystemEntries(pathToShim) .Should() .HaveCount(1, "should only be the original conflicting command"); }
public void GivenANonexistentShimRemoveDoesNotThrow(bool testMockBehaviorIsInSync) { var shellCommandName = nameof(ShellShimRepositoryTests) + Path.GetRandomFileName(); var pathToShim = GetNewCleanFolderUnderTempRoot(); IShellShimRepository shellShimRepository; if (testMockBehaviorIsInSync) { shellShimRepository = new ShellShimRepositoryMock(new DirectoryPath(pathToShim)); } else { shellShimRepository = new ShellShimRepository(new DirectoryPath(pathToShim)); } Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); shellShimRepository.RemoveShim(shellCommandName); Directory.EnumerateFileSystemEntries(pathToShim).Should().BeEmpty(); }