diff options
Diffstat (limited to 'src/test/WixToolsetTest.ManagedHost/TestEngine.cs')
-rw-r--r-- | src/test/WixToolsetTest.ManagedHost/TestEngine.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.ManagedHost/TestEngine.cs b/src/test/WixToolsetTest.ManagedHost/TestEngine.cs new file mode 100644 index 00000000..4dd531ad --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/TestEngine.cs | |||
@@ -0,0 +1,53 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolsetTest.ManagedHost | ||
4 | { | ||
5 | using System.Collections.Generic; | ||
6 | using System.Diagnostics; | ||
7 | using WixBuildTools.TestSupport; | ||
8 | |||
9 | public class TestEngine | ||
10 | { | ||
11 | private static readonly string TestEngineFile = TestData.Get(@"..\Win32\examples\Example.TestEngine\Example.TestEngine.exe"); | ||
12 | |||
13 | public TestEngineResult RunShutdownEngine(string baFile) | ||
14 | { | ||
15 | var args = new string[] { '"' + baFile + '"' }; | ||
16 | return RunProcessCaptureOutput(TestEngineFile, args); | ||
17 | } | ||
18 | |||
19 | private static TestEngineResult RunProcessCaptureOutput(string executablePath, string[] arguments = null, string workingFolder = null) | ||
20 | { | ||
21 | var startInfo = new ProcessStartInfo(executablePath) | ||
22 | { | ||
23 | Arguments = string.Join(' ', arguments), | ||
24 | CreateNoWindow = true, | ||
25 | RedirectStandardError = true, | ||
26 | RedirectStandardOutput = true, | ||
27 | UseShellExecute = false, | ||
28 | WorkingDirectory = workingFolder, | ||
29 | }; | ||
30 | |||
31 | var exitCode = 0; | ||
32 | var output = new List<string>(); | ||
33 | |||
34 | using (var process = Process.Start(startInfo)) | ||
35 | { | ||
36 | process.OutputDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; | ||
37 | process.ErrorDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; | ||
38 | |||
39 | process.BeginErrorReadLine(); | ||
40 | process.BeginOutputReadLine(); | ||
41 | |||
42 | process.WaitForExit(); | ||
43 | exitCode = process.ExitCode; | ||
44 | } | ||
45 | |||
46 | return new TestEngineResult | ||
47 | { | ||
48 | ExitCode = exitCode, | ||
49 | Output = output, | ||
50 | }; | ||
51 | } | ||
52 | } | ||
53 | } | ||