| 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 LocalizationFixture : BaseConverterFixture |
| 13 | { |
| 14 | [Fact] |
| 15 | public void EnsureNoXmlDeclaration() |
| 16 | { |
| 17 | var parse = String.Join(Environment.NewLine, |
| 18 | "<?xml version='1.0' ?>", |
| 19 | "<WixLocalization Culture='en-us'>", |
| 20 | " <String Id='SomeId'>Value</String>", |
| 21 | "</WixLocalization>"); |
| 22 | |
| 23 | var expected = new[] |
| 24 | { |
| 25 | "<WixLocalization Culture=\"en-us\" xmlns=\"http://wixtoolset.org/schemas/v4/wxl\">", |
| 26 | " <String Id=\"SomeId\" Value=\"Value\" />", |
| 27 | "</WixLocalization>" |
| 28 | }; |
| 29 | |
| 30 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 31 | |
| 32 | var messaging = new MockMessaging(); |
| 33 | var converter = new WixConverter(messaging, 2, null, null); |
| 34 | |
| 35 | var errors = converter.ConvertDocument(document); |
| 36 | Assert.Equal(3, errors); |
| 37 | |
| 38 | var actualLines = UnformattedDocumentLines(document); |
| 39 | WixAssert.CompareLineByLine(expected, actualLines); |
| 40 | } |
| 41 | |
| 42 | [Fact] |
| 43 | public void EnsureNamespace() |
| 44 | { |
| 45 | var parse = String.Join(Environment.NewLine, |
| 46 | "<WixLocalization Culture='en-us'>", |
| 47 | " <String Id='SomeId'>Value</String>", |
| 48 | "</WixLocalization>"); |
| 49 | |
| 50 | var expected = new[] |
| 51 | { |
| 52 | "<WixLocalization Culture=\"en-us\" xmlns=\"http://wixtoolset.org/schemas/v4/wxl\">", |
| 53 | " <String Id=\"SomeId\" Value=\"Value\" />", |
| 54 | "</WixLocalization>" |
| 55 | }; |
| 56 | |
| 57 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 58 | |
| 59 | var messaging = new MockMessaging(); |
| 60 | var converter = new WixConverter(messaging, 2, null, null); |
| 61 | |
| 62 | var errors = converter.ConvertDocument(document); |
| 63 | Assert.Equal(2, errors); |
| 64 | |
| 65 | var actualLines = UnformattedDocumentLines(document); |
| 66 | WixAssert.CompareLineByLine(expected, actualLines); |
| 67 | } |
| 68 | |
| 69 | [Fact] |
| 70 | public void FixNamespace() |
| 71 | { |
| 72 | var parse = String.Join(Environment.NewLine, |
| 73 | "<WixLocalization Culture='en-us' xmlns='http://schemas.microsoft.com/wix/2006/localization'>", |
| 74 | " <String Id='SomeId'>Value</String>", |
| 75 | "</WixLocalization>"); |
| 76 | |
| 77 | var expected = new[] |
| 78 | { |
| 79 | "<WixLocalization Culture=\"en-us\" xmlns=\"http://wixtoolset.org/schemas/v4/wxl\">", |
| 80 | " <String Id=\"SomeId\" Value=\"Value\" />", |
| 81 | "</WixLocalization>" |
| 82 | }; |
| 83 | |
| 84 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 85 | |
| 86 | var messaging = new MockMessaging(); |
| 87 | var converter = new WixConverter(messaging, 2, null, null); |
| 88 | |
| 89 | var errors = converter.ConvertDocument(document); |
| 90 | Assert.Equal(2, errors); |
| 91 | |
| 92 | var actualLines = UnformattedDocumentLines(document); |
| 93 | WixAssert.CompareLineByLine(expected, actualLines); |
| 94 | } |
| 95 | |
| 96 | [Fact] |
| 97 | public void FixStringTextWithComment() |
| 98 | { |
| 99 | var parse = String.Join(Environment.NewLine, |
| 100 | "<WixLocalization Culture='en-us' xmlns='http://wixtoolset.org/schemas/v4/wxl'>", |
| 101 | " <String Id='SomeId'><!-- Comment -->Value</String>", |
| 102 | "</WixLocalization>"); |
| 103 | |
| 104 | var expected = new[] |
| 105 | { |
| 106 | "<WixLocalization Culture=\"en-us\" xmlns=\"http://wixtoolset.org/schemas/v4/wxl\">", |
| 107 | " <!-- Comment -->", |
| 108 | " <String Id=\"SomeId\" Value=\"Value\" />", |
| 109 | "</WixLocalization>" |
| 110 | }; |
| 111 | |
| 112 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 113 | |
| 114 | var messaging = new MockMessaging(); |
| 115 | var converter = new WixConverter(messaging, 2, null, null); |
| 116 | |
| 117 | var errors = converter.ConvertDocument(document); |
| 118 | Assert.Equal(1, errors); |
| 119 | |
| 120 | var actualLines = UnformattedDocumentLines(document); |
| 121 | WixAssert.CompareLineByLine(expected, actualLines); |
| 122 | } |
| 123 | |
| 124 | [Fact] |
| 125 | public void FixUILocalization() |
| 126 | { |
| 127 | var parse = String.Join(Environment.NewLine, |
| 128 | "<WixLocalization Culture='en-us' xmlns='http://wixtoolset.org/schemas/v4/wxl'>", |
| 129 | " <UI Dialog='DialogId' Control='ControlId' X='1' Y='2'>Some text</UI>", |
| 130 | "</WixLocalization>"); |
| 131 | |
| 132 | var expected = new[] |
| 133 | { |
| 134 | "<WixLocalization Culture=\"en-us\" xmlns=\"http://wixtoolset.org/schemas/v4/wxl\">", |
| 135 | " <UI Dialog=\"DialogId\" Control=\"ControlId\" X=\"1\" Y=\"2\" Text=\"Some text\" />", |
| 136 | "</WixLocalization>" |
| 137 | }; |
| 138 | |
| 139 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 140 | |
| 141 | var messaging = new MockMessaging(); |
| 142 | var converter = new WixConverter(messaging, 2, null, null); |
| 143 | |
| 144 | var errors = converter.ConvertDocument(document); |
| 145 | Assert.Equal(1, errors); |
| 146 | |
| 147 | var actualLines = UnformattedDocumentLines(document); |
| 148 | WixAssert.CompareLineByLine(expected, actualLines); |
| 149 | } |
| 150 | } |
| 151 | } |