aboutsummaryrefslogtreecommitdiff
path: root/src/test/burn/WixToolsetTest.BurnE2E/FilesInUseTests.cs
blob: 1b2356e394dd08a1a46c96523e64e2034c0e1a74 (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
// 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.IO;
    using WixTestTools;
    using Xunit.Abstractions;

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

        [RuntimeFact]
        public void CanCancelInstallAfterRetryingLockedFile()
        {
            var packageA = this.CreatePackageInstaller("PackageA");
            var bundleA = this.CreateBundleInstaller("BundleA");
            var testBAController = this.CreateTestBAController();

            testBAController.SetPackageRetryExecuteFilesInUse("PackageA", 1);

            packageA.VerifyInstalled(false);

            // Lock the file that will be installed.
            string targetInstallFile = packageA.GetInstalledFilePath("Package.wxs");
            Directory.CreateDirectory(Path.GetDirectoryName(targetInstallFile));
            using (FileStream lockTargetFile = new FileStream(targetInstallFile, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.DeleteOnClose))
            {
                bundleA.Install(expectedExitCode: (int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_USEREXIT);
            }

            bundleA.VerifyUnregisteredAndRemovedFromPackageCache();

            packageA.VerifyInstalled(false);
        }

        [LongRuntimeFact]
        public void WixStdBAFailsWithLockedFile()
        {
            var packageA = this.CreatePackageInstaller("PackageA");
            var bundleA = this.CreateBundleInstaller("WixStdBaBundle");

            packageA.VerifyInstalled(false);

            bundleA.Install();

            packageA.VerifyInstalled(true);

            // Lock the file that will be uninstalled.
            var targetInstallFile = packageA.GetInstalledFilePath("Package.wxs");
            using (var lockTargetFile = new FileStream(targetInstallFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
            {
                bundleA.Uninstall(expectedExitCode: (int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE);
            }
        }
    }
}