diff options
Diffstat (limited to '')
-rw-r--r-- | src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs | 119 |
1 files changed, 80 insertions, 39 deletions
diff --git a/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs b/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs index a27928d5..95b727ad 100644 --- a/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs +++ b/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs | |||
@@ -2,62 +2,103 @@ | |||
2 | 2 | ||
3 | namespace WixToolsetTest.BuildTasks | 3 | namespace WixToolsetTest.BuildTasks |
4 | { | 4 | { |
5 | using System; | ||
5 | using System.IO; | 6 | using System.IO; |
6 | using System.Linq; | 7 | using System.Linq; |
7 | using Microsoft.Build.Utilities; | ||
8 | using WixBuildTools.TestSupport; | 8 | using WixBuildTools.TestSupport; |
9 | using WixToolset.BuildTasks; | 9 | using WixToolset.BuildTasks; |
10 | using WixToolset.Data; | ||
11 | using WixToolset.Data.Tuples; | ||
12 | using Xunit; | 10 | using Xunit; |
13 | 11 | ||
14 | public partial class MsbuildFixture | 12 | public class MsbuildFixture |
15 | { | 13 | { |
14 | private static readonly string WixTargetsPath = Path.Combine(Path.GetDirectoryName(new Uri(typeof(DoIt).Assembly.CodeBase).AbsolutePath), "wix.targets"); | ||
15 | |||
16 | public MsbuildFixture() | ||
17 | { | ||
18 | this.MsbuildRunner = new MsbuildRunner(); | ||
19 | } | ||
20 | |||
21 | private MsbuildRunner MsbuildRunner { get; } | ||
22 | |||
16 | [Fact] | 23 | [Fact] |
17 | public void CanBuildSimpleMsiPackage() | 24 | public void CanBuildSimpleMsiPackage() |
18 | { | 25 | { |
19 | var folder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage"); | 26 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); |
20 | 27 | ||
21 | using (var fs = new DisposableFileSystem()) | 28 | using (var fs = new DisposableFileSystem()) |
22 | { | 29 | { |
23 | var baseFolder = fs.GetFolder(); | 30 | var baseFolder = fs.GetFolder(); |
24 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | 31 | var binFolder = Path.Combine(baseFolder, @"bin\"); |
32 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
25 | 33 | ||
26 | var engine = new FakeBuildEngine(); | 34 | var result = this.MsbuildRunner.Execute(projectPath, new[] |
35 | { | ||
36 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
37 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
38 | $"-p:OutputPath={binFolder}" | ||
39 | }); | ||
40 | result.AssertSuccess(); | ||
27 | 41 | ||
28 | var task = new DoIt | 42 | var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) |
43 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
44 | .OrderBy(s => s) | ||
45 | .ToArray(); | ||
46 | Assert.Equal(new[] | ||
29 | { | 47 | { |
30 | BuildEngine = engine, | 48 | @"bin\en-US\cab1.cab", |
31 | SourceFiles = new[] | 49 | @"bin\en-US\MsiPackage.msi", |
32 | { | 50 | @"bin\en-US\MsiPackage.wixpdb", |
33 | new TaskItem(Path.Combine(folder, "Package.wxs")), | 51 | }, paths); |
34 | new TaskItem(Path.Combine(folder, "PackageComponents.wxs")), | 52 | } |
35 | }, | 53 | } |
36 | LocalizationFiles = new[] | 54 | |
37 | { | 55 | [Fact] |
38 | new TaskItem(Path.Combine(folder, "Package.en-us.wxl")), | 56 | public void CanBuildAndCleanSimpleMsiPackage() |
39 | }, | 57 | { |
40 | BindInputPaths = new[] | 58 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); |
41 | { | 59 | |
42 | new TaskItem(Path.Combine(folder, "data")), | 60 | using (var fs = new DisposableFileSystem()) |
43 | }, | 61 | { |
44 | IntermediateDirectory = new TaskItem(intermediateFolder), | 62 | var baseFolder = fs.GetFolder(); |
45 | OutputFile = new TaskItem(Path.Combine(baseFolder, @"bin\test.msi")), | 63 | var binFolder = Path.Combine(baseFolder, @"bin\"); |
46 | }; | 64 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); |
47 | 65 | ||
48 | var result = task.Execute(); | 66 | // Build |
49 | Assert.True(result, $"MSBuild task failed unexpectedly. Output:\r\n{engine.Output}"); | 67 | var result = this.MsbuildRunner.Execute(projectPath, new[] |
50 | 68 | { | |
51 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.msi"))); | 69 | $"-p:WixTargetsPath={WixTargetsPath}", |
52 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.wixpdb"))); | 70 | $"-p:IntermediateOutputPath={intermediateFolder}", |
53 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\cab1.cab"))); | 71 | $"-p:OutputPath={binFolder}", |
54 | 72 | "-v:diag" | |
55 | var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wir")); | 73 | }); |
56 | var section = intermediate.Sections.Single(); | 74 | result.AssertSuccess(); |
57 | 75 | ||
58 | var wixFile = section.Tuples.OfType<WixFileTuple>().Single(); | 76 | var buildOutput = String.Join("\r\n", result.Output); |
59 | Assert.Equal(Path.Combine(folder, @"data\test.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path); | 77 | |
60 | Assert.Equal(@"test.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path); | 78 | var createdPaths = Directory.EnumerateFiles(baseFolder, @"*.*", SearchOption.AllDirectories) |
79 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
80 | .OrderBy(s => s) | ||
81 | .ToArray(); | ||
82 | Assert.NotEmpty(createdPaths); | ||
83 | |||
84 | // Clean | ||
85 | result = this.MsbuildRunner.Execute(projectPath, new[] | ||
86 | { | ||
87 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
88 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
89 | $"-p:OutputPath={binFolder}", | ||
90 | "-t:Clean", | ||
91 | "-v:diag" | ||
92 | }); | ||
93 | result.AssertSuccess(); | ||
94 | |||
95 | var cleanOutput = String.Join("\r\n", result.Output); | ||
96 | |||
97 | var remainingPaths = Directory.EnumerateFiles(baseFolder, @"*.*", SearchOption.AllDirectories) | ||
98 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
99 | .OrderBy(s => s) | ||
100 | .ToArray(); | ||
101 | Assert.Empty(remainingPaths); | ||
61 | } | 102 | } |
62 | } | 103 | } |
63 | } | 104 | } |