diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2019-12-22 13:51:35 +1100 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2019-12-22 13:34:07 +1000 |
| commit | 4a176b759c47fa1970fcfd0d9e25c294bda82ef4 (patch) | |
| tree | 961cc91c44569d72c12d9f2dc5b1c11a80bb94a9 /src/test/WixToolsetTest.ManagedHost | |
| parent | 43fb611edc680a74d229e8f1eeacb30adad8e3c7 (diff) | |
| download | wix-4a176b759c47fa1970fcfd0d9e25c294bda82ef4.tar.gz wix-4a176b759c47fa1970fcfd0d9e25c294bda82ef4.tar.bz2 wix-4a176b759c47fa1970fcfd0d9e25c294bda82ef4.zip | |
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.
Diffstat (limited to 'src/test/WixToolsetTest.ManagedHost')
4 files changed, 136 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs b/src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs new file mode 100644 index 00000000..8da42e77 --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs | |||
| @@ -0,0 +1,40 @@ | |||
| 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 WixBuildTools.TestSupport; | ||
| 6 | using Xunit; | ||
| 7 | |||
| 8 | public class MbaHostFixture | ||
| 9 | { | ||
| 10 | [Fact] | ||
| 11 | public void CanLoadFullFramework2MBA() | ||
| 12 | { | ||
| 13 | var testEngine = new TestEngine(); | ||
| 14 | var baFile = TestData.Get(@"..\examples\Example.FullFramework2MBA\mbahost.dll"); | ||
| 15 | |||
| 16 | var result = testEngine.RunShutdownEngine(baFile); | ||
| 17 | Assert.Equal(0, result.ExitCode); | ||
| 18 | |||
| 19 | var logMessages = result.Output; | ||
| 20 | Assert.Equal(2, logMessages.Count); | ||
| 21 | Assert.Equal("Loading managed bootstrapper application.", logMessages[0]); | ||
| 22 | Assert.Equal("Shutdown,ReloadBootstrapper,0", logMessages[1]); | ||
| 23 | } | ||
| 24 | |||
| 25 | [Fact] | ||
| 26 | public void CanLoadFullFramework4MBA() | ||
| 27 | { | ||
| 28 | var testEngine = new TestEngine(); | ||
| 29 | var baFile = TestData.Get(@"..\examples\Example.FullFramework4MBA\net48\mbahost.dll"); | ||
| 30 | |||
| 31 | var result = testEngine.RunShutdownEngine(baFile); | ||
| 32 | Assert.Equal(0, result.ExitCode); | ||
| 33 | |||
| 34 | var logMessages = result.Output; | ||
| 35 | Assert.Equal(2, logMessages.Count); | ||
| 36 | Assert.Equal("Loading managed bootstrapper application.", logMessages[0]); | ||
| 37 | Assert.Equal("Shutdown,ReloadBootstrapper,0", logMessages[1]); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
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 | } | ||
diff --git a/src/test/WixToolsetTest.ManagedHost/TestEngineResult.cs b/src/test/WixToolsetTest.ManagedHost/TestEngineResult.cs new file mode 100644 index 00000000..63f6f7f5 --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/TestEngineResult.cs | |||
| @@ -0,0 +1,12 @@ | |||
| 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 | |||
| 7 | public class TestEngineResult | ||
| 8 | { | ||
| 9 | public int ExitCode { get; set; } | ||
| 10 | public List<string> Output { get; set; } | ||
| 11 | } | ||
| 12 | } | ||
diff --git a/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj b/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj new file mode 100644 index 00000000..cb1d1c78 --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!-- 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. --> | ||
| 3 | |||
| 4 | <Project Sdk="Microsoft.NET.Sdk"> | ||
| 5 | <PropertyGroup> | ||
| 6 | <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| 7 | <IsPackable>false</IsPackable> | ||
| 8 | </PropertyGroup> | ||
| 9 | |||
| 10 | <PropertyGroup> | ||
| 11 | <NoWarn>NU1701</NoWarn> | ||
| 12 | </PropertyGroup> | ||
| 13 | |||
| 14 | <ItemGroup> | ||
| 15 | </ItemGroup> | ||
| 16 | |||
| 17 | <ItemGroup> | ||
| 18 | <ProjectReference Include="..\examples\FullFramework2MBA\Example.FullFramework2MBA.csproj" /> | ||
| 19 | <ProjectReference Include="..\examples\TestEngine\Example.TestEngine.vcxproj" /> | ||
| 20 | </ItemGroup> | ||
| 21 | |||
| 22 | <ItemGroup> | ||
| 23 | <PackageReference Include="WixBuildTools.TestSupport" Version="4.0.*" /> | ||
| 24 | </ItemGroup> | ||
| 25 | |||
| 26 | <ItemGroup> | ||
| 27 | <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | ||
| 28 | <PackageReference Include="xunit" Version="2.4.1" /> | ||
| 29 | <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="All" /> | ||
| 30 | </ItemGroup> | ||
| 31 | </Project> | ||
