| 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 FirewallExtensionFixture : BaseConverterFixture |
| 14 | { |
| 15 | [Fact] |
| 16 | public void FixRemoteAddressValue() |
| 17 | { |
| 18 | var parse = String.Join(Environment.NewLine, |
| 19 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:fw='http://schemas.microsoft.com/wix/FirewallExtension'>", |
| 20 | " <Fragment>", |
| 21 | " <fw:RemoteAddress>", |
| 22 | " 127.0.0.1", |
| 23 | " </fw:RemoteAddress>", |
| 24 | " </Fragment>", |
| 25 | "</Wix>"); |
| 26 | |
| 27 | var expected = new[] |
| 28 | { |
| 29 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:fw=\"http://wixtoolset.org/schemas/v4/wxs/firewall\">", |
| 30 | " <Fragment>", |
| 31 | " <fw:RemoteAddress Value=\"127.0.0.1\" />", |
| 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 | Assert.Equal(3, errors); |
| 43 | |
| 44 | var actualLines = UnformattedDocumentLines(document); |
| 45 | WixAssert.CompareLineByLine(expected, actualLines); |
| 46 | } |
| 47 | |
| 48 | [Fact] |
| 49 | public void FixNamespacePlacement() |
| 50 | { |
| 51 | var parse = String.Join(Environment.NewLine, |
| 52 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 53 | " <Fragment>", |
| 54 | " <RemoteAddress xmlns='http://schemas.microsoft.com/wix/FirewallExtension'>", |
| 55 | " 127.0.0.1", |
| 56 | " </RemoteAddress>", |
| 57 | " </Fragment>", |
| 58 | "</Wix>"); |
| 59 | |
| 60 | var expected = new[] |
| 61 | { |
| 62 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:fw=\"http://wixtoolset.org/schemas/v4/wxs/firewall\">", |
| 63 | " <Fragment>", |
| 64 | " <fw:RemoteAddress Value=\"127.0.0.1\" />", |
| 65 | " </Fragment>", |
| 66 | "</Wix>" |
| 67 | }; |
| 68 | |
| 69 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 70 | |
| 71 | var messaging = new MockMessaging(); |
| 72 | var converter = new WixConverter(messaging, 2, null, null); |
| 73 | |
| 74 | var errors = converter.ConvertDocument(document); |
| 75 | WixAssert.CompareLineByLine(new[] |
| 76 | { |
| 77 | "[Converted] The namespace 'http://schemas.microsoft.com/wix/2006/wi' is out of date. It must be 'http://wixtoolset.org/schemas/v4/wxs'. (XmlnsValueWrong)", |
| 78 | "[Converted] The namespace 'http://schemas.microsoft.com/wix/FirewallExtension' is out of date. It must be 'http://wixtoolset.org/schemas/v4/wxs/firewall'. (XmlnsValueWrong)", |
| 79 | "[Converted] Using RemoteAddress element text is deprecated. Use the 'Value' attribute instead. (InnerTextDeprecated)", |
| 80 | "[Converted] Namespace should be defined on the root. The 'http://wixtoolset.org/schemas/v4/wxs/firewall' namespace was move to the root element. (MoveNamespacesToRoot)" |
| 81 | }, messaging.Messages.Select(m => m.ToString()).ToArray()); |
| 82 | Assert.Equal(4, errors); |
| 83 | |
| 84 | var actualLines = UnformattedDocumentLines(document); |
| 85 | WixAssert.CompareLineByLine(expected, actualLines); |
| 86 | } |
| 87 | |
| 88 | [Fact] |
| 89 | public void FixNamespacePlacementWhenItExists() |
| 90 | { |
| 91 | //xmlns:abc='http://schemas.microsoft.com/wix/FirewallExtension' |
| 92 | var parse = String.Join(Environment.NewLine, |
| 93 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 94 | " <Fragment>", |
| 95 | " <RemoteAddress xmlns='http://schemas.microsoft.com/wix/FirewallExtension'>", |
| 96 | " 127.0.0.1", |
| 97 | " </RemoteAddress>", |
| 98 | " </Fragment>", |
| 99 | "</Wix>"); |
| 100 | |
| 101 | var expected = new[] |
| 102 | { |
| 103 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:fw=\"http://wixtoolset.org/schemas/v4/wxs/firewall\">", |
| 104 | " <Fragment>", |
| 105 | " <fw:RemoteAddress Value=\"127.0.0.1\" />", |
| 106 | " </Fragment>", |
| 107 | "</Wix>" |
| 108 | }; |
| 109 | |
| 110 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 111 | |
| 112 | var messaging = new MockMessaging(); |
| 113 | var converter = new WixConverter(messaging, 2, null, null); |
| 114 | |
| 115 | var errors = converter.ConvertDocument(document); |
| 116 | WixAssert.CompareLineByLine(new[] |
| 117 | { |
| 118 | "[Converted] The namespace 'http://schemas.microsoft.com/wix/2006/wi' is out of date. It must be 'http://wixtoolset.org/schemas/v4/wxs'. (XmlnsValueWrong)", |
| 119 | "[Converted] The namespace 'http://schemas.microsoft.com/wix/FirewallExtension' is out of date. It must be 'http://wixtoolset.org/schemas/v4/wxs/firewall'. (XmlnsValueWrong)", |
| 120 | "[Converted] Using RemoteAddress element text is deprecated. Use the 'Value' attribute instead. (InnerTextDeprecated)", |
| 121 | "[Converted] Namespace should be defined on the root. The 'http://wixtoolset.org/schemas/v4/wxs/firewall' namespace was move to the root element. (MoveNamespacesToRoot)" |
| 122 | }, messaging.Messages.Select(m => m.ToString()).ToArray()); |
| 123 | Assert.Equal(4, errors); |
| 124 | |
| 125 | var actualLines = UnformattedDocumentLines(document); |
| 126 | WixAssert.CompareLineByLine(expected, actualLines); |
| 127 | } |
| 128 | } |
| 129 | } |