summaryrefslogtreecommitdiff
path: root/src/wix/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs
blob: f158e3f20b3419b2344979bb321e6a6939722a82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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.

namespace WixToolsetTest.BuildTasks
{
    using System.IO;
    using System.Linq;
    using Microsoft.Build.Utilities;
    using WixBuildTools.TestSupport;
    using WixToolset.BuildTasks;
    using WixToolset.Data;
    using WixToolset.Data.Symbols;
    using Xunit;

    public class WixBuildTaskFixture
    {
        [Fact]
        public void CanBuildSimpleMsiPackage()
        {
            var folder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage");

            using (var fs = new DisposableFileSystem())
            {
                var baseFolder = fs.GetFolder();
                var intermediateFolder = Path.Combine(baseFolder, "obj");
                var pdbPath = Path.Combine(baseFolder, @"bin\testpackage.wixpdb");
                var engine = new FakeBuildEngine();

                var task = new WixBuild
                {
                    BuildEngine = engine,
                    SourceFiles = new[]
                    {
                        new TaskItem(Path.Combine(folder, "Package.wxs")),
                        new TaskItem(Path.Combine(folder, "PackageComponents.wxs")),
                    },
                    LocalizationFiles = new[]
                    {
                        new TaskItem(Path.Combine(folder, "Package.en-us.wxl")),
                    },
                    BindInputPaths = new[]
                    {
                        new TaskItem(Path.Combine(folder, "data")),
                    },
                    IntermediateDirectory = new TaskItem(intermediateFolder),
                    OutputFile = new TaskItem(Path.Combine(baseFolder, @"bin\test.msi")),
                    PdbType = "Full",
                    PdbFile = new TaskItem(pdbPath),
                    DefaultCompressionLevel = "nOnE",
                };

                var result = task.Execute();
                Assert.True(result, $"MSBuild task failed unexpectedly. Output:\r\n{engine.Output}");

                Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.msi")));
                Assert.True(File.Exists(pdbPath));
                Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\cab1.cab")));

                var intermediate = Intermediate.Load(pdbPath);
                var section = intermediate.Sections.Single();

                var fileSymbol = section.Symbols.OfType<FileSymbol>().Single();
                WixAssert.StringEqual(Path.Combine(folder, @"data\test.txt"), fileSymbol[FileSymbolFields.Source].AsPath().Path);
                WixAssert.StringEqual(@"test.txt", fileSymbol[FileSymbolFields.Source].PreviousValue.AsPath().Path);
            }
        }
    }
}