| 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 PrereqPackageFixture : BaseConverterFixture |
| 14 | { |
| 15 | [Fact] |
| 16 | public void CanConvertWixMbaPrereqPackageIdToPrereqPackage() |
| 17 | { |
| 18 | var parse = String.Join(Environment.NewLine, |
| 19 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs' xmlns:bal='http://wixtoolset.org/schemas/v4/wxs/bal'>", |
| 20 | " <Fragment>", |
| 21 | " <WixVariable Id='WixMbaPrereqPackageId' Value='NetFx452Web' />", |
| 22 | " <WixVariable Id='WixMbaPrereqLicenseUrl' Value='$(var.NetFx452EulaLink)' Overridable='yes' />", |
| 23 | " <PackageGroup Id='NetFx452Web'>", |
| 24 | " <ExePackage Id='NetFx452Web' />", |
| 25 | " </PackageGroup>", |
| 26 | " </Fragment>", |
| 27 | "</Wix>"); |
| 28 | |
| 29 | var expected = new[] |
| 30 | { |
| 31 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:bal=\"http://wixtoolset.org/schemas/v4/wxs/bal\">", |
| 32 | " <Fragment>", |
| 33 | " <PackageGroup Id=\"NetFx452Web\">", |
| 34 | " <ExePackage Id=\"NetFx452Web\" bal:PrereqPackage=\"yes\" bal:PrereqLicenseUrl=\"$(var.NetFx452EulaLink)\" />", |
| 35 | " </PackageGroup>", |
| 36 | " </Fragment>", |
| 37 | "</Wix>" |
| 38 | }; |
| 39 | |
| 40 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 41 | |
| 42 | var messaging = new MockMessaging(); |
| 43 | var converter = new WixConverter(messaging, 2, null, null); |
| 44 | |
| 45 | var errors = converter.ConvertDocument(document); |
| 46 | Assert.Equal(2, errors); |
| 47 | |
| 48 | var actualLines = UnformattedDocumentLines(document); |
| 49 | WixAssert.CompareLineByLine(new[] |
| 50 | { |
| 51 | "[Converted] The magic WixVariable 'WixMbaPrereqPackageId' has been removed. Add bal:PrereqPackage=\"yes\" to the target package instead. (WixMbaPrereqPackageIdDeprecated)", |
| 52 | "[Converted] The magic WixVariable 'WixMbaPrereqLicenseUrl' has been removed. Add bal:PrereqLicenseUrl=\"<url>\" to a prereq package instead. (WixMbaPrereqLicenseUrlDeprecated)", |
| 53 | }, messaging.Messages.Select(m => m.ToString()).ToArray()); |
| 54 | WixAssert.CompareLineByLine(expected, actualLines); |
| 55 | } |
| 56 | |
| 57 | [Fact] |
| 58 | public void CanWarnAboutOrphanWixMbaPrereqPackageId() |
| 59 | { |
| 60 | var parse = String.Join(Environment.NewLine, |
| 61 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 62 | " <Fragment>", |
| 63 | " <WixVariable Id='WixMbaPrereqPackageId' Value='NetFx452Web' />", |
| 64 | " <WixVariable Id='WixMbaPrereqLicenseUrl' Value='$(var.NetFx452EulaLink)' Overridable='yes' />", |
| 65 | " </Fragment>", |
| 66 | "</Wix>"); |
| 67 | |
| 68 | var expected = new[] |
| 69 | { |
| 70 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 71 | " <Fragment>", |
| 72 | " <WixVariable Id=\"WixMbaPrereqPackageId\" Value=\"NetFx452Web\" />", |
| 73 | " <WixVariable Id=\"WixMbaPrereqLicenseUrl\" Value=\"$(var.NetFx452EulaLink)\" Overridable=\"yes\" />", |
| 74 | " </Fragment>", |
| 75 | "</Wix>" |
| 76 | }; |
| 77 | |
| 78 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 79 | |
| 80 | var messaging = new MockMessaging(); |
| 81 | var converter = new WixConverter(messaging, 2, null, null); |
| 82 | |
| 83 | var errors = converter.ConvertDocument(document); |
| 84 | Assert.Equal(2, errors); |
| 85 | |
| 86 | var actualLines = UnformattedDocumentLines(document); |
| 87 | WixAssert.CompareLineByLine(new[] |
| 88 | { |
| 89 | "The magic WixVariable 'WixMbaPrereqPackageId' has been removed. Add bal:PrereqPackage=\"yes\" to the target package instead. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-bundles (WixMbaPrereqPackageIdDeprecated)", |
| 90 | "The magic WixVariable 'WixMbaPrereqLicenseUrl' has been removed. Add bal:PrereqLicenseUrl=\"<url>\" to a prereq package instead. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-bundles (WixMbaPrereqLicenseUrlDeprecated)", |
| 91 | }, messaging.Messages.Select(m => m.ToString()).ToArray()); |
| 92 | WixAssert.CompareLineByLine(expected, actualLines); |
| 93 | } |
| 94 | } |
| 95 | } |