| 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 UIExtensionFixture : BaseConverterFixture |
| 14 | { |
| 15 | [Fact] |
| 16 | public void FixUIRefs() |
| 17 | { |
| 18 | var parse = String.Join(Environment.NewLine, |
| 19 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 20 | " <Fragment>", |
| 21 | " <UIRef Id=\"WixUI_Advanced\" />", |
| 22 | " <UIRef Id=\"WixUI_FeatureTree\" />", |
| 23 | " <UIRef Id=\"WixUI_BobsSpecialUI\" />", |
| 24 | " <UI>", |
| 25 | " <UIRef Id=\"WixUI_Advanced\" />", |
| 26 | " <UIRef Id=\"WixUI_FeatureTree\" />", |
| 27 | " <UIRef Id=\"WixUI_BobsSpecialUI\" />", |
| 28 | " </UI>", |
| 29 | " </Fragment>", |
| 30 | "</Wix>"); |
| 31 | |
| 32 | var expected = new[] |
| 33 | { |
| 34 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:ui=\"http://wixtoolset.org/schemas/v4/wxs/ui\">", |
| 35 | " <Fragment>", |
| 36 | " <ui:WixUI Id=\"WixUI_Advanced\" />", |
| 37 | " <ui:WixUI Id=\"WixUI_FeatureTree\" />", |
| 38 | " <UIRef Id=\"WixUI_BobsSpecialUI\" />", |
| 39 | " <UI>", |
| 40 | " <ui:WixUI Id=\"WixUI_Advanced\" />", |
| 41 | " <ui:WixUI Id=\"WixUI_FeatureTree\" />", |
| 42 | " <UIRef Id=\"WixUI_BobsSpecialUI\" />", |
| 43 | " </UI>", |
| 44 | " </Fragment>", |
| 45 | "</Wix>" |
| 46 | }; |
| 47 | |
| 48 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 49 | |
| 50 | var messaging = new MockMessaging(); |
| 51 | var converter = new WixConverter(messaging, 2, null, null); |
| 52 | |
| 53 | var errors = converter.ConvertDocument(document); |
| 54 | Assert.Equal(5, errors); |
| 55 | |
| 56 | var actualLines = UnformattedDocumentLines(document); |
| 57 | WixAssert.CompareLineByLine(expected, actualLines); |
| 58 | } |
| 59 | |
| 60 | [Fact] |
| 61 | public void RemovePrintCustomAction() |
| 62 | { |
| 63 | var parse = String.Join(Environment.NewLine, |
| 64 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 65 | " <Fragment>", |
| 66 | " <UI Id=\"WixUI_Advanced_$(WIXUIARCH)\">", |
| 67 | " <Publish Dialog=\"AdvancedWelcomeEulaDlg\" Control=\"Print\" Event=\"DoAction\" Value=\"WixUIPrintEula_$(WIXUIARCH)\" />", |
| 68 | " </UI>", |
| 69 | " </Fragment>", |
| 70 | "</Wix>"); |
| 71 | |
| 72 | var expected = new[] |
| 73 | { |
| 74 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 75 | " <Fragment>", |
| 76 | " <UI Id=\"WixUI_Advanced_$(WIXUIARCH)\">", |
| 77 | " ", |
| 78 | " </UI>", |
| 79 | " </Fragment>", |
| 80 | "</Wix>" |
| 81 | }; |
| 82 | |
| 83 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 84 | |
| 85 | var messaging = new MockMessaging(); |
| 86 | var converter = new WixConverter(messaging, 2, null, null); |
| 87 | |
| 88 | var errors = converter.ConvertDocument(document); |
| 89 | |
| 90 | var actual = UnformattedDocumentLines(document); |
| 91 | |
| 92 | WixAssert.CompareLineByLine(expected, actual); |
| 93 | Assert.Equal(2, errors); |
| 94 | } |
| 95 | |
| 96 | [Fact] |
| 97 | public void FixValidatePathCustomAction() |
| 98 | { |
| 99 | var parse = String.Join(Environment.NewLine, |
| 100 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 101 | " <Fragment>", |
| 102 | " <UI Id='WixUI_Test'>", |
| 103 | " <Publish Dialog='BrowseDlg' Control='OK' Event='DoAction' Value='WixUIValidatePath' Order='3' />", |
| 104 | " </UI>", |
| 105 | " </Fragment>", |
| 106 | "</Wix>"); |
| 107 | |
| 108 | var expected = new[] |
| 109 | { |
| 110 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 111 | " <Fragment>", |
| 112 | " <UI Id=\"WixUI_Test\">", |
| 113 | " <Publish Dialog=\"BrowseDlg\" Control=\"OK\" Event=\"DoAction\" Value=\"WixUIValidatePath_$(sys.BUILDARCHSHORT)\" Order=\"3\" />", |
| 114 | " </UI>", |
| 115 | " </Fragment>", |
| 116 | "</Wix>", |
| 117 | }; |
| 118 | |
| 119 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 120 | |
| 121 | var messaging = new MockMessaging(); |
| 122 | var converter = new WixConverter(messaging, 2, null, null); |
| 123 | |
| 124 | var errors = converter.ConvertDocument(document); |
| 125 | |
| 126 | var actual = UnformattedDocumentLines(document); |
| 127 | |
| 128 | WixAssert.CompareLineByLine(expected, actual); |
| 129 | Assert.Single(messaging.Messages.Where(m => m.Id == 65)); |
| 130 | Assert.Equal(2, errors); |
| 131 | } |
| 132 | } |
| 133 | } |