| 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 WixInternal.TestSupport; |
| 8 | using WixToolset.Converters; |
| 9 | using WixToolsetTest.Converters.Mocks; |
| 10 | using Xunit; |
| 11 | |
| 12 | public class CustomTableFixture : BaseConverterFixture |
| 13 | { |
| 14 | [Fact] |
| 15 | public void FixCustomTableCategoryAndModularization() |
| 16 | { |
| 17 | var parse = String.Join(Environment.NewLine, |
| 18 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 19 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 20 | " <Fragment>", |
| 21 | " <CustomTable Id='Custom1'>", |
| 22 | " <Column Id='Column1' Type='string' Category='Text' Modularize='Column' />", |
| 23 | " </CustomTable>", |
| 24 | " </Fragment>", |
| 25 | "</Wix>"); |
| 26 | |
| 27 | var expected = new[] |
| 28 | { |
| 29 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 30 | " <Fragment>", |
| 31 | " <CustomTable Id=\"Custom1\">", |
| 32 | " <Column Id=\"Column1\" Type=\"string\" Category=\"text\" Modularize=\"column\" />", |
| 33 | " </CustomTable>", |
| 34 | " </Fragment>", |
| 35 | "</Wix>" |
| 36 | }; |
| 37 | |
| 38 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 39 | |
| 40 | var messaging = new MockMessaging(); |
| 41 | var converter = new WixConverter(messaging, 2, null, null); |
| 42 | |
| 43 | var errors = converter.ConvertDocument(document); |
| 44 | Assert.Equal(4, errors); |
| 45 | |
| 46 | var actualLines = UnformattedDocumentLines(document); |
| 47 | WixAssert.CompareLineByLine(expected, actualLines); |
| 48 | } |
| 49 | |
| 50 | [Fact] |
| 51 | public void FixCustomRowTextValue() |
| 52 | { |
| 53 | var parse = String.Join(Environment.NewLine, |
| 54 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 55 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 56 | " <Fragment>", |
| 57 | " <CustomTable Id='Custom1'>", |
| 58 | " <Row>", |
| 59 | " <Data Id='Column1'>", |
| 60 | " Some value", |
| 61 | " </Data>", |
| 62 | " </Row>", |
| 63 | " </CustomTable>", |
| 64 | " </Fragment>", |
| 65 | "</Wix>"); |
| 66 | |
| 67 | var expected = new[] |
| 68 | { |
| 69 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 70 | " <Fragment>", |
| 71 | " <CustomTable Id=\"Custom1\">", |
| 72 | " <Row>", |
| 73 | " <Data Id=\"Column1\" Value=\"Some value\" />", |
| 74 | " </Row>", |
| 75 | " </CustomTable>", |
| 76 | " </Fragment>", |
| 77 | "</Wix>" |
| 78 | }; |
| 79 | |
| 80 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 81 | |
| 82 | var messaging = new MockMessaging(); |
| 83 | var converter = new WixConverter(messaging, 2, null, null); |
| 84 | |
| 85 | var errors = converter.ConvertDocument(document); |
| 86 | Assert.Equal(4, errors); |
| 87 | |
| 88 | var actualLines = UnformattedDocumentLines(document); |
| 89 | WixAssert.CompareLineByLine(expected, actualLines); |
| 90 | } |
| 91 | |
| 92 | [Fact] |
| 93 | public void FixCustomRowCdataValue() |
| 94 | { |
| 95 | var parse = String.Join(Environment.NewLine, |
| 96 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 97 | " <Fragment>", |
| 98 | " <CustomTable Id='Custom1'>", |
| 99 | " <Row>", |
| 100 | " <Data Id='Column1'>", |
| 101 | " <![CDATA[", |
| 102 | " Some value", |
| 103 | " ]]>", |
| 104 | " </Data>", |
| 105 | " </Row>", |
| 106 | " </CustomTable>", |
| 107 | " </Fragment>", |
| 108 | "</Wix>"); |
| 109 | |
| 110 | var expected = new[] |
| 111 | { |
| 112 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 113 | " <Fragment>", |
| 114 | " <CustomTable Id=\"Custom1\">", |
| 115 | " <Row>", |
| 116 | " <Data Id=\"Column1\" Value=\"Some value\" />", |
| 117 | " </Row>", |
| 118 | " </CustomTable>", |
| 119 | " </Fragment>", |
| 120 | "</Wix>" |
| 121 | }; |
| 122 | |
| 123 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 124 | |
| 125 | var messaging = new MockMessaging(); |
| 126 | var converter = new WixConverter(messaging, 2, null, null); |
| 127 | |
| 128 | var errors = converter.ConvertDocument(document); |
| 129 | Assert.Equal(3, errors); |
| 130 | |
| 131 | var actualLines = UnformattedDocumentLines(document); |
| 132 | WixAssert.CompareLineByLine(expected, actualLines); |
| 133 | } |
| 134 | |
| 135 | [Fact] |
| 136 | public void FixCustomRowWithoutValue() |
| 137 | { |
| 138 | var parse = String.Join(Environment.NewLine, |
| 139 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 140 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 141 | " <Fragment>", |
| 142 | " <CustomTable Id='Custom1'>", |
| 143 | " <Row Id='Column1'></Row>", |
| 144 | " </CustomTable>", |
| 145 | " </Fragment>", |
| 146 | "</Wix>"); |
| 147 | |
| 148 | var expected = new[] |
| 149 | { |
| 150 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 151 | " <Fragment>", |
| 152 | " <CustomTable Id=\"Custom1\">", |
| 153 | " <Row Id=\"Column1\"></Row>", |
| 154 | " </CustomTable>", |
| 155 | " </Fragment>", |
| 156 | "</Wix>" |
| 157 | }; |
| 158 | |
| 159 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 160 | |
| 161 | var messaging = new MockMessaging(); |
| 162 | var converter = new WixConverter(messaging, 2, null, null); |
| 163 | |
| 164 | var errors = converter.ConvertDocument(document); |
| 165 | Assert.Equal(3, errors); |
| 166 | |
| 167 | var actualLines = UnformattedDocumentLines(document); |
| 168 | WixAssert.CompareLineByLine(expected, actualLines); |
| 169 | } |
| 170 | |
| 171 | [Fact] |
| 172 | public void CanConvertBundleCustomTableBootstrapperApplicationData() |
| 173 | { |
| 174 | var parse = String.Join(Environment.NewLine, |
| 175 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 176 | " <CustomTable Id='FgAppx' BootstrapperApplicationData='yes'>", |
| 177 | " <Column Id='Column1' PrimaryKey='yes' Type='string' Width='0' Category='text' Description='The first custom column.' />", |
| 178 | " <Row>", |
| 179 | " <Data Column='Column1'>Row1</Data>", |
| 180 | " </Row>", |
| 181 | " </CustomTable>", |
| 182 | "</Wix>"); |
| 183 | |
| 184 | var expected = new[] |
| 185 | { |
| 186 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 187 | " <BundleCustomData Id=\"FgAppx\">", |
| 188 | " <BundleAttributeDefinition Id=\"Column1\" />", |
| 189 | " <BundleElement>", |
| 190 | " <BundleAttribute Id=\"Column1\" Value=\"Row1\" />", |
| 191 | " </BundleElement>", |
| 192 | " </BundleCustomData>", |
| 193 | "</Wix>", |
| 194 | }; |
| 195 | |
| 196 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 197 | |
| 198 | var messaging = new MockMessaging(); |
| 199 | var converter = new WixConverter(messaging, 2, customTableTarget: CustomTableTarget.Bundle); |
| 200 | |
| 201 | var errors = converter.ConvertDocument(document); |
| 202 | |
| 203 | var actual = UnformattedDocumentLines(document); |
| 204 | |
| 205 | Assert.Equal(2, errors); |
| 206 | WixAssert.CompareLineByLine(expected, actual); |
| 207 | } |
| 208 | |
| 209 | [Fact] |
| 210 | public void CanConvertBundleCustomTableRef() |
| 211 | { |
| 212 | var parse = String.Join(Environment.NewLine, |
| 213 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 214 | " <CustomTable Id='FgAppx'>", |
| 215 | " <Row>", |
| 216 | " <Data Column='Column1'>Row1</Data>", |
| 217 | " </Row>", |
| 218 | " </CustomTable>", |
| 219 | "</Wix>"); |
| 220 | |
| 221 | var expected = new[] |
| 222 | { |
| 223 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 224 | " <BundleCustomDataRef Id=\"FgAppx\">", |
| 225 | " <BundleElement>", |
| 226 | " <BundleAttribute Id=\"Column1\" Value=\"Row1\" />", |
| 227 | " </BundleElement>", |
| 228 | " </BundleCustomDataRef>", |
| 229 | "</Wix>", |
| 230 | }; |
| 231 | |
| 232 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 233 | |
| 234 | var messaging = new MockMessaging(); |
| 235 | var converter = new WixConverter(messaging, 2, customTableTarget: CustomTableTarget.Bundle); |
| 236 | |
| 237 | var errors = converter.ConvertDocument(document); |
| 238 | |
| 239 | var actual = UnformattedDocumentLines(document); |
| 240 | |
| 241 | Assert.Equal(2, errors); |
| 242 | WixAssert.CompareLineByLine(expected, actual); |
| 243 | } |
| 244 | |
| 245 | [Fact] |
| 246 | public void CanConvertMsiCustomTableBootstrapperApplicationData() |
| 247 | { |
| 248 | var parse = String.Join(Environment.NewLine, |
| 249 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 250 | " <CustomTable Id='FgAppx' BootstrapperApplicationData='yes'>", |
| 251 | " <Column Id='Column1' PrimaryKey='yes' Type='string' Width='0' Category='text' Description='The first custom column.' />", |
| 252 | " <Row>", |
| 253 | " <Data Column='Column1'>Row1</Data>", |
| 254 | " </Row>", |
| 255 | " </CustomTable>", |
| 256 | "</Wix>"); |
| 257 | |
| 258 | var expected = new[] |
| 259 | { |
| 260 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 261 | " <CustomTable Id=\"FgAppx\" Unreal=\"yes\">", |
| 262 | " <Column Id=\"Column1\" PrimaryKey=\"yes\" Type=\"string\" Width=\"0\" Category=\"text\" Description=\"The first custom column.\" />", |
| 263 | " <Row>", |
| 264 | " <Data Column=\"Column1\" Value=\"Row1\" />", |
| 265 | " </Row>", |
| 266 | " </CustomTable>", |
| 267 | "</Wix>", |
| 268 | }; |
| 269 | |
| 270 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 271 | |
| 272 | var messaging = new MockMessaging(); |
| 273 | var converter = new WixConverter(messaging, 2, customTableTarget: CustomTableTarget.Msi); |
| 274 | |
| 275 | var errors = converter.ConvertDocument(document); |
| 276 | |
| 277 | var actual = UnformattedDocumentLines(document); |
| 278 | |
| 279 | Assert.Equal(2, errors); |
| 280 | WixAssert.CompareLineByLine(expected, actual); |
| 281 | } |
| 282 | |
| 283 | [Fact] |
| 284 | public void CanConvertMsiCustomTableRef() |
| 285 | { |
| 286 | var parse = String.Join(Environment.NewLine, |
| 287 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 288 | " <CustomTable Id='FgAppx'>", |
| 289 | " <Row>", |
| 290 | " <Data Column='Column1'>Row1</Data>", |
| 291 | " </Row>", |
| 292 | " </CustomTable>", |
| 293 | "</Wix>"); |
| 294 | |
| 295 | var expected = new[] |
| 296 | { |
| 297 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 298 | " <CustomTableRef Id=\"FgAppx\">", |
| 299 | " <Row>", |
| 300 | " <Data Column=\"Column1\" Value=\"Row1\" />", |
| 301 | " </Row>", |
| 302 | " </CustomTableRef>", |
| 303 | "</Wix>", |
| 304 | }; |
| 305 | |
| 306 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 307 | |
| 308 | var messaging = new MockMessaging(); |
| 309 | var converter = new WixConverter(messaging, 2, customTableTarget: CustomTableTarget.Msi); |
| 310 | |
| 311 | var errors = converter.ConvertDocument(document); |
| 312 | |
| 313 | var actual = UnformattedDocumentLines(document); |
| 314 | |
| 315 | Assert.Equal(2, errors); |
| 316 | WixAssert.CompareLineByLine(expected, actual); |
| 317 | } |
| 318 | |
| 319 | [Fact] |
| 320 | public void CanDetectAmbiguousCustomTableBootstrapperApplicationData() |
| 321 | { |
| 322 | var parse = String.Join(Environment.NewLine, |
| 323 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 324 | " <CustomTable Id='FgAppx' BootstrapperApplicationData='yes' />", |
| 325 | "</Wix>"); |
| 326 | |
| 327 | var expected = new[] |
| 328 | { |
| 329 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 330 | " <CustomTable Id=\"FgAppx\" BootstrapperApplicationData=\"yes\" />", |
| 331 | "</Wix>", |
| 332 | }; |
| 333 | |
| 334 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 335 | |
| 336 | var messaging = new MockMessaging(); |
| 337 | var converter = new WixConverter(messaging, 2); |
| 338 | |
| 339 | var errors = converter.ConvertDocument(document); |
| 340 | |
| 341 | var actual = UnformattedDocumentLines(document); |
| 342 | |
| 343 | Assert.Equal(1, errors); |
| 344 | WixAssert.CompareLineByLine(expected, actual); |
| 345 | } |
| 346 | |
| 347 | [Fact] |
| 348 | public void CanRemoveBootstrapperApplicationDataFromRealCustomTable() |
| 349 | { |
| 350 | var parse = String.Join(Environment.NewLine, |
| 351 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 352 | " <CustomTable Id='FgAppx' BootstrapperApplicationData='no' />", |
| 353 | "</Wix>"); |
| 354 | |
| 355 | var expected = new[] |
| 356 | { |
| 357 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 358 | " <CustomTable Id=\"FgAppx\" />", |
| 359 | "</Wix>", |
| 360 | }; |
| 361 | |
| 362 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 363 | |
| 364 | var messaging = new MockMessaging(); |
| 365 | var converter = new WixConverter(messaging, 2); |
| 366 | |
| 367 | var errors = converter.ConvertDocument(document); |
| 368 | |
| 369 | var actual = UnformattedDocumentLines(document); |
| 370 | |
| 371 | Assert.Equal(1, errors); |
| 372 | WixAssert.CompareLineByLine(expected, actual); |
| 373 | } |
| 374 | } |
| 375 | } |