| 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.Linq; |
| 7 | using System.Xml.Linq; |
| 8 | using WixInternal.TestSupport; |
| 9 | using WixToolset.Converters; |
| 10 | using WixToolsetTest.Converters.Mocks; |
| 11 | using Xunit; |
| 12 | |
| 13 | public class PropertyFixture : BaseConverterFixture |
| 14 | { |
| 15 | [Fact] |
| 16 | public void CanFixCdataWhitespace() |
| 17 | { |
| 18 | var parse = String.Join(Environment.NewLine, |
| 19 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 20 | " <Fragment>", |
| 21 | " <Property Id='Prop'>", |
| 22 | " <![CDATA[1<2]]>", |
| 23 | " </Property>", |
| 24 | " </Fragment>", |
| 25 | "</Wix>"); |
| 26 | |
| 27 | var expected = new[] |
| 28 | { |
| 29 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 30 | " <Fragment>", |
| 31 | " <Property Id=\"Prop\" Value=\"1<2\" />", |
| 32 | " </Fragment>", |
| 33 | "</Wix>", |
| 34 | }; |
| 35 | |
| 36 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 37 | |
| 38 | var messaging = new MockMessaging(); |
| 39 | var converter = new WixConverter(messaging, 2, null, null); |
| 40 | |
| 41 | var errors = converter.ConvertDocument(document); |
| 42 | |
| 43 | var actual = UnformattedDocumentLines(document); |
| 44 | |
| 45 | WixAssert.CompareLineByLine(expected, actual); |
| 46 | Assert.Equal(1, errors); |
| 47 | } |
| 48 | |
| 49 | [Fact] |
| 50 | public void CanFixCdataWithWhitespace() |
| 51 | { |
| 52 | var parse = String.Join(Environment.NewLine, |
| 53 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 54 | " <Fragment>", |
| 55 | " <Property Id='Prop'>", |
| 56 | " <![CDATA[", |
| 57 | " 1<2", |
| 58 | " ]]>", |
| 59 | " </Property>", |
| 60 | " </Fragment>", |
| 61 | "</Wix>"); |
| 62 | |
| 63 | var expected = new[] |
| 64 | { |
| 65 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 66 | " <Fragment>", |
| 67 | " <Property Id=\"Prop\" Value=\"1<2\" />", |
| 68 | " </Fragment>", |
| 69 | "</Wix>", |
| 70 | }; |
| 71 | |
| 72 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 73 | |
| 74 | var messaging = new MockMessaging(); |
| 75 | var converter = new WixConverter(messaging, 2, null, null); |
| 76 | |
| 77 | var errors = converter.ConvertDocument(document); |
| 78 | |
| 79 | var actual = UnformattedDocumentLines(document); |
| 80 | |
| 81 | WixAssert.CompareLineByLine(expected, actual); |
| 82 | Assert.Equal(1, errors); |
| 83 | } |
| 84 | |
| 85 | [Fact] |
| 86 | public void CanKeepCdataWithOnlyWhitespace() |
| 87 | { |
| 88 | var parse = String.Join(Environment.NewLine, |
| 89 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 90 | " <Fragment>", |
| 91 | " <Property Id='Prop'><![CDATA[ ]]></Property>", |
| 92 | " </Fragment>", |
| 93 | "</Wix>"); |
| 94 | |
| 95 | var expected = new[] |
| 96 | { |
| 97 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 98 | " <Fragment>", |
| 99 | " <Property Id=\"Prop\" Value=\" \" />", |
| 100 | " </Fragment>", |
| 101 | "</Wix>", |
| 102 | }; |
| 103 | |
| 104 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 105 | |
| 106 | var messaging = new MockMessaging(); |
| 107 | var converter = new WixConverter(messaging, 2, null, null); |
| 108 | var errors = converter.ConvertDocument(document); |
| 109 | |
| 110 | var actual = UnformattedDocumentLines(document); |
| 111 | |
| 112 | WixAssert.CompareLineByLine(expected, actual); |
| 113 | Assert.Equal(1, errors); |
| 114 | } |
| 115 | |
| 116 | [Fact] |
| 117 | public void CanConvertWithValueAndEmptyText() |
| 118 | { |
| 119 | var parse = String.Join(Environment.NewLine, |
| 120 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 121 | " <Fragment>", |
| 122 | " <Property Id='Prop' Value='123'>", |
| 123 | " </Property>", |
| 124 | " </Fragment>", |
| 125 | "</Wix>"); |
| 126 | |
| 127 | var expected = new[] |
| 128 | { |
| 129 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 130 | " <Fragment>", |
| 131 | " <Property Id=\"Prop\" Value=\"123\">", |
| 132 | " </Property>", |
| 133 | " </Fragment>", |
| 134 | "</Wix>", |
| 135 | }; |
| 136 | |
| 137 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 138 | |
| 139 | var messaging = new MockMessaging(); |
| 140 | var converter = new WixConverter(messaging, 2, null, null); |
| 141 | var errors = converter.ConvertDocument(document); |
| 142 | |
| 143 | var actual = UnformattedDocumentLines(document); |
| 144 | |
| 145 | WixAssert.CompareLineByLine(expected, actual); |
| 146 | Assert.Equal(0, errors); |
| 147 | } |
| 148 | |
| 149 | [Fact] |
| 150 | public void CanConvertWithValueAndComment() |
| 151 | { |
| 152 | var parse = String.Join(Environment.NewLine, |
| 153 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 154 | " <Fragment>", |
| 155 | " <Property Id='Prop' Value='123'>", |
| 156 | " <!-- this is a comment -->", |
| 157 | " </Property>", |
| 158 | " </Fragment>", |
| 159 | "</Wix>"); |
| 160 | |
| 161 | var expected = new[] |
| 162 | { |
| 163 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 164 | " <Fragment>", |
| 165 | " <Property Id=\"Prop\" Value=\"123\">", |
| 166 | " <!-- this is a comment -->", |
| 167 | " </Property>", |
| 168 | " </Fragment>", |
| 169 | "</Wix>", |
| 170 | }; |
| 171 | |
| 172 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 173 | |
| 174 | var messaging = new MockMessaging(); |
| 175 | var converter = new WixConverter(messaging, 2, null, null); |
| 176 | var errors = converter.ConvertDocument(document); |
| 177 | |
| 178 | var actual = UnformattedDocumentLines(document); |
| 179 | |
| 180 | WixAssert.CompareLineByLine(expected, actual); |
| 181 | Assert.Equal(0, errors); |
| 182 | } |
| 183 | |
| 184 | [Fact] |
| 185 | public void CanErrorWithValueAndText() |
| 186 | { |
| 187 | var parse = String.Join(Environment.NewLine, |
| 188 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 189 | " <Fragment>", |
| 190 | " <Property Id='Prop' Value='123'>Not Allowed Value</Property>", |
| 191 | " </Fragment>", |
| 192 | "</Wix>"); |
| 193 | |
| 194 | var expected = new[] |
| 195 | { |
| 196 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 197 | " <Fragment>", |
| 198 | " <Property Id=\"Prop\" Value=\"123\">Not Allowed Value</Property>", |
| 199 | " </Fragment>", |
| 200 | "</Wix>", |
| 201 | }; |
| 202 | |
| 203 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 204 | |
| 205 | var messaging = new MockMessaging(); |
| 206 | var converter = new WixConverter(messaging, 2, null, null); |
| 207 | var errors = converter.ConvertDocument(document); |
| 208 | |
| 209 | var actual = UnformattedDocumentLines(document); |
| 210 | |
| 211 | WixAssert.CompareLineByLine(expected, actual); |
| 212 | WixAssert.CompareLineByLine(new[] |
| 213 | { |
| 214 | "Using Property element text is deprecated. Remove the element's text and use only the 'Value' attribute. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages (InnerTextDeprecated)" |
| 215 | }, messaging.Messages.Select(m => m.ToString()).ToArray()); |
| 216 | Assert.Equal(1, errors); |
| 217 | } |
| 218 | } |
| 219 | } |