| 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 FeatureFixture : BaseConverterFixture |
| 13 | { |
| 14 | [Fact] |
| 15 | public void FixAllowAttributes() |
| 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 | " <Feature Absent='allow' AllowAdvertise='system' />", |
| 22 | " </Fragment>", |
| 23 | "</Wix>"); |
| 24 | |
| 25 | var expected = new[] |
| 26 | { |
| 27 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 28 | " <Fragment>", |
| 29 | " <Feature AllowAdvertise=\"yes\" />", |
| 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(4, errors); |
| 41 | |
| 42 | var actualLines = UnformattedDocumentLines(document); |
| 43 | WixAssert.CompareLineByLine(expected, actualLines); |
| 44 | } |
| 45 | |
| 46 | [Fact] |
| 47 | public void FixDisallowAttributes() |
| 48 | { |
| 49 | var parse = String.Join(Environment.NewLine, |
| 50 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 51 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 52 | " <Fragment>", |
| 53 | " <Feature Absent='disallow' AllowAdvertise='no' />", |
| 54 | " </Fragment>", |
| 55 | "</Wix>"); |
| 56 | |
| 57 | var expected = new[] |
| 58 | { |
| 59 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 60 | " <Fragment>", |
| 61 | " <Feature AllowAdvertise=\"no\" AllowAbsent=\"no\" />", |
| 62 | " </Fragment>", |
| 63 | "</Wix>" |
| 64 | }; |
| 65 | |
| 66 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 67 | |
| 68 | var messaging = new MockMessaging(); |
| 69 | var converter = new WixConverter(messaging, 2, null, null); |
| 70 | |
| 71 | var errors = converter.ConvertDocument(document); |
| 72 | Assert.Equal(3, errors); |
| 73 | |
| 74 | var actualLines = UnformattedDocumentLines(document); |
| 75 | WixAssert.CompareLineByLine(expected, actualLines); |
| 76 | } |
| 77 | |
| 78 | [Fact] |
| 79 | public void RemoveDeprecatedAllowAdvertiseAttributes() |
| 80 | { |
| 81 | var parse = String.Join(Environment.NewLine, |
| 82 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 83 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 84 | " <Fragment>", |
| 85 | " <Feature AllowAdvertise='disallow' />", |
| 86 | " </Fragment>", |
| 87 | "</Wix>"); |
| 88 | |
| 89 | var expected = new[] |
| 90 | { |
| 91 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 92 | " <Fragment>", |
| 93 | " <Feature />", |
| 94 | " </Fragment>", |
| 95 | "</Wix>" |
| 96 | }; |
| 97 | |
| 98 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 99 | |
| 100 | var messaging = new MockMessaging(); |
| 101 | var converter = new WixConverter(messaging, 2, null, null); |
| 102 | |
| 103 | var errors = converter.ConvertDocument(document); |
| 104 | Assert.Equal(3, errors); |
| 105 | |
| 106 | var actualLines = UnformattedDocumentLines(document); |
| 107 | WixAssert.CompareLineByLine(expected, actualLines); |
| 108 | } |
| 109 | } |
| 110 | } |