public void InitializeThrowsExceptionIfDependencyPathDoesNotExist()
        {
            Mock <ITemporaryStorageManager> storageManagerMock = new Mock <ITemporaryStorageManager>();
            ExternalProcessManager          processManager     = CreateExternalProcessManager(storageManagerMock.Object);

            string invalidBaseDirectory = Path.Combine(baseDirectory, "DoesNotExist");

            Assert.ThrowsException <DependencyPathDoesNotExistException>(() => processManager.Initialize(invalidBaseDirectory, ""));
        }
        public void RunProcessThrowsExceptionIfExecutableDoesNotExist()
        {
            Mock <ITemporaryStorageManager> storageManagerMock = new Mock <ITemporaryStorageManager>();

            storageManagerMock.Setup(mock => mock.CreateFilePath("ExternalApp.exe")).Returns("DoesNotExistsPath.exe");
            ExternalProcessManager processManager = CreateExternalProcessManager(storageManagerMock.Object);

            processManager.Initialize(baseDirectory, "");

            Assert.ThrowsException <ExternalProcessExecutableDoesNotExist>(() => processManager.RunProcess());
        }
        public void InitializeCopiesDependencyContentsToTemporaryDirectoryForDifferentArchitectures(bool is64Bit, string architecture)
        {
            Mock <ITemporaryStorageManager> storageManagerMock = new Mock <ITemporaryStorageManager>();

            ExternalProcessManager processManager = CreateExternalProcessManager(storageManagerMock.Object, is64Bit);

            processManager.Initialize(baseDirectory, "");

            string expectedPath = Path.Combine(baseDirectory, "DependencyExe", architecture);

            storageManagerMock.Verify(mock => mock.CopyFolderContentsToTemporaryDirectory(expectedPath));
        }
        public void RunProcessThrowsExceptionIfWorkingDirectoryDoesNotExist()
        {
            Mock <ITemporaryStorageManager> storageManagerMock = new Mock <ITemporaryStorageManager>();
            string executableName = "ExternalApp.exe";

            storageManagerMock.Setup(mock => mock.CreateFilePath(executableName)).Returns(Path.Combine(expectedExecutablePath, executableName));
            //storageManagerMock.SetupGet(mock => mock.TemporaryDirectoryPath).Returns(expectedExecutablePath);
            storageManagerMock.SetupGet(mock => mock.TemporaryDirectoryPath).Returns(Path.Combine(expectedExecutablePath, "DoesNotExist"));
            ExternalProcessManager processManager = CreateExternalProcessManager(storageManagerMock.Object);

            processManager.Initialize(baseDirectory, "");

            Assert.ThrowsException <ExternalProcessWorkingDirectoryDoesNotExist>(() => processManager.RunProcess());
        }
        public void RunProcessReturnsProcessResultFromExecutable()
        {
            Mock <ITemporaryStorageManager> storageManagerMock = new Mock <ITemporaryStorageManager>();
            string executableName = "ExternalApp.exe";

            storageManagerMock.Setup(mock => mock.CreateFilePath(executableName)).Returns(Path.Combine(expectedExecutablePath, executableName));
            storageManagerMock.SetupGet(mock => mock.TemporaryDirectoryPath).Returns(expectedExecutablePath);
            ExternalProcessManager processManager = CreateExternalProcessManager(storageManagerMock.Object);

            processManager.Initialize(baseDirectory, "5");

            ProcessRunResult result = processManager.RunProcess();

            result.ProcessExitCode.Should().Be(5);
            result.Output.Should().Be($"Hello World!{Environment.NewLine}");
            result.Error.Should().Be($"Sad Trombone...{Environment.NewLine}");
        }