summaryrefslogtreecommitdiff
path: root/src/test/burn/WixToolsetTest.BurnE2E/MsiTransactionTests.cs
blob: cbfee806c343ede814c6fab1039dd67f8ca3e6d0 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// 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.BurnE2E
{
    using System;
    using System.IO;
    using WixTestTools;
    using Xunit;
    using Xunit.Abstractions;

    public class MsiTransactionTests : BurnE2ETests
    {
        public MsiTransactionTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }

        [Fact]
        public void CanUpgradeBundleWithMsiTransaction()
        {
            var packageA = this.CreatePackageInstaller("PackageA");
            var packageBv1 = this.CreatePackageInstaller("PackageBv1");
            var packageBv2 = this.CreatePackageInstaller("PackageBv2");
            var packageCv1 = this.CreatePackageInstaller("PackageCv1");
            var packageCv2 = this.CreatePackageInstaller("PackageCv2");
            var packageD = this.CreatePackageInstaller("PackageD");

            var bundleAv1 = this.CreateBundleInstaller("BundleAv1");
            var bundleAv2 = this.CreateBundleInstaller("BundleAv2");

            var packageASourceCodeInstalled = packageA.GetInstalledFilePath("Package.wxs");
            var packageBv1SourceCodeInstalled = packageBv1.GetInstalledFilePath("Package.wxs");
            var packageBv2SourceCodeInstalled = packageBv2.GetInstalledFilePath("Package.wxs");
            var packageCv1SourceCodeInstalled = packageCv1.GetInstalledFilePath("Package.wxs");
            var packageCv2SourceCodeInstalled = packageCv2.GetInstalledFilePath("Package.wxs");
            var packageDSourceCodeInstalled = packageD.GetInstalledFilePath("Package.wxs");

            // Source file should *not* be installed
            Assert.False(File.Exists(packageASourceCodeInstalled), $"Package A payload should not be there on test start: {packageASourceCodeInstalled}");
            Assert.False(File.Exists(packageBv1SourceCodeInstalled), $"Package Bv1 payload should not be there on test start: {packageBv1SourceCodeInstalled}");
            Assert.False(File.Exists(packageBv2SourceCodeInstalled), $"Package Bv2 payload should not be there on test start: {packageBv2SourceCodeInstalled}");
            Assert.False(File.Exists(packageCv1SourceCodeInstalled), $"Package Cv1 payload should not be there on test start: {packageCv1SourceCodeInstalled}");
            Assert.False(File.Exists(packageCv2SourceCodeInstalled), $"Package Cv2 payload should not be there on test start: {packageCv2SourceCodeInstalled}");
            Assert.False(File.Exists(packageDSourceCodeInstalled), $"Package D payload should not be there on test start: {packageDSourceCodeInstalled}");

            bundleAv1.Install();

            var bundleAv1Registration = bundleAv1.VerifyRegisteredAndInPackageCache();

            // Source file should be installed
            Assert.True(File.Exists(packageASourceCodeInstalled), String.Concat("Should have found Package A payload installed at: ", packageASourceCodeInstalled));
            Assert.True(File.Exists(packageBv1SourceCodeInstalled), String.Concat("Should have found Package Bv1 payload installed at: ", packageBv1SourceCodeInstalled));
            Assert.True(File.Exists(packageCv1SourceCodeInstalled), String.Concat("Should have found Package Cv1 payload installed at: ", packageCv1SourceCodeInstalled));

            bundleAv2.Install();

            var bundleAv2Registration = bundleAv2.VerifyRegisteredAndInPackageCache();

            // Source file should be upgraded
            Assert.True(File.Exists(packageDSourceCodeInstalled), String.Concat("Should have found Package D payload installed at: ", packageDSourceCodeInstalled));
            Assert.True(File.Exists(packageBv2SourceCodeInstalled), String.Concat("Should have found Package Bv2 payload installed at: ", packageBv2SourceCodeInstalled));
            Assert.True(File.Exists(packageCv2SourceCodeInstalled), String.Concat("Should have found Package Cv2 payload installed at: ", packageCv2SourceCodeInstalled));
            Assert.False(File.Exists(packageCv1SourceCodeInstalled), String.Concat("Package Cv1 payload should have been removed by upgrade uninstall from: ", packageCv1SourceCodeInstalled));
            Assert.False(File.Exists(packageBv1SourceCodeInstalled), String.Concat("Package Bv1 payload should have been removed by upgrade uninstall from: ", packageBv1SourceCodeInstalled));
            Assert.False(File.Exists(packageASourceCodeInstalled), String.Concat("Package A payload should have been removed by upgrade uninstall from: ", packageASourceCodeInstalled));

            bundleAv1.VerifyUnregisteredAndRemovedFromPackageCache(bundleAv1Registration.CachePath);

            // Uninstall everything.
            bundleAv2.Uninstall();

            // Source file should *not* be installed
            Assert.False(File.Exists(packageDSourceCodeInstalled), String.Concat("Package D payload should have been removed by uninstall from: ", packageDSourceCodeInstalled));
            Assert.False(File.Exists(packageBv2SourceCodeInstalled), String.Concat("Package Bv2 payload should have been removed by uninstall from: ", packageBv2SourceCodeInstalled));
            Assert.False(File.Exists(packageCv2SourceCodeInstalled), String.Concat("Package Cv2 payload should have been removed by uninstall from: ", packageCv2SourceCodeInstalled));

            bundleAv2.VerifyUnregisteredAndRemovedFromPackageCache(bundleAv2Registration.CachePath);
        }

        /// <summary>
        /// Installs 2 bundles:
        ///   BundleBv1- installs package Bv1
        ///   BundleBv2- installs packages A, Bv2, F
        ///     package Bv2 performs a major upgrade of package Bv1
        ///     package F fails
        ///     Thus, rolling back the transaction should reinstall package Bv1
        /// </summary>
        [Fact]
        public void CanRelyOnMsiTransactionRollback()
        {
            var packageA = this.CreatePackageInstaller("PackageA");
            var packageBv1 = this.CreatePackageInstaller("PackageBv1");
            var packageBv2 = this.CreatePackageInstaller("PackageBv2");
            this.CreatePackageInstaller("PackageF");

            var bundleBv1 = this.CreateBundleInstaller("BundleBv1");
            var bundleBv2 = this.CreateBundleInstaller("BundleBv2");

            var packageASourceCodeInstalled = packageA.GetInstalledFilePath("Package.wxs");
            var packageBv1SourceCodeInstalled = packageBv1.GetInstalledFilePath("Package.wxs");
            var packageBv2SourceCodeInstalled = packageBv2.GetInstalledFilePath("Package.wxs");

            // Source file should *not* be installed
            Assert.False(File.Exists(packageASourceCodeInstalled), $"Package A payload should not be there on test start: {packageASourceCodeInstalled}");
            Assert.False(File.Exists(packageBv1SourceCodeInstalled), $"Package Bv1 payload should not be there on test start: {packageBv1SourceCodeInstalled}");
            Assert.False(File.Exists(packageBv2SourceCodeInstalled), $"Package Bv2 payload should not be there on test start: {packageBv2SourceCodeInstalled}");

            bundleBv1.Install();

            bundleBv1.VerifyRegisteredAndInPackageCache();

            // Source file should be installed
            Assert.True(File.Exists(packageBv1SourceCodeInstalled), String.Concat("Should have found Package Bv1 payload installed at: ", packageBv1SourceCodeInstalled));

            bundleBv2.Install((int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE);

            // Bundle v2 should be registered since it installed a non-permanent package.
            bundleBv2.VerifyRegisteredAndInPackageCache();

            // Bundle v1 should not have been removed since the install of v2 failed in the middle of the chain.
            bundleBv1.VerifyRegisteredAndInPackageCache();

            // Source file should be installed
            Assert.True(File.Exists(packageASourceCodeInstalled), String.Concat("Should have found Package A payload installed at: ", packageASourceCodeInstalled));

            // Previous source file should be installed
            Assert.True(File.Exists(packageBv1SourceCodeInstalled), String.Concat("Should have found Package Bv1 payload installed at: ", packageBv1SourceCodeInstalled));
            Assert.False(File.Exists(packageBv2SourceCodeInstalled), String.Concat("Should not have found Package Bv2 payload installed at: ", packageBv2SourceCodeInstalled));
        }
    }
}