main
cs 302 lines 13.7 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.BootstrapperApplications
4 {
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 using System.Linq;
9 using WixInternal.Core.TestPackage;
10 using WixInternal.TestSupport;
11 using Xunit;
12
13 public class BalExtensionFixture
14 {
15 [Fact]
16 public void CanBuildUsingDisplayInternalUICondition()
17 {
18 using (var fs = new DisposableFileSystem())
19 {
20 var baseFolder = fs.GetFolder();
21 var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
22 var bundleSourceFolder = TestData.Get(@"TestData\WixStdBa");
23 var intermediateFolder = Path.Combine(baseFolder, "obj");
24 var baFolderPath = Path.Combine(baseFolder, "ba");
25 var extractFolderPath = Path.Combine(baseFolder, "extract");
26
27 var compileResult = WixRunner.Execute(new[]
28 {
29 "build",
30 Path.Combine(bundleSourceFolder, "DisplayInternalUIConditionBundle.wxs"),
31 "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
32 "-intermediateFolder", intermediateFolder,
33 "-bindpath", Path.Combine(bundleSourceFolder, "data"),
34 "-o", bundleFile,
35 });
36 compileResult.AssertSuccess();
37
38 Assert.True(File.Exists(bundleFile));
39
40 var extractResult = BundleExtractor.ExtractBAContainer(null, bundleFile, baFolderPath, extractFolderPath);
41 extractResult.AssertSuccess();
42
43 var balPackageInfos = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixBalPackageInfo");
44 WixAssert.CompareLineByLine(new string[]
45 {
46 "<WixBalPackageInfo PackageId='test.msi' DisplayInternalUICondition='1' />",
47 }, balPackageInfos);
48
49 Assert.True(File.Exists(Path.Combine(baFolderPath, "thm.wxl")));
50 }
51 }
52
53 [Fact]
54 public void CanBuildUsingBootstrapperApplicationId()
55 {
56 using (var fs = new DisposableFileSystem())
57 {
58 var baseFolder = fs.GetFolder();
59 var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
60 var bundleSourceFolder = TestData.Get("TestData", "WixStdBa");
61 var intermediateFolder = Path.Combine(baseFolder, "obj");
62 var baFolderPath = Path.Combine(baseFolder, "ba");
63 var extractFolderPath = Path.Combine(baseFolder, "extract");
64
65 var compileResult = WixRunner.Execute(new[]
66 {
67 "build",
68 Path.Combine(bundleSourceFolder, "BootstrapperApplicationId.wxs"),
69 "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
70 "-intermediateFolder", intermediateFolder,
71 "-bindpath", Path.Combine(bundleSourceFolder, "data"),
72 "-o", bundleFile,
73 });
74 compileResult.AssertSuccess();
75
76 Assert.True(File.Exists(bundleFile));
77
78 var extractResult = BundleExtractor.ExtractBAContainer(null, bundleFile, baFolderPath, extractFolderPath);
79 extractResult.AssertSuccess();
80
81 var ignoreAttributesByElementName = new Dictionary<string, List<string>>
82 {
83 { "Payload", new List<string> { "SourcePath" } },
84 };
85
86 var wixStdBaPayloadInfo = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:UX/burn:Payload[@FilePath='wixstdba.exe']", ignoreAttributesByElementName);
87 WixAssert.CompareLineByLine(new string[]
88 {
89 $@"<Payload Id='WixStandardBootstrapperApplication_X86' FilePath='wixstdba.exe' SourcePath='*' />"
90 }, wixStdBaPayloadInfo);
91 }
92 }
93
94 [Fact]
95 public void CanBuildUsingOverridable()
96 {
97 using (var fs = new DisposableFileSystem())
98 {
99 var baseFolder = fs.GetFolder();
100 var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
101 var bundleSourceFolder = TestData.Get(@"TestData\Overridable");
102 var intermediateFolder = Path.Combine(baseFolder, "obj");
103 var baFolderPath = Path.Combine(baseFolder, "ba");
104 var extractFolderPath = Path.Combine(baseFolder, "extract");
105
106 var compileResult = WixRunner.Execute(new[]
107 {
108 "build",
109 Path.Combine(bundleSourceFolder, "Bundle.wxs"),
110 "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
111 "-intermediateFolder", intermediateFolder,
112 "-o", bundleFile,
113 });
114 compileResult.AssertSuccess();
115
116 Assert.True(File.Exists(bundleFile));
117
118 var extractResult = BundleExtractor.ExtractBAContainer(null, bundleFile, baFolderPath, extractFolderPath);
119 extractResult.AssertSuccess();
120
121 var balCommandLines = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixStdbaCommandLine");
122 WixAssert.CompareLineByLine(new[]
123 {
124 "<WixStdbaCommandLine VariableType='caseInsensitive' />",
125 }, balCommandLines);
126
127 var balOverridableVariables = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixStdbaOverridableVariable");
128 WixAssert.CompareLineByLine(new[]
129 {
130 "<WixStdbaOverridableVariable Name='TEST1' />",
131 }, balOverridableVariables);
132 }
133 }
134
135 [Fact]
136 public void CanBuildUsingWixStdBa()
137 {
138 using (var fs = new DisposableFileSystem())
139 {
140 var baseFolder = fs.GetFolder();
141 var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
142 var bundleSourceFolder = TestData.Get(@"TestData\WixStdBa");
143 var intermediateFolder = Path.Combine(baseFolder, "obj");
144
145 var compileResult = WixRunner.Execute(new[]
146 {
147 "build",
148 Path.Combine(bundleSourceFolder, "Bundle.wxs"),
149 "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
150 "-intermediateFolder", intermediateFolder,
151 "-o", bundleFile,
152 });
153 compileResult.AssertSuccess();
154
155 Assert.True(File.Exists(bundleFile));
156 }
157 }
158
159 //[Fact]
160 //public void CanBuildUsingMBAWithAlwaysInstallPrereqs()
161 //{
162 // using (var fs = new DisposableFileSystem())
163 // {
164 // var baseFolder = fs.GetFolder();
165 // var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
166 // var bundleSourceFolder = TestData.Get("TestData", "MBA");
167 // var intermediateFolder = Path.Combine(baseFolder, "obj");
168 // var baFolderPath = Path.Combine(baseFolder, "ba");
169 // var extractFolderPath = Path.Combine(baseFolder, "extract");
170
171 // var compileResult = WixRunner.Execute(new[]
172 // {
173 // "build",
174 // Path.Combine(bundleSourceFolder, "AlwaysInstallPrereqsBundle.wxs"),
175 // "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
176 // "-intermediateFolder", intermediateFolder,
177 // "-o", bundleFile,
178 // });
179
180 // compileResult.AssertSuccess();
181
182 // Assert.True(File.Exists(bundleFile));
183
184 // var extractResult = BundleExtractor.ExtractBAContainer(null, bundleFile, baFolderPath, extractFolderPath);
185 // extractResult.AssertSuccess();
186
187 // var wixPrereqOptionsElements = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixPrereqOptions");
188 // WixAssert.CompareLineByLine(new[]
189 // {
190 // "<WixPrereqOptions AlwaysInstallPrereqs='1' />",
191 // }, wixPrereqOptionsElements);
192
193 // var wixPrereqInformationElements = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixPrereqInformation");
194 // WixAssert.CompareLineByLine(new[]
195 // {
196 // "<WixPrereqInformation PackageId='wixnative.exe' />",
197 // }, wixPrereqInformationElements);
198 // }
199 //}
200
201 [Fact]
202 public void CannotBuildUsingMBAWithNoPrereqs()
203 {
204 using (var fs = new DisposableFileSystem())
205 {
206 var baseFolder = fs.GetFolder();
207 var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
208 var bundleSourceFolder = TestData.Get(@"TestData", "MBA");
209 var dataFolder = TestData.Get(@"TestData", ".Data");
210 var intermediateFolder = Path.Combine(baseFolder, "obj");
211
212 var compileResult = WixRunner.Execute(new[]
213 {
214 "build",
215 Path.Combine(bundleSourceFolder, "Bundle.wxs"),
216 "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
217 "-intermediateFolder", intermediateFolder,
218 "-bindpath", dataFolder,
219 "-o", bundleFile,
220 });
221
222 WixAssert.CompareLineByLine(new[]
223 {
224 "The WixManagedBootstrapperApplicationHost element has been deprecated.",
225 }, compileResult.Messages.Select(m => m.ToString()).ToArray());
226 Assert.Equal(1130, compileResult.ExitCode);
227
228 Assert.False(File.Exists(bundleFile));
229 Assert.False(File.Exists(Path.Combine(intermediateFolder, "test.exe")));
230 }
231 }
232
233 [Fact]
234 public void CannotBuildUsingDncbaMissingBAFactoryPayload()
235 {
236 using (var fs = new DisposableFileSystem())
237 {
238 var baseFolder = fs.GetFolder();
239 var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
240 var bundleSourceFolder = TestData.Get(@"TestData\Dncba");
241 var intermediateFolder = Path.Combine(baseFolder, "obj");
242
243 var compileResult = WixRunner.Execute(new[]
244 {
245 "build",
246 Path.Combine(bundleSourceFolder, "Bundle.wxs"),
247 "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
248 "-intermediateFolder", intermediateFolder,
249 "-o", bundleFile,
250 });
251
252 WixAssert.CompareLineByLine(new[]
253 {
254 "The WixDotNetCoreBootstrapperApplicationHost element has been deprecated.",
255 "The BootstrapperApplication element's Name or SourceFile attribute was not found; one of these is required."
256 }, compileResult.Messages.Select(x => x.ToString()).ToArray());
257 Assert.Equal(44, compileResult.ExitCode);
258
259 Assert.False(File.Exists(bundleFile));
260 Assert.False(File.Exists(Path.Combine(intermediateFolder, "test.exe")));
261 }
262 }
263
264 [Fact]
265 public void CannotBuildUsingOverridableWrongCase()
266 {
267 using (var fs = new DisposableFileSystem())
268 {
269 var baseFolder = fs.GetFolder();
270 var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
271 var bundleSourceFolder = TestData.Get(@"TestData");
272 var intermediateFolder = Path.Combine(baseFolder, "obj");
273 var baFolderPath = Path.Combine(baseFolder, "ba");
274 var extractFolderPath = Path.Combine(baseFolder, "extract");
275
276 var result = WixRunner.Execute(new[]
277 {
278 "build",
279 Path.Combine(bundleSourceFolder, "Overridable", "WrongCaseBundle.wxs"),
280 "-loc", Path.Combine(bundleSourceFolder, "Overridable", "WrongCaseBundle.wxl"),
281 "-bindpath", Path.Combine(bundleSourceFolder, "WixStdBa", "Data"),
282 "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
283 "-intermediateFolder", intermediateFolder,
284 "-o", bundleFile,
285 });
286
287 Assert.InRange(result.ExitCode, 2, Int32.MaxValue);
288
289 var messages = result.Messages.Select(m => m.ToString()).ToList();
290 messages.Sort();
291
292 WixAssert.CompareLineByLine(new[]
293 {
294 "bal:Condition/@Condition contains the built-in Variable 'WixBundleAction', which is not available when it is evaluated. (Unavailable Variables are: 'WixBundleAction'.). Rewrite the condition to avoid Variables that are never valid during its evaluation.",
295 "Overridable variable 'TEST1' collides with 'Test1' with Bundle/@CommandLineVariables value 'caseInsensitive'.",
296 "The *Package/@bal:DisplayInternalUICondition attribute's value '=' is not a valid bundle condition.",
297 "The location of the Variable related to the previous error.",
298 }, messages.ToArray());
299 }
300 }
301 }
302 }