From 4a176b759c47fa1970fcfd0d9e25c294bda82ef4 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 22 Dec 2019 13:51:35 +1100 Subject: Update the MbaHost test project to use an external exe to load the BA, which allows loading a different .NET than the one running the tests. This also allows writing the tests in C# instead of C++/CLI. --- src/test/WixToolsetTest.ManagedHost/TestEngine.cs | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/WixToolsetTest.ManagedHost/TestEngine.cs (limited to 'src/test/WixToolsetTest.ManagedHost/TestEngine.cs') 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 @@ +// 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. + +namespace WixToolsetTest.ManagedHost +{ + using System.Collections.Generic; + using System.Diagnostics; + using WixBuildTools.TestSupport; + + public class TestEngine + { + private static readonly string TestEngineFile = TestData.Get(@"..\Win32\examples\Example.TestEngine\Example.TestEngine.exe"); + + public TestEngineResult RunShutdownEngine(string baFile) + { + var args = new string[] { '"' + baFile + '"' }; + return RunProcessCaptureOutput(TestEngineFile, args); + } + + private static TestEngineResult RunProcessCaptureOutput(string executablePath, string[] arguments = null, string workingFolder = null) + { + var startInfo = new ProcessStartInfo(executablePath) + { + Arguments = string.Join(' ', arguments), + CreateNoWindow = true, + RedirectStandardError = true, + RedirectStandardOutput = true, + UseShellExecute = false, + WorkingDirectory = workingFolder, + }; + + var exitCode = 0; + var output = new List(); + + using (var process = Process.Start(startInfo)) + { + process.OutputDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; + process.ErrorDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; + + process.BeginErrorReadLine(); + process.BeginOutputReadLine(); + + process.WaitForExit(); + exitCode = process.ExitCode; + } + + return new TestEngineResult + { + ExitCode = exitCode, + Output = output, + }; + } + } +} -- cgit v1.2.3-55-g6feb