@joebigelow / wix / commits / f17f7138

Add inner text conversions for Util.wixext

Rob Mensching committed Jun 26, 2020 at 14:55 UTC f17f7138de534891a2605c9a86c0acc36cc41154
2 files changed +87
src/WixToolset.Converters/WixConverter.cs
+8
@@ -63,7 +63,9 @@ namespace WixToolset.Converters
63 private static readonly XName ShortcutPropertyElementName = WixNamespace + "ShortcutProperty";
64 private static readonly XName TextElementName = WixNamespace + "Text";
65 private static readonly XName UITextElementName = WixNamespace + "UIText";
66 + private static readonly XName UtilCloseApplicationElementName = WixUtilNamespace + "CloseApplication";
67 private static readonly XName UtilPermissionExElementName = WixUtilNamespace + "PermissionEx";
68 + private static readonly XName UtilXmlConfigElementName = WixUtilNamespace + "XmlConfig";
69 private static readonly XName CustomActionElementName = WixNamespace + "CustomAction";
70 private static readonly XName PropertyElementName = WixNamespace + "Property";
71 private static readonly XName WixElementWithoutNamespaceName = XNamespace.None + "Wix";
@@ -156,7 +158,9 @@ namespace WixToolset.Converters
158 { WixConverter.ShortcutPropertyElementName, this.ConvertShortcutPropertyElement },
159 { WixConverter.TextElementName, this.ConvertTextElement },
160 { WixConverter.UITextElementName, this.ConvertUITextElement },
161 + { WixConverter.UtilCloseApplicationElementName, this.ConvertUtilCloseApplicationElementName },
162 { WixConverter.UtilPermissionExElementName, this.ConvertUtilPermissionExElement },
163 + { WixConverter.UtilXmlConfigElementName, this.ConvertUtilXmlConfigElement },
164 { WixConverter.PropertyElementName, this.ConvertPropertyElement },
165 { WixConverter.WixElementWithoutNamespaceName, this.ConvertElementWithoutNamespace },
166 { WixConverter.IncludeElementWithoutNamespaceName, this.ConvertElementWithoutNamespace },
@@ -692,6 +696,8 @@ namespace WixToolset.Converters
696 this.ConvertInnerTextToAttribute(xProperty, "Value");
697 }
698
699 + private void ConvertUtilCloseApplicationElementName(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition");
700 +
701 private void ConvertUtilPermissionExElement(XElement element)
702 {
703 if (this.SourceVersion < 4 && null == element.Attribute("Inheritable"))
@@ -707,6 +713,8 @@ namespace WixToolset.Converters
713 }
714 }
715
716 + private void ConvertUtilXmlConfigElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value");
717 +
718 /// <summary>
719 /// Converts a Wix element.
720 /// </summary>
src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs new
+79
@@ -0,0 +1,79 @@
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.Converters
4 +{
5 + using System;
6 + using System.Xml.Linq;
7 + using WixToolset.Converters;
8 + using WixToolsetTest.Converters.Mocks;
9 + using Xunit;
10 +
11 + public class UtilExtensionFixture : BaseConverterFixture
12 + {
13 + [Fact]
14 + public void FixCloseAppsCondition()
15 + {
16 + var parse = String.Join(Environment.NewLine,
17 + "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>",
18 + " <Fragment>",
19 + " <util:CloseApplication Id='EndApp' Target='example.exe'>",
20 + " a&lt;>b",
21 + " </util:CloseApplication>",
22 + " </Fragment>",
23 + "</Wix>");
24 +
25 + var expected = new[]
26 + {
27 + "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">",
28 + " <Fragment>",
29 + " <util:CloseApplication Id=\"EndApp\" Target=\"example.exe\" Condition=\"a&lt;&gt;b\" />",
30 + " </Fragment>",
31 + "</Wix>"
32 + };
33 +
34 + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
35 +
36 + var messaging = new MockMessaging();
37 + var converter = new WixConverter(messaging, 2, null, null);
38 +
39 + var errors = converter.ConvertDocument(document);
40 + Assert.Equal(3, errors);
41 +
42 + var actualLines = UnformattedDocumentLines(document);
43 + CompareLineByLine(expected, actualLines);
44 + }
45 +
46 + [Fact]
47 + public void FixXmlConfigValue()
48 + {
49 + var parse = String.Join(Environment.NewLine,
50 + "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>",
51 + " <Fragment>",
52 + " <util:XmlConfig Id='Change' ElementPath='book'>",
53 + " a&lt;>b",
54 + " </util:XmlConfig>",
55 + " </Fragment>",
56 + "</Wix>");
57 +
58 + var expected = new[]
59 + {
60 + "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">",
61 + " <Fragment>",
62 + " <util:XmlConfig Id=\"Change\" ElementPath=\"book\" Value=\"a&lt;&gt;b\" />",
63 + " </Fragment>",
64 + "</Wix>"
65 + };
66 +
67 + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
68 +
69 + var messaging = new MockMessaging();
70 + var converter = new WixConverter(messaging, 2, null, null);
71 +
72 + var errors = converter.ConvertDocument(document);
73 + Assert.Equal(3, errors);
74 +
75 + var actualLines = UnformattedDocumentLines(document);
76 + CompareLineByLine(expected, actualLines);
77 + }
78 + }
79 +}