Пример #1
0
        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);
        }
Пример #2
0
        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)));
        }
Пример #3
0
        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>();
        }
Пример #4
0
        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>();
        }
Пример #5
0
        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");
        }
Пример #6
0
        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]}");
            }
        }
Пример #7
0
        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");
        }
Пример #8
0
        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");
        }