public void ObservableErrorScenario() { const int n = 5; var obs = CreateProcessStartInfo .FromFile(Constants.IpsumExecutablePath, $"/error:{n}") .ToObservable(); var signals = obs.ToEnumerable().ToList(); GeneralInvariants(signals); Assert.IsTrue(signals.Any(__ => __.Type == ProcessSignalType.Exited && __.ExitCode != null), "Expected at least one signal with exitcode"); Assert.IsTrue(signals.All(__ => __.Type != ProcessSignalType.Disposed), "Unexpected dispose"); Assert.IsTrue(signals.Any(__ => __.ProcessId != null), "Expected to find a process id"); Assert.IsTrue(signals.Count(__ => __.Type == ProcessSignalType.ErrorData) == n, $"Expected to find {n} error lines"); Assert.IsTrue(signals.Count(__ => __.Type == ProcessSignalType.OutputData) == 0, $"Expected to find 0 output lines"); var c = 0; foreach (var result in signals) { if (result.Type == ProcessSignalType.OutputData) { Assert.AreEqual(Constants.IpsumLines[c], result.Data, $"Expected line data matches static lorem ipsum data"); c++; } } }
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); }
public void ObservableMixedScenario() { const int errorCount = 5; const int outputCount = 10; var obs = CreateProcessStartInfo .FromFile(Constants.IpsumExecutablePath, $"/output:{errorCount}", $"/error:{errorCount}") .EnsureFileExists() .ToObservable(); var signals = obs.ToEnumerable().ToList(); GeneralInvariants(signals); Assert.IsTrue(signals.Any(__ => __.Type == ProcessSignalType.Exited && __.ExitCode != null), "Expected at least one signal with exitcode"); Assert.IsTrue(signals.All(__ => __.Type != ProcessSignalType.Disposed), "Unexpected dispose"); Assert.IsTrue(signals.Any(__ => __.ProcessId != null), "Expected to find a process id"); Assert.IsTrue(signals.Count(__ => __.Type == ProcessSignalType.ErrorData) == errorCount, $"Expected to find {errorCount} error lines"); Assert.IsTrue(signals.Count(__ => __.Type == ProcessSignalType.OutputData) == errorCount, $"Expected to find {outputCount} output lines"); }
public async Task TaskScriptScenario() { const int outputCount = 10; const int errorCount = 5; var result = await CreateProcessStartInfo .FromFile(Constants.TestScriptFileName) .ToObservable() .RunAsync(); Assert.IsFalse(result.IsDisposed, "Unexpected dispose"); Assert.IsNotNull(result.ProcessId, "Expected to find a process id"); Assert.IsTrue(result.Data.Length >= (outputCount + errorCount), $"Expected at least {outputCount + outputCount} lines"); Assert.IsTrue(result.Data.Count(l => l.Type == DataLineType.Output) >= outputCount, $"Expected at least {outputCount} {DataLineType.Output} lines"); Assert.IsTrue(result.Data.Count(l => l.Type == DataLineType.Error) >= errorCount, $"Expected at least {errorCount} {DataLineType.Error} lines"); var c = 0; foreach (var l in result.Data) { Assert.AreEqual(c, l.LineNumber, $"Expected line number is sequential, starting with 0"); c++; } }
public async Task TaskMixedScenario() { const int outputCount = 5; const int errorCount = 3; var result = await CreateProcessStartInfo .FromFile(Constants.IpsumExecutablePath, $"/output:{outputCount}", $"/error:{errorCount}") .ToObservable() .RunAsync(); Assert.IsNotNull(result.ExitCode, "Expected exitcode"); Assert.IsFalse(result.IsDisposed, "Unexpected dispose"); Assert.IsNotNull(result.ProcessId, "Expected to find a process id"); Assert.AreEqual((outputCount + errorCount), result.Data.Length, $"Expected to find {outputCount+outputCount} lines"); Assert.IsTrue(result.Data.Count(l => l.Type == DataLineType.Output) == outputCount, $"Expected {outputCount} {DataLineType.Output} lines"); Assert.IsTrue(result.Data.Count(l => l.Type == DataLineType.Error) == errorCount, $"Expected {errorCount} {DataLineType.Error} lines"); var c = 0; foreach (var l in result.Data) { Assert.AreEqual(c, l.LineNumber, $"Expected line number is sequential, starting with 0"); c++; } }
public async Task TaskErrorScenario() { const int n = 5; var result = await CreateProcessStartInfo .FromFile(Constants.IpsumExecutablePath, $"/error:{n}") .EnsureFileExists() .ToObservable() .RunAsync(/*progress: new Progress<ProcessSignal>(p => Console.WriteLine(p.ToString()))*/); Assert.IsNotNull(result.ExitCode, "Expected exitcode"); Assert.IsFalse(result.IsDisposed, "Unexpected dispose"); Assert.IsNotNull(result.ProcessId, "Expected to find a process id"); Assert.AreEqual(n, result.Data.Length, $"Expected to find {n} lines"); Assert.IsTrue(result.Data.All(l => l.Type == DataLineType.Error), $"Not all lines are type={DataLineType.Error}"); var c = 0; foreach (var l in result.Data) { Assert.AreEqual(DataLineType.Error, l.Type, $"Expected line type = error"); Assert.AreEqual(c, l.LineNumber, $"Expected line number is sequential, starting with 0"); c++; } }
public async Task TaskOutputScenario() { const int n = 5; var result = await CreateProcessStartInfo .FromFile(Constants.IpsumExecutablePath, $"/output:{n}") .ToObservable() .RunAsync(); Assert.IsTrue(result.ExitCode == 0, "Expected exitcode=0"); Assert.IsTrue(!result.IsDisposed, "Unexpected dispose"); Assert.IsTrue(result.ProcessId != null, "Expected to find a process id"); Assert.IsTrue(result.Data.Length == n, $"Expected to find {n} lines"); Assert.IsTrue(result.Data.All(l => l.Type == DataLineType.Output), $"Not all lines are type={DataLineType.Output}"); var c = 0; foreach (var l in result.Data) { Assert.IsTrue(l.Type == DataLineType.Output, $"Expected line type = output"); Assert.IsTrue(l.LineNumber == c, $"Expected line number is sequential, starting with 0"); Assert.IsTrue(l.Data == Constants.IpsumLines[c], $"Expected line data matches static lorem ipsum data"); c++; } }