diff options
Diffstat (limited to 'src/test/WixToolsetTest.MSBuild/MsbuildHeatFixture.cs')
-rw-r--r-- | src/test/WixToolsetTest.MSBuild/MsbuildHeatFixture.cs | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.MSBuild/MsbuildHeatFixture.cs b/src/test/WixToolsetTest.MSBuild/MsbuildHeatFixture.cs new file mode 100644 index 00000000..fa8acb81 --- /dev/null +++ b/src/test/WixToolsetTest.MSBuild/MsbuildHeatFixture.cs | |||
@@ -0,0 +1,151 @@ | |||
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.MSBuild | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Linq; | ||
8 | using WixBuildTools.TestSupport; | ||
9 | using WixToolset.Core.TestPackage; | ||
10 | using WixToolset.Data; | ||
11 | using WixToolset.Data.Tuples; | ||
12 | using Xunit; | ||
13 | |||
14 | public class MsbuildHeatFixture | ||
15 | { | ||
16 | private static readonly string WixTargetsPath = Path.Combine(new Uri(typeof(MsbuildHeatFixture).Assembly.CodeBase).AbsolutePath, "..", "..", "publish", "WixToolset.MSBuild", "tools", "wix.targets"); | ||
17 | |||
18 | [Fact] | ||
19 | public void CanBuildHeatFilePackage() | ||
20 | { | ||
21 | var projectPath = TestData.Get(@"TestData\HeatFilePackage\HeatFilePackage.wixproj"); | ||
22 | |||
23 | using (var fs = new DisposableFileSystem()) | ||
24 | { | ||
25 | var baseFolder = fs.GetFolder(); | ||
26 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
27 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
28 | |||
29 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
30 | { | ||
31 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
32 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
33 | $"-p:OutputPath={binFolder}" | ||
34 | }); | ||
35 | result.AssertSuccess(); | ||
36 | |||
37 | var heatCommandLines = result.Output.Where(line => line.TrimStart().StartsWith("heat.exe file")); | ||
38 | Assert.Single(heatCommandLines); | ||
39 | |||
40 | var warnings = result.Output.Where(line => line.Contains(": warning")); | ||
41 | Assert.Empty(warnings); | ||
42 | |||
43 | var generatedFilePath = Path.Combine(intermediateFolder, @"_ProductComponents_INSTALLFOLDER_HeatFilePackage.wixproj_file.wxs"); | ||
44 | Assert.True(File.Exists(generatedFilePath)); | ||
45 | |||
46 | var generatedContents = File.ReadAllText(generatedFilePath); | ||
47 | var testXml = generatedContents.GetTestXml(); | ||
48 | Assert.Equal(@"<Wix>" + | ||
49 | "<Fragment>" + | ||
50 | "<DirectoryRef Id='INSTALLFOLDER'>" + | ||
51 | "<Component Id='HeatFilePackage.wixproj' Guid='*'>" + | ||
52 | "<File Id='HeatFilePackage.wixproj' KeyPath='yes' Source='SourceDir\\HeatFilePackage.wixproj' />" + | ||
53 | "</Component>" + | ||
54 | "</DirectoryRef>" + | ||
55 | "</Fragment>" + | ||
56 | "<Fragment>" + | ||
57 | "<ComponentGroup Id='ProductComponents'>" + | ||
58 | "<ComponentRef Id='HeatFilePackage.wixproj' />" + | ||
59 | "</ComponentGroup>" + | ||
60 | "</Fragment>" + | ||
61 | "</Wix>", testXml); | ||
62 | |||
63 | var pdbPath = Path.Combine(binFolder, "HeatFilePackage.wixpdb"); | ||
64 | Assert.True(File.Exists(pdbPath)); | ||
65 | |||
66 | var intermediate = Intermediate.Load(pdbPath); | ||
67 | var section = intermediate.Sections.Single(); | ||
68 | |||
69 | var fileTuple = section.Tuples.OfType<FileTuple>().Single(); | ||
70 | Assert.Equal(@"SourceDir\HeatFilePackage.wixproj", fileTuple[FileTupleFields.Source].PreviousValue.AsPath().Path); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | [Fact] | ||
75 | public void CanBuildHeatFileWithMultipleFilesPackage() | ||
76 | { | ||
77 | var projectPath = TestData.Get(@"TestData\HeatFileMultipleFilesSameFileName\HeatFileMultipleFilesSameFileName.wixproj"); | ||
78 | |||
79 | using (var fs = new DisposableFileSystem()) | ||
80 | { | ||
81 | var baseFolder = fs.GetFolder(); | ||
82 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
83 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
84 | |||
85 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
86 | { | ||
87 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
88 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
89 | $"-p:OutputPath={binFolder}" | ||
90 | }); | ||
91 | result.AssertSuccess(); | ||
92 | |||
93 | var heatCommandLines = result.Output.Where(line => line.TrimStart().StartsWith("heat.exe file")); | ||
94 | Assert.Equal(2, heatCommandLines.Count()); | ||
95 | |||
96 | var warnings = result.Output.Where(line => line.Contains(": warning")); | ||
97 | Assert.Empty(warnings); | ||
98 | |||
99 | var generatedFilePath = Path.Combine(intermediateFolder, @"_TxtProductComponents_INSTALLFOLDER_MyProgram.txt_file.wxs"); | ||
100 | Assert.True(File.Exists(generatedFilePath)); | ||
101 | |||
102 | var generatedContents = File.ReadAllText(generatedFilePath); | ||
103 | var testXml = generatedContents.GetTestXml(); | ||
104 | Assert.Equal("<Wix>" + | ||
105 | "<Fragment>" + | ||
106 | "<DirectoryRef Id='INSTALLFOLDER'>" + | ||
107 | "<Component Id='MyProgram.txt' Guid='*'>" + | ||
108 | @"<File Id='MyProgram.txt' KeyPath='yes' Source='SourceDir\MyProgram.txt' />" + | ||
109 | "</Component>" + | ||
110 | "</DirectoryRef>" + | ||
111 | "</Fragment>" + | ||
112 | "<Fragment>" + | ||
113 | "<ComponentGroup Id='TxtProductComponents'>" + | ||
114 | "<ComponentRef Id='MyProgram.txt' />" + | ||
115 | "</ComponentGroup>" + | ||
116 | "</Fragment>" + | ||
117 | "</Wix>", testXml); | ||
118 | |||
119 | generatedFilePath = Path.Combine(intermediateFolder, @"_JsonProductComponents_INSTALLFOLDER_MyProgram.json_file.wxs"); | ||
120 | Assert.True(File.Exists(generatedFilePath)); | ||
121 | |||
122 | generatedContents = File.ReadAllText(generatedFilePath); | ||
123 | testXml = generatedContents.GetTestXml(); | ||
124 | Assert.Equal("<Wix>" + | ||
125 | "<Fragment>" + | ||
126 | "<DirectoryRef Id='INSTALLFOLDER'>" + | ||
127 | "<Component Id='MyProgram.json' Guid='*'>" + | ||
128 | @"<File Id='MyProgram.json' KeyPath='yes' Source='SourceDir\MyProgram.json' />" + | ||
129 | "</Component>" + | ||
130 | "</DirectoryRef>" + | ||
131 | "</Fragment>" + | ||
132 | "<Fragment>" + | ||
133 | "<ComponentGroup Id='JsonProductComponents'>" + | ||
134 | "<ComponentRef Id='MyProgram.json' />" + | ||
135 | "</ComponentGroup>" + | ||
136 | "</Fragment>" + | ||
137 | "</Wix>", testXml); | ||
138 | |||
139 | var pdbPath = Path.Combine(binFolder, "HeatFileMultipleFilesSameFileName.wixpdb"); | ||
140 | Assert.True(File.Exists(pdbPath)); | ||
141 | |||
142 | var intermediate = Intermediate.Load(pdbPath); | ||
143 | var section = intermediate.Sections.Single(); | ||
144 | |||
145 | var fileTuples = section.Tuples.OfType<FileTuple>().ToArray(); | ||
146 | Assert.Equal(@"SourceDir\MyProgram.txt", fileTuples[0][FileTupleFields.Source].PreviousValue.AsPath().Path); | ||
147 | Assert.Equal(@"SourceDir\MyProgram.json", fileTuples[1][FileTupleFields.Source].PreviousValue.AsPath().Path); | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | } | ||