| 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; |
| 6 | using System.IO; |
| 7 | using System.Linq; |
| 8 | using WixInternal.TestSupport; |
| 9 | using Xunit; |
| 10 | |
| 11 | public class DirectoryToPayloadGroupFixture |
| 12 | { |
| 13 | [Fact] |
| 14 | public void CanHarvestSimpleDirectory() |
| 15 | { |
| 16 | var folder = TestData.Get("TestData", "SingleFile"); |
| 17 | |
| 18 | using (var fs = new DisposableFileSystem()) |
| 19 | { |
| 20 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 21 | |
| 22 | var args = new[] |
| 23 | { |
| 24 | "dir", folder, |
| 25 | "-generate", "payloadgroup", |
| 26 | "-o", outputPath |
| 27 | }; |
| 28 | |
| 29 | var result = HeatRunner.Execute(args); |
| 30 | result.AssertSuccess(); |
| 31 | |
| 32 | var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 33 | WixAssert.CompareLineByLine(new[] |
| 34 | { |
| 35 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 36 | " <Fragment>", |
| 37 | " <PayloadGroup Id='TARGETDIR'>", |
| 38 | " <Payload SourceFile='SourceDir\\a.txt' />", |
| 39 | " </PayloadGroup>", |
| 40 | " </Fragment>", |
| 41 | "</Wix>", |
| 42 | }, wxs); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | [Fact] |
| 47 | public void CanHarvestSimpleDirectoryWithSourceDirSubstitution() |
| 48 | { |
| 49 | var folder = TestData.Get("TestData", "SingleFile"); |
| 50 | |
| 51 | using (var fs = new DisposableFileSystem()) |
| 52 | { |
| 53 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 54 | |
| 55 | var args = new[] |
| 56 | { |
| 57 | "dir", folder, |
| 58 | "-generate", "payloadgroup", |
| 59 | "-var", "var.RootDir", |
| 60 | "-o", outputPath |
| 61 | }; |
| 62 | |
| 63 | var result = HeatRunner.Execute(args); |
| 64 | result.AssertSuccess(); |
| 65 | |
| 66 | var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 67 | WixAssert.CompareLineByLine(new[] |
| 68 | { |
| 69 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 70 | " <Fragment>", |
| 71 | " <PayloadGroup Id='TARGETDIR'>", |
| 72 | " <Payload SourceFile='$(var.RootDir)\\a.txt' />", |
| 73 | " </PayloadGroup>", |
| 74 | " </Fragment>", |
| 75 | "</Wix>", |
| 76 | }, wxs); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | [Fact] |
| 81 | public void CanHarvestNestedFiles() |
| 82 | { |
| 83 | var folder = TestData.Get("TestData", "NestedFiles"); |
| 84 | |
| 85 | using (var fs = new DisposableFileSystem()) |
| 86 | { |
| 87 | var outputPath = Path.Combine(fs.GetFolder(), "out.wxs"); |
| 88 | |
| 89 | var args = new[] |
| 90 | { |
| 91 | "dir", folder, |
| 92 | "-generate", "payloadgroup", |
| 93 | "-o", outputPath |
| 94 | }; |
| 95 | |
| 96 | var result = HeatRunner.Execute(args); |
| 97 | result.AssertSuccess(); |
| 98 | |
| 99 | var wxs = File.ReadAllLines(outputPath).Select(s => s.Replace("\"", "'")).ToArray(); |
| 100 | WixAssert.CompareLineByLine(new[] |
| 101 | { |
| 102 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", |
| 103 | " <Fragment>", |
| 104 | " <PayloadGroup Id='TARGETDIR'>", |
| 105 | " <Payload SourceFile='SourceDir\\Nested\\c.txt' Name='Nested\\c.txt' />", |
| 106 | " <Payload SourceFile='SourceDir\\b.txt' />", |
| 107 | " </PayloadGroup>", |
| 108 | " </Fragment>", |
| 109 | "</Wix>", |
| 110 | }, wxs); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |