| 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 VariableFixture : BaseConverterFixture |
| 13 | { |
| 14 | [Fact] |
| 15 | public void FixFormattedType() |
| 16 | { |
| 17 | var parse = String.Join(Environment.NewLine, |
| 18 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 19 | " <Fragment>", |
| 20 | " <Variable Name='ExplicitString' Type='string' Value='explicit' />", |
| 21 | " <Variable Name='ImplicitNumber' Value='42' />", |
| 22 | " <Variable Name='ImplicitString' Value='implicit' />", |
| 23 | " <Variable Name='ImplicitVersion' Value='v2' />", |
| 24 | " <Variable Name='NoTypeOrValue' />", |
| 25 | " </Fragment>", |
| 26 | "</Wix>"); |
| 27 | |
| 28 | var expected = new[] |
| 29 | { |
| 30 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 31 | " <Fragment>", |
| 32 | " <Variable Name=\"ExplicitString\" Type=\"formatted\" Value=\"explicit\" />", |
| 33 | " <Variable Name=\"ImplicitNumber\" Value=\"42\" />", |
| 34 | " <Variable Name=\"ImplicitString\" Value=\"implicit\" Type=\"formatted\" />", |
| 35 | " <Variable Name=\"ImplicitVersion\" Value=\"v2\" />", |
| 36 | " <Variable Name=\"NoTypeOrValue\" />", |
| 37 | " </Fragment>", |
| 38 | "</Wix>" |
| 39 | }; |
| 40 | |
| 41 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 42 | |
| 43 | var messaging = new MockMessaging(); |
| 44 | var converter = new WixConverter(messaging, 2, null, null); |
| 45 | |
| 46 | var errors = converter.ConvertDocument(document); |
| 47 | Assert.Equal(3, errors); |
| 48 | |
| 49 | var actualLines = UnformattedDocumentLines(document); |
| 50 | WixAssert.CompareLineByLine(expected, actualLines); |
| 51 | } |
| 52 | |
| 53 | [Fact] |
| 54 | public void DoesntFixFormattedTypeFromV4() |
| 55 | { |
| 56 | var parse = String.Join(Environment.NewLine, |
| 57 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 58 | " <Fragment>", |
| 59 | " <Variable Name='ImplicitString' Value='implicit' />", |
| 60 | " <Variable Name='ExplicitString' Type='string' Value='explicit' />", |
| 61 | " </Fragment>", |
| 62 | "</Wix>"); |
| 63 | |
| 64 | var expected = new[] |
| 65 | { |
| 66 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 67 | " <Fragment>", |
| 68 | " <Variable Name=\"ImplicitString\" Value=\"implicit\" />", |
| 69 | " <Variable Name=\"ExplicitString\" Type=\"string\" Value=\"explicit\" />", |
| 70 | " </Fragment>", |
| 71 | "</Wix>" |
| 72 | }; |
| 73 | |
| 74 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 75 | |
| 76 | var messaging = new MockMessaging(); |
| 77 | var converter = new WixConverter(messaging, 2, null, null); |
| 78 | |
| 79 | var errors = converter.ConvertDocument(document); |
| 80 | Assert.Equal(0, errors); |
| 81 | |
| 82 | var actualLines = UnformattedDocumentLines(document); |
| 83 | WixAssert.CompareLineByLine(expected, actualLines); |
| 84 | } |
| 85 | } |
| 86 | } |