diff options
| author | Rob Mensching <rob@firegiant.com> | 2021-05-03 15:55:48 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2021-05-03 15:55:48 -0700 |
| commit | ba7bab476501c16e437b0aee71c1be02c3dda176 (patch) | |
| tree | 814fba485c29a7dfe1adb396169e27ed641ef9a3 /src/ext/Bal/test/WixToolsetTest.ManagedHost/TestEngine.cs | |
| parent | 14987a72cc1a3493ca8f80693d273352fc314bd9 (diff) | |
| download | wix-ba7bab476501c16e437b0aee71c1be02c3dda176.tar.gz wix-ba7bab476501c16e437b0aee71c1be02c3dda176.tar.bz2 wix-ba7bab476501c16e437b0aee71c1be02c3dda176.zip | |
Move Bal.wixext into ext
Diffstat (limited to 'src/ext/Bal/test/WixToolsetTest.ManagedHost/TestEngine.cs')
| -rw-r--r-- | src/ext/Bal/test/WixToolsetTest.ManagedHost/TestEngine.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/ext/Bal/test/WixToolsetTest.ManagedHost/TestEngine.cs b/src/ext/Bal/test/WixToolsetTest.ManagedHost/TestEngine.cs new file mode 100644 index 00000000..44538227 --- /dev/null +++ b/src/ext/Bal/test/WixToolsetTest.ManagedHost/TestEngine.cs | |||
| @@ -0,0 +1,74 @@ | |||
| 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 System.IO; | ||
| 8 | using WixBuildTools.TestSupport; | ||
| 9 | using WixToolset.Core.TestPackage; | ||
| 10 | |||
| 11 | public class TestEngine | ||
| 12 | { | ||
| 13 | private static readonly string TestEngineFile = TestData.Get(@"..\Win32\examples\Example.TestEngine\Example.TestEngine.exe"); | ||
| 14 | |||
| 15 | public TestEngineResult RunReloadEngine(string bundleFilePath, string tempFolderPath) | ||
| 16 | { | ||
| 17 | return this.RunTestEngine("reload", bundleFilePath, tempFolderPath); | ||
| 18 | } | ||
| 19 | |||
| 20 | public TestEngineResult RunShutdownEngine(string bundleFilePath, string tempFolderPath) | ||
| 21 | { | ||
| 22 | return this.RunTestEngine("shutdown", bundleFilePath, tempFolderPath); | ||
| 23 | } | ||
| 24 | |||
| 25 | private TestEngineResult RunTestEngine(string engineMode, string bundleFilePath, string tempFolderPath) | ||
| 26 | { | ||
| 27 | var baFolderPath = Path.Combine(tempFolderPath, "ba"); | ||
| 28 | var extractFolderPath = Path.Combine(tempFolderPath, "extract"); | ||
| 29 | var extractResult = BundleExtractor.ExtractBAContainer(null, bundleFilePath, baFolderPath, extractFolderPath); | ||
| 30 | extractResult.AssertSuccess(); | ||
| 31 | |||
| 32 | var args = new string[] { | ||
| 33 | engineMode, | ||
| 34 | '"' + bundleFilePath + '"', | ||
| 35 | '"' + extractResult.GetBAFilePath(baFolderPath) + '"', | ||
| 36 | }; | ||
| 37 | return RunProcessCaptureOutput(TestEngineFile, args); | ||
| 38 | } | ||
| 39 | |||
| 40 | private static TestEngineResult RunProcessCaptureOutput(string executablePath, string[] arguments = null, string workingFolder = null) | ||
| 41 | { | ||
| 42 | var startInfo = new ProcessStartInfo(executablePath) | ||
| 43 | { | ||
| 44 | Arguments = string.Join(' ', arguments), | ||
| 45 | CreateNoWindow = true, | ||
| 46 | RedirectStandardError = true, | ||
| 47 | RedirectStandardOutput = true, | ||
| 48 | UseShellExecute = false, | ||
| 49 | WorkingDirectory = workingFolder, | ||
| 50 | }; | ||
| 51 | |||
| 52 | var exitCode = 0; | ||
| 53 | var output = new List<string>(); | ||
| 54 | |||
| 55 | using (var process = Process.Start(startInfo)) | ||
| 56 | { | ||
| 57 | process.OutputDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; | ||
| 58 | process.ErrorDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; | ||
| 59 | |||
| 60 | process.BeginErrorReadLine(); | ||
| 61 | process.BeginOutputReadLine(); | ||
| 62 | |||
| 63 | process.WaitForExit(); | ||
| 64 | exitCode = process.ExitCode; | ||
| 65 | } | ||
| 66 | |||
| 67 | return new TestEngineResult | ||
| 68 | { | ||
| 69 | ExitCode = exitCode, | ||
| 70 | Output = output, | ||
| 71 | }; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
