| 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.CoreIntegration |
| 4 | { |
| 5 | using System.Collections.Generic; |
| 6 | using System.IO; |
| 7 | using System.Linq; |
| 8 | using System.Xml; |
| 9 | using WixInternal.TestSupport; |
| 10 | using WixInternal.Core.TestPackage; |
| 11 | using Xunit; |
| 12 | |
| 13 | public class RollbackBoundaryFixture |
| 14 | { |
| 15 | [Fact] |
| 16 | public void CanStartChainWithRollbackBoundary() |
| 17 | { |
| 18 | var folder = TestData.Get(@"TestData"); |
| 19 | |
| 20 | using (var fs = new DisposableFileSystem()) |
| 21 | { |
| 22 | var baseFolder = fs.GetFolder(); |
| 23 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 24 | var exePath = Path.Combine(baseFolder, @"bin\test.exe"); |
| 25 | |
| 26 | var result = WixRunner.Execute(new[] |
| 27 | { |
| 28 | "build", |
| 29 | Path.Combine(folder, "RollbackBoundary", "BeginningOfChain.wxs"), |
| 30 | Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), |
| 31 | Path.Combine(folder, "BundleWithPackageGroupRef", "MinimalPackageGroup.wxs"), |
| 32 | "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), |
| 33 | "-intermediateFolder", intermediateFolder, |
| 34 | "-o", exePath, |
| 35 | }); |
| 36 | |
| 37 | result.AssertSuccess(); |
| 38 | |
| 39 | Assert.True(File.Exists(exePath)); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | [Fact] |
| 44 | public void CannotHaveRollbackBoundaryAndChainPackageWithSameId() |
| 45 | { |
| 46 | var folder = TestData.Get(@"TestData"); |
| 47 | |
| 48 | using (var fs = new DisposableFileSystem()) |
| 49 | { |
| 50 | var baseFolder = fs.GetFolder(); |
| 51 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 52 | var exePath = Path.Combine(baseFolder, @"bin\test.exe"); |
| 53 | |
| 54 | var result = WixRunner.Execute(new[] |
| 55 | { |
| 56 | "build", |
| 57 | Path.Combine(folder, "RollbackBoundary", "SharedIdWithPackage.wxs"), |
| 58 | Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), |
| 59 | Path.Combine(folder, "BundleWithPackageGroupRef", "MinimalPackageGroup.wxs"), |
| 60 | "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), |
| 61 | "-intermediateFolder", intermediateFolder, |
| 62 | "-o", exePath, |
| 63 | }); |
| 64 | |
| 65 | Assert.Equal(92, result.ExitCode); |
| 66 | |
| 67 | WixAssert.CompareLineByLine(new[] |
| 68 | { |
| 69 | "Duplicate WixChainItem with identifier 'collision' found. Access modifiers (global, library, file, section) cannot prevent these conflicts. Ensure all your identifiers of a given type (Directory, File, etc.) are unique.", |
| 70 | "Location of symbol related to previous error.", |
| 71 | }, result.Messages.Select(m => m.ToString()).ToArray()); |
| 72 | |
| 73 | Assert.False(File.Exists(exePath)); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | [Fact] |
| 78 | public void DiscardsConsecutiveRollbackBoundaries() |
| 79 | { |
| 80 | var folder = TestData.Get(@"TestData"); |
| 81 | |
| 82 | using (var fs = new DisposableFileSystem()) |
| 83 | { |
| 84 | var baseFolder = fs.GetFolder(); |
| 85 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 86 | var exePath = Path.Combine(baseFolder, @"bin\test.exe"); |
| 87 | var baFolderPath = Path.Combine(baseFolder, "ba"); |
| 88 | var extractFolderPath = Path.Combine(baseFolder, "extract"); |
| 89 | |
| 90 | var result = WixRunner.Execute(false, new[] |
| 91 | { |
| 92 | "build", |
| 93 | Path.Combine(folder, "RollbackBoundary", "ConsecutiveRollbackBoundaries.wxs"), |
| 94 | Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), |
| 95 | Path.Combine(folder, "BundleWithPackageGroupRef", "MinimalPackageGroup.wxs"), |
| 96 | "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), |
| 97 | "-intermediateFolder", intermediateFolder, |
| 98 | "-o", exePath, |
| 99 | }); |
| 100 | |
| 101 | result.AssertSuccess(); |
| 102 | |
| 103 | WixAssert.CompareLineByLine(new[] |
| 104 | { |
| 105 | "The RollbackBoundary 'Second' was discarded because it was not followed by a package. Without a package the rollback boundary doesn't do anything. Verify that the RollbackBoundary element is not followed by another RollbackBoundary and that the element is not at the end of the chain.", |
| 106 | "Location of rollback boundary related to previous warning.", |
| 107 | }, result.Messages.Select(m => m.ToString()).ToArray()); |
| 108 | |
| 109 | Assert.True(File.Exists(exePath)); |
| 110 | |
| 111 | var extractResult = BundleExtractor.ExtractBAContainer(null, exePath, baFolderPath, extractFolderPath); |
| 112 | extractResult.AssertSuccess(); |
| 113 | |
| 114 | var rollbackBoundaries = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:RollbackBoundary"); |
| 115 | WixAssert.CompareLineByLine(new[] |
| 116 | { |
| 117 | "<RollbackBoundary Id='First' Vital='yes' Transaction='no' />", |
| 118 | }, rollbackBoundaries); |
| 119 | |
| 120 | var ignoreAttributesByElementName = new Dictionary<string, List<string>> |
| 121 | { |
| 122 | { "MsiPackage", new List<string> { "Size" } }, |
| 123 | }; |
| 124 | var chainPackages = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Chain/*", ignoreAttributesByElementName); |
| 125 | WixAssert.CompareLineByLine(new[] |
| 126 | { |
| 127 | "<MsiPackage Id='test.msi' Cache='keep' CacheId='{040011E1-F84C-4927-AD62-50A5EC19CA32}v1.0.0.0' InstallSize='34' Size='*' PerMachine='yes' Permanent='no' Vital='yes' RollbackBoundaryForward='First' RollbackBoundaryBackward='First' LogPathVariable='WixBundleLog_test.msi' RollbackLogPathVariable='WixBundleRollbackLog_test.msi' ProductCode='{040011E1-F84C-4927-AD62-50A5EC19CA32}' Language='1033' Version='1.0.0.0' UpgradeCode='{047730A5-30FE-4A62-A520-DA9381B8226A}'>" + |
| 128 | "<MsiProperty Id='ARPSYSTEMCOMPONENT' Value='1' />" + |
| 129 | "<MsiProperty Id='MSIFASTINSTALL' Value='7' />" + |
| 130 | "<Provides Key='{040011E1-F84C-4927-AD62-50A5EC19CA32}_v1.0.0.0' Version='1.0.0.0' DisplayName='MsiPackage' />" + |
| 131 | "<RelatedPackage Id='{047730A5-30FE-4A62-A520-DA9381B8226A}' MaxVersion='1.0.0.0' MaxInclusive='no' OnlyDetect='no' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" + |
| 132 | "<RelatedPackage Id='{047730A5-30FE-4A62-A520-DA9381B8226A}' MinVersion='1.0.0.0' MinInclusive='no' OnlyDetect='yes' LangInclusive='yes'><Language Id='1033' /></RelatedPackage>" + |
| 133 | "<PayloadRef Id='test.msi' />" + |
| 134 | "<PayloadRef Id='fhuZsOcBDTuIX8rF96kswqI6SnuI' />" + |
| 135 | "<PayloadRef Id='faf_OZ741BG7SJ6ZkcIvivZ2Yzo8' />" + |
| 136 | "</MsiPackage>", |
| 137 | }, chainPackages); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |