| 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.Heat |
| 4 | { |
| 5 | using System.IO; |
| 6 | using System.Linq; |
| 7 | using WixInternal.TestSupport; |
| 8 | using Xunit; |
| 9 | |
| 10 | public class HeatFixture |
| 11 | { |
| 12 | [Fact] |
| 13 | public void CanHarvestSimpleDirectory() |
| 14 | { |
| 15 | var folder = TestData.Get("TestData", "SingleFile"); |
| 16 | |
| 17 | using (var fs = new DisposableFileSystem()) |
| 18 | { |
| 19 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 20 | |
| 21 | var args = new[] |
| 22 | { |
| 23 | "dir", folder, |
| 24 | "-o", outputPath |
| 25 | }; |
| 26 | |
| 27 | var result = HeatRunner.Execute(args); |
| 28 | result.AssertSuccess(); |
| 29 | |
| 30 | var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 31 | WixAssert.CompareLineByLine(new[] |
| 32 | { |
| 33 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 34 | " <Fragment>", |
| 35 | " <StandardDirectory Id='TARGETDIR'>", |
| 36 | " <Directory Id='dirwsJn0Cqs9KdlDSFdQsu9ygYvMF8' Name='SingleFile' />", |
| 37 | " </StandardDirectory>", |
| 38 | " </Fragment>", |
| 39 | " <Fragment>", |
| 40 | " <DirectoryRef Id='dirwsJn0Cqs9KdlDSFdQsu9ygYvMF8'>", |
| 41 | " <Component Id='cmp0i3dThrp4nheCteEmXvHxBDa_VE' Guid='PUT-GUID-HERE'>", |
| 42 | " <File Id='filziMcXYgrmcbVF8PuTUfIB9Vgqo0' KeyPath='yes' Source='SourceDir\\a.txt' />", |
| 43 | " </Component>", |
| 44 | " </DirectoryRef>", |
| 45 | " </Fragment>", |
| 46 | "</Wix>", |
| 47 | }, wxs); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | [Fact] |
| 52 | public void CanHarvestSimpleDirectoryToComponentGroup() |
| 53 | { |
| 54 | var folder = TestData.Get("TestData", "SingleFile"); |
| 55 | |
| 56 | using (var fs = new DisposableFileSystem()) |
| 57 | { |
| 58 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 59 | |
| 60 | var args = new[] |
| 61 | { |
| 62 | "dir", folder, |
| 63 | "-cg", "CG1", |
| 64 | "-o", outputPath |
| 65 | }; |
| 66 | |
| 67 | var result = HeatRunner.Execute(args); |
| 68 | result.AssertSuccess(); |
| 69 | |
| 70 | var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 71 | WixAssert.CompareLineByLine(new[] |
| 72 | { |
| 73 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 74 | " <Fragment>", |
| 75 | " <StandardDirectory Id='TARGETDIR'>", |
| 76 | " <Directory Id='dirwsJn0Cqs9KdlDSFdQsu9ygYvMF8' Name='SingleFile' />", |
| 77 | " </StandardDirectory>", |
| 78 | " </Fragment>", |
| 79 | " <Fragment>", |
| 80 | " <ComponentGroup Id='CG1'>", |
| 81 | " <Component Id='cmp0i3dThrp4nheCteEmXvHxBDa_VE' Directory='dirwsJn0Cqs9KdlDSFdQsu9ygYvMF8' Guid='PUT-GUID-HERE'>", |
| 82 | " <File Id='filziMcXYgrmcbVF8PuTUfIB9Vgqo0' KeyPath='yes' Source='SourceDir\\a.txt' />", |
| 83 | " </Component>", |
| 84 | " </ComponentGroup>", |
| 85 | " </Fragment>", |
| 86 | "</Wix>", |
| 87 | }, wxs); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | [Fact] |
| 92 | public void CanHarvestSimpleDirectoryToInstallFolder() |
| 93 | { |
| 94 | var folder = TestData.Get("TestData", "SingleFile"); |
| 95 | |
| 96 | using (var fs = new DisposableFileSystem()) |
| 97 | { |
| 98 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 99 | |
| 100 | var args = new[] |
| 101 | { |
| 102 | "dir", folder, |
| 103 | "-dr", "INSTALLFOLDER", |
| 104 | "-indent", "2", |
| 105 | "-o", outputPath |
| 106 | }; |
| 107 | |
| 108 | var result = HeatRunner.Execute(args); |
| 109 | result.AssertSuccess(); |
| 110 | |
| 111 | var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 112 | WixAssert.CompareLineByLine(new[] |
| 113 | { |
| 114 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 115 | " <Fragment>", |
| 116 | " <DirectoryRef Id='INSTALLFOLDER'>", |
| 117 | " <Directory Id='dirlooNEIrtEBL2w_RhFEIgiKcUlxE' Name='SingleFile' />", |
| 118 | " </DirectoryRef>", |
| 119 | " </Fragment>", |
| 120 | " <Fragment>", |
| 121 | " <DirectoryRef Id='dirlooNEIrtEBL2w_RhFEIgiKcUlxE'>", |
| 122 | " <Component Id='cmpxHVF6oXohc0EWgRphmYZvw5.GGU' Guid='PUT-GUID-HERE'>", |
| 123 | " <File Id='filk_7KUAfL4VfzxSRsGFf_XOBHln0' KeyPath='yes' Source='SourceDir\\a.txt' />", |
| 124 | " </Component>", |
| 125 | " </DirectoryRef>", |
| 126 | " </Fragment>", |
| 127 | "</Wix>", |
| 128 | }, wxs); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | [Fact] |
| 133 | public void CanHarvestFile() |
| 134 | { |
| 135 | var folder = TestData.Get("TestData", "SingleFile"); |
| 136 | |
| 137 | using (var fs = new DisposableFileSystem()) |
| 138 | { |
| 139 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 140 | |
| 141 | var args = new[] |
| 142 | { |
| 143 | "file", Path.Combine(folder, "a.txt"), |
| 144 | "-cg", "GroupA", |
| 145 | "-dr", "ProgramFiles6432Folder", |
| 146 | "-o", outputPath |
| 147 | |
| 148 | }; |
| 149 | |
| 150 | var result = HeatRunner.Execute(args); |
| 151 | result.AssertSuccess(); |
| 152 | |
| 153 | var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 154 | WixAssert.CompareLineByLine(new[] |
| 155 | { |
| 156 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 157 | " <Fragment>", |
| 158 | " <StandardDirectory Id='ProgramFiles6432Folder'>", |
| 159 | " <Directory Id='dirl6r_Yc0gvMUEUVe5rioOOIIasoU' Name='SingleFile' />", |
| 160 | " </StandardDirectory>", |
| 161 | " </Fragment>", |
| 162 | " <Fragment>", |
| 163 | " <ComponentGroup Id='GroupA'>", |
| 164 | " <Component Id='cmpfBcW61_XzosRWK3EzUTBtJrcJD8' Directory='dirl6r_Yc0gvMUEUVe5rioOOIIasoU' Guid='PUT-GUID-HERE'>", |
| 165 | " <File Id='filKrZgaIOSKpNZXFnezZc9X.LKGpw' KeyPath='yes' Source='SourceDir\\SingleFile\\a.txt' />", |
| 166 | " </Component>", |
| 167 | " </ComponentGroup>", |
| 168 | " </Fragment>", |
| 169 | "</Wix>", |
| 170 | }, wxs); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | [Fact] |
| 175 | public void CanHarvestRegistry() |
| 176 | { |
| 177 | var folder = TestData.Get("TestData", "RegFile"); |
| 178 | |
| 179 | using (var fs = new DisposableFileSystem()) |
| 180 | { |
| 181 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 182 | |
| 183 | var args = new[] |
| 184 | { |
| 185 | "reg", Path.Combine(folder, "input.reg"), |
| 186 | "-o", outputPath |
| 187 | }; |
| 188 | |
| 189 | var result = HeatRunner.Execute(args); |
| 190 | result.AssertSuccess(); |
| 191 | |
| 192 | var actual = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 193 | var expected = File.ReadAllLines(Path.Combine(folder, "Expected.wxs")).Select(s => s.Replace("\"", "'")).ToArray(); |
| 194 | WixAssert.CompareLineByLine(expected, actual); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | [Fact] |
| 199 | public void CanHarvestRegistryIntoComponentGroup() |
| 200 | { |
| 201 | var folder = TestData.Get("TestData", "RegFile"); |
| 202 | |
| 203 | using (var fs = new DisposableFileSystem()) |
| 204 | { |
| 205 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 206 | |
| 207 | var args = new[] |
| 208 | { |
| 209 | "reg", Path.Combine(folder, "input.reg"), |
| 210 | "-cg", "CG1", |
| 211 | "-o", outputPath |
| 212 | }; |
| 213 | |
| 214 | var result = HeatRunner.Execute(args); |
| 215 | result.AssertSuccess(); |
| 216 | |
| 217 | var actual = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 218 | var expected = File.ReadAllLines(Path.Combine(folder, "ExpectedWithComponentGroup.wxs")).Select(s => s.Replace("\"", "'")).ToArray(); |
| 219 | WixAssert.CompareLineByLine(expected, actual); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |