main
cs 333 lines 15.6 KB
Raw
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 DirectoryFixture : BaseConverterFixture
14 {
15 [Fact]
16 public void RemoveTargetDir()
17 {
18 var parse = String.Join(Environment.NewLine,
19 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
20 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
21 " <Fragment>",
22 " <Directory Id='TARGETDIR' Name='SourceDir'>",
23 " <!-- Comment -->",
24 " <Directory Id='RootFolder' Name='Root'>",
25 " <Directory Id='ChildFolder' Name='Child' />",
26 " </Directory>",
27 " </Directory>",
28 " </Fragment>",
29 "</Wix>");
30
31 var expected = new[]
32 {
33 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
34 " <Fragment>",
35 " <!-- Comment -->",
36 " <Directory Id=\"RootFolder\" Name=\"Root\">",
37 " <Directory Id=\"ChildFolder\" Name=\"Child\" />",
38 " </Directory>",
39 " </Fragment>",
40 "</Wix>"
41 };
42
43 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
44
45 var messaging = new MockMessaging();
46 var converter = new WixConverter(messaging, 2, null, null);
47
48 var errors = converter.ConvertDocument(document);
49
50 var actualLines = UnformattedDocumentLines(document);
51 WixAssert.CompareLineByLine(expected, actualLines);
52 Assert.Equal(3, errors);
53 }
54
55 [Fact]
56 public void RemoveTargetDirRef()
57 {
58 var parse = String.Join(Environment.NewLine,
59 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
60 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
61 " <Fragment>",
62 " <DirectoryRef Id='TARGETDIR'>",
63 " <!-- Comment -->",
64 " <Directory Id='RootFolder' Name='Root'>",
65 " <Directory Id='ChildFolder' Name='Child' />",
66 " </Directory>",
67 " </DirectoryRef>",
68 " </Fragment>",
69 "</Wix>");
70
71 var expected = new[]
72 {
73 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
74 " <Fragment>",
75 " <!-- Comment -->",
76 " <Directory Id=\"RootFolder\" Name=\"Root\">",
77 " <Directory Id=\"ChildFolder\" Name=\"Child\" />",
78 " </Directory>",
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 actualLines = UnformattedDocumentLines(document);
91 WixAssert.CompareLineByLine(expected, actualLines);
92 WixAssert.CompareLineByLine(new[]
93 {
94 "[Converted] This file contains an XML declaration on the first line. (DeclarationPresent)",
95 "[Converted] The namespace 'http://schemas.microsoft.com/wix/2006/wi' is out of date. It must be 'http://wixtoolset.org/schemas/v4/wxs'. (XmlnsValueWrong)",
96 "[Converted] The TARGETDIR directory should no longer be explicitly referenced. Remove the DirectoryRef element with Id attribute 'TARGETDIR'. (StandardDirectoryRefDeprecated)",
97 "A reference to the TARGETDIR Directory was removed. This can cause unintended side effects. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages (TargetDirRefRemoved)",
98 }, messaging.Messages.Select(m => m.ToString()).ToArray());
99 Assert.Equal(4, errors);
100 }
101
102 [Fact]
103 public void FixStandardDirectory()
104 {
105 var parse = String.Join(Environment.NewLine,
106 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
107 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
108 " <Fragment>",
109 " <Directory Id='TARGETDIR' Name='SourceDir'>",
110 " <Directory Id='ProgramFilesFolder' Name='PFiles'>",
111 " <Directory Id='ChildFolder' Name='Child' />",
112 " </Directory>",
113 " </Directory>",
114 " </Fragment>",
115 "</Wix>");
116
117 var expected = new[]
118 {
119 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
120 " <Fragment>",
121 " <StandardDirectory Id=\"ProgramFilesFolder\">",
122 " <Directory Id=\"ChildFolder\" Name=\"Child\" />",
123 " </StandardDirectory>",
124 " </Fragment>",
125 "</Wix>"
126 };
127
128 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
129
130 var messaging = new MockMessaging();
131 var converter = new WixConverter(messaging, 2, null, null);
132
133 var errors = converter.ConvertDocument(document);
134
135 var actualLines = UnformattedDocumentLines(document);
136 WixAssert.CompareLineByLine(expected, actualLines);
137 Assert.Equal(4, errors);
138 }
139
140 [Fact]
141 public void FixStandardDirectoryRef()
142 {
143 var parse = String.Join(Environment.NewLine,
144 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
145 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
146 " <Fragment>",
147 " <DirectoryRef Id='ProgramFilesFolder'>",
148 " <Directory Id='ChildFolder' Name='Child' />",
149 " </DirectoryRef>",
150 " </Fragment>",
151 "</Wix>");
152
153 var expected = new[]
154 {
155 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
156 " <Fragment>",
157 " <StandardDirectory Id=\"ProgramFilesFolder\">",
158 " <Directory Id=\"ChildFolder\" Name=\"Child\" />",
159 " </StandardDirectory>",
160 " </Fragment>",
161 "</Wix>"
162 };
163
164 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
165
166 var messaging = new MockMessaging();
167 var converter = new WixConverter(messaging, 2, null, null);
168
169 var errors = converter.ConvertDocument(document);
170
171 var actualLines = UnformattedDocumentLines(document);
172 WixAssert.CompareLineByLine(expected, actualLines);
173 Assert.Equal(3, errors);
174 }
175
176 [Fact]
177 public void RemoveTargetDirRefAndFixStandardDirectory()
178 {
179 var parse = String.Join(Environment.NewLine,
180 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
181 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
182 " <Fragment>",
183 " <DirectoryRef Id='TARGETDIR'>",
184 " <Directory Id='ProgramFilesFolder' Name='PFiles'>",
185 " <Directory Id='ChildFolder' Name='Child' />",
186 " </Directory>",
187 " </DirectoryRef>",
188 " </Fragment>",
189 "</Wix>");
190
191 var expected = new[]
192 {
193 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
194 " <Fragment>",
195 " <StandardDirectory Id=\"ProgramFilesFolder\">",
196 " <Directory Id=\"ChildFolder\" Name=\"Child\" />",
197 " </StandardDirectory>",
198 " </Fragment>",
199 "</Wix>"
200 };
201
202 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
203
204 var messaging = new MockMessaging();
205 var converter = new WixConverter(messaging, 2, null, null);
206
207 var errors = converter.ConvertDocument(document);
208
209 var actualLines = UnformattedDocumentLines(document);
210 WixAssert.CompareLineByLine(expected, actualLines);
211 Assert.Equal(5, errors);
212 }
213
214 [Fact]
215 public void RemoveTargetDirWithComponents()
216 {
217 var parse = String.Join(Environment.NewLine,
218 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
219 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
220 " <Fragment>",
221 " <DirectoryRef Id='TARGETDIR'>",
222 " <Component Id='C1'>",
223 " <File Source='c1.txt' />",
224 " </Component>",
225 " <Component Id='C2'>",
226 " <File Source='c2.txt' />",
227 " </Component>",
228 " </DirectoryRef>",
229 " </Fragment>",
230 " <Fragment>",
231 " <Directory Id='TARGETDIR'>",
232 " <Component Id='C3'>",
233 " <File Source='c3.txt' />",
234 " </Component>",
235 " <Component Id='C4' Directory='PreExisting'>",
236 " <File Source='c4.txt' />",
237 " </Component>",
238 " </Directory>",
239 " </Fragment>",
240 "</Wix>");
241
242 var expected = new[]
243 {
244 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
245 " <Fragment>",
246 " <Component Id=\"C1\" Directory=\"TARGETDIR\">",
247 " <File Id=\"c1.txt\" Source=\"c1.txt\" />",
248 " </Component>",
249 " <Component Id=\"C2\" Directory=\"TARGETDIR\">",
250 " <File Id=\"c2.txt\" Source=\"c2.txt\" />",
251 " </Component>",
252 " </Fragment>",
253 " <Fragment>",
254 " <Component Id=\"C3\" Directory=\"TARGETDIR\">",
255 " <File Id=\"c3.txt\" Source=\"c3.txt\" />",
256 " </Component>",
257 " <Component Id=\"C4\" Directory=\"PreExisting\">",
258 " <File Id=\"c4.txt\" Source=\"c4.txt\" />",
259 " </Component>",
260 " </Fragment>",
261 "</Wix>"
262 };
263
264 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
265
266 var messaging = new MockMessaging();
267 var converter = new WixConverter(messaging, 2, null, null);
268
269 var errors = converter.ConvertDocument(document);
270
271 var actualLines = UnformattedDocumentLines(document);
272 WixAssert.CompareLineByLine(expected, actualLines);
273
274 WixAssert.CompareLineByLine(new[]
275 {
276 "[Converted] This file contains an XML declaration on the first line. (DeclarationPresent)",
277 "[Converted] The namespace 'http://schemas.microsoft.com/wix/2006/wi' is out of date. It must be 'http://wixtoolset.org/schemas/v4/wxs'. (XmlnsValueWrong)",
278 "[Converted] The TARGETDIR directory should no longer be explicitly referenced. Remove the DirectoryRef element with Id attribute 'TARGETDIR'. (StandardDirectoryRefDeprecated)",
279 "A reference to the TARGETDIR Directory was removed. This can cause unintended side effects. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages (TargetDirRefRemoved)",
280 "[Converted] The file id is being updated to 'c1.txt' to ensure it remains the same as the v3 default (AssignAnonymousFileId)",
281 "[Converted] The file id is being updated to 'c2.txt' to ensure it remains the same as the v3 default (AssignAnonymousFileId)",
282 "[Converted] The TARGETDIR directory should no longer be explicitly defined. Remove the Directory element with Id attribute 'TARGETDIR'. (TargetDirDeprecated)",
283 "[Converted] The file id is being updated to 'c3.txt' to ensure it remains the same as the v3 default (AssignAnonymousFileId)",
284 "[Converted] The file id is being updated to 'c4.txt' to ensure it remains the same as the v3 default (AssignAnonymousFileId)"
285 }, messaging.Messages.Select(m => m.ToString()).ToArray());
286
287 Assert.Equal(9, errors);
288 }
289
290 [Fact]
291 public void ErrorOnEmptyStandardDirectoryRef()
292 {
293 var parse = String.Join(Environment.NewLine,
294 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
295 " <Fragment>",
296 " <DirectoryRef Id='TARGETDIR' />",
297 " <DirectoryRef Id='ProgramFilesFolder' />",
298 " <DirectoryRef Id='DesktopFolder' />",
299 " </Fragment>",
300 "</Wix>");
301
302 var expected = new[]
303 {
304 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
305 " <Fragment>",
306 " <DirectoryRef Id=\"TARGETDIR\" />",
307 " <DirectoryRef Id=\"ProgramFilesFolder\" />",
308 " <DirectoryRef Id=\"DesktopFolder\" />",
309 " </Fragment>",
310 "</Wix>"
311 };
312
313 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
314
315 var messaging = new MockMessaging();
316 var converter = new WixConverter(messaging, 2, null, null);
317
318 var errors = converter.ConvertDocument(document);
319
320 WixAssert.CompareLineByLine(new[]
321 {
322 "[Converted] The namespace 'http://schemas.microsoft.com/wix/2006/wi' is out of date. It must be 'http://wixtoolset.org/schemas/v4/wxs'. (XmlnsValueWrong)",
323 "Referencing 'TARGETDIR' directory directly is no longer supported. The DirectoryRef will not be removed but you will probably need to reference a more specific directory. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages (EmptyStandardDirectoryRefNotConvertable)",
324 "Referencing 'ProgramFilesFolder' directory directly is no longer supported. The DirectoryRef will not be removed but you will probably need to reference a more specific directory. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages (EmptyStandardDirectoryRefNotConvertable)",
325 "Referencing 'DesktopFolder' directory directly is no longer supported. The DirectoryRef will not be removed but you will probably need to reference a more specific directory. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages (EmptyStandardDirectoryRefNotConvertable)"
326 }, messaging.Messages.Select(m => m.ToString()).ToArray());
327
328 var actualLines = UnformattedDocumentLines(document);
329 WixAssert.CompareLineByLine(expected, actualLines);
330 Assert.Equal(4, errors);
331 }
332 }
333 }