public void WhenProcessCommandExcutes_DelegatesCreationToContainer() { container.CreateProcess(null).ReturnsForAnyArgs(process); var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args"); cmd.Execute(); container.Received().CreateProcess(Arg.Any <CreateProcessStartInfo>()); }
public void ReturnsResultWithExitCode() { container.CreateProcess(null).ReturnsForAnyArgs(process); process.ExitCode.Returns(100); var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args"); var result = cmd.Execute(); Assert.Equal(100, result.ExitCode); }
public void AwaitsProcessExit() { container.CreateProcess(null).ReturnsForAnyArgs(process); var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args"); cmd.Execute(); process.Received().WaitForExit(); }
public void WhenNotPrivileged_ShouldImpersonateRestrictedUser() { CreateProcessStartInfo si = null; container.CreateProcess(null).ReturnsForAnyArgs(c => { si = c.Arg <CreateProcessStartInfo>(); return(process); }); var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args", false); cmd.Execute(); container.Received().CreateProcess(Arg.Any <CreateProcessStartInfo>(), true); }
public void SetsTheWorkingDirectoryInStartInfo() { CreateProcessStartInfo si = null; container.CreateProcess(null).ReturnsForAnyArgs(c => { si = c.Arg <CreateProcessStartInfo>(); return(process); }); var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args", true); cmd.Execute(); Assert.Equal(tempDir, si.WorkingDirectory); }
private string InvokeCommandAndGetLogContent(string logRelativePath) { string content = null; // When Wait for exit is called, get the content of the env log. string expectedEnvPath = Path.Combine(tempDir, logRelativePath); process.When(p => p.WaitForExit()).Do(c => content = File.ReadAllText(expectedEnvPath)); process.Id.Returns(100); container.ContainerDirectoryPath.Returns(tempDir); container.CreateProcess(null).ReturnsForAnyArgs(process); var env = new Dictionary <string, string> { { "env1", "val1" }, { "env2", "val2" }, { "rootedenv", "@ROOT@\\sub\\dir" } }; var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args", environment: env); cmd.Execute(); return(content); }