diff options
Diffstat (limited to 'src/wix/WixInternal.Core.TestPackage/WixRunnerResult.cs')
-rw-r--r-- | src/wix/WixInternal.Core.TestPackage/WixRunnerResult.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/wix/WixInternal.Core.TestPackage/WixRunnerResult.cs b/src/wix/WixInternal.Core.TestPackage/WixRunnerResult.cs new file mode 100644 index 00000000..9e7fa2f0 --- /dev/null +++ b/src/wix/WixInternal.Core.TestPackage/WixRunnerResult.cs | |||
@@ -0,0 +1,62 @@ | |||
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 WixInternal.Core.TestPackage | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using WixToolset.Data; | ||
8 | using Xunit; | ||
9 | |||
10 | /// <summary> | ||
11 | /// The result of an Execute method of <see cref="WixRunner"/>. | ||
12 | /// </summary> | ||
13 | public class WixRunnerResult | ||
14 | { | ||
15 | /// <summary> | ||
16 | /// ExitCode for the operation. | ||
17 | /// </summary> | ||
18 | public int ExitCode { get; set; } | ||
19 | |||
20 | /// <summary> | ||
21 | /// Messages from the operation. | ||
22 | /// </summary> | ||
23 | public Message[] Messages { get; set; } | ||
24 | |||
25 | /// <summary> | ||
26 | /// | ||
27 | /// </summary> | ||
28 | /// <returns></returns> | ||
29 | public WixRunnerResult AssertSuccess() | ||
30 | { | ||
31 | AssertSuccess(this.ExitCode, this.Messages); | ||
32 | return this; | ||
33 | } | ||
34 | |||
35 | /// <summary> | ||
36 | /// | ||
37 | /// </summary> | ||
38 | /// <param name="exitCode"></param> | ||
39 | /// <param name="messages"></param> | ||
40 | public static void AssertSuccess(int exitCode, IEnumerable<Message> messages) | ||
41 | { | ||
42 | Assert.True(0 == exitCode, $"\r\n\r\nWixRunner failed with exit code: {exitCode}\r\n Output: {String.Join("\r\n ", FormatMessages(messages))}\r\n"); | ||
43 | } | ||
44 | |||
45 | private static IEnumerable<string> FormatMessages(IEnumerable<Message> messages) | ||
46 | { | ||
47 | foreach (var message in messages) | ||
48 | { | ||
49 | var filename = message.SourceLineNumbers?.FileName ?? "TEST"; | ||
50 | var line = message.SourceLineNumbers?.LineNumber ?? -1; | ||
51 | var type = message.Level.ToString().ToLowerInvariant(); | ||
52 | |||
53 | if (line > 0) | ||
54 | { | ||
55 | filename = String.Concat(filename, "(", line, ")"); | ||
56 | } | ||
57 | |||
58 | yield return String.Format("{0} : {1} {2}{3:0000}: {4}", filename, type, "TEST", message.Id, message.ToString()); | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | } | ||