| 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.BurnE2E |
| 4 | { |
| 5 | using System.IO; |
| 6 | using WixTestTools; |
| 7 | using Xunit.Abstractions; |
| 8 | |
| 9 | public class FilesInUseTests : BurnE2ETests |
| 10 | { |
| 11 | public FilesInUseTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } |
| 12 | |
| 13 | [RuntimeFact] |
| 14 | public void CanCancelInstallAfterRetryingLockedFile() |
| 15 | { |
| 16 | var packageA = this.CreatePackageInstaller("PackageA"); |
| 17 | var bundleA = this.CreateBundleInstaller("BundleA"); |
| 18 | var testBAController = this.CreateTestBAController(); |
| 19 | |
| 20 | testBAController.SetPackageRetryExecuteFilesInUse("PackageA", 1); |
| 21 | |
| 22 | packageA.VerifyInstalled(false); |
| 23 | |
| 24 | // Lock the file that will be installed. |
| 25 | string targetInstallFile = packageA.GetInstalledFilePath("Package.wxs"); |
| 26 | Directory.CreateDirectory(Path.GetDirectoryName(targetInstallFile)); |
| 27 | using (FileStream lockTargetFile = new FileStream(targetInstallFile, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.DeleteOnClose)) |
| 28 | { |
| 29 | bundleA.Install(expectedExitCode: (int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_USEREXIT); |
| 30 | } |
| 31 | |
| 32 | bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); |
| 33 | |
| 34 | packageA.VerifyInstalled(false); |
| 35 | } |
| 36 | |
| 37 | [LongRuntimeFact] |
| 38 | public void WixStdBAFailsWithLockedFile() |
| 39 | { |
| 40 | var packageA = this.CreatePackageInstaller("PackageA"); |
| 41 | var bundleA = this.CreateBundleInstaller("WixStdBaBundle"); |
| 42 | |
| 43 | packageA.VerifyInstalled(false); |
| 44 | |
| 45 | bundleA.Install(); |
| 46 | |
| 47 | packageA.VerifyInstalled(true); |
| 48 | |
| 49 | // Lock the file that will be uninstalled. |
| 50 | var targetInstallFile = packageA.GetInstalledFilePath("Package.wxs"); |
| 51 | using (var lockTargetFile = new FileStream(targetInstallFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) |
| 52 | { |
| 53 | bundleA.Uninstall(expectedExitCode: (int)MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |