| 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; |
| 6 | using System.IO; |
| 7 | using System.Linq; |
| 8 | using WixInternal.Core.TestPackage; |
| 9 | using WixInternal.TestSupport; |
| 10 | using WixToolset.Data.WindowsInstaller; |
| 11 | using WixToolset.Dtf.WindowsInstaller; |
| 12 | using Xunit; |
| 13 | |
| 14 | public class InstanceTransformFixture |
| 15 | { |
| 16 | [Fact] |
| 17 | public void CanBuildInstanceTransform() |
| 18 | { |
| 19 | var folder = TestData.Get("TestData", "InstanceTransform"); |
| 20 | |
| 21 | using (var fs = new DisposableFileSystem()) |
| 22 | { |
| 23 | var intermediateFolder = fs.GetFolder(); |
| 24 | var msiPath = Path.Combine(intermediateFolder, "bin", "test.msi"); |
| 25 | var wixpdbPath = Path.Combine(intermediateFolder, "bin", "test.wixpdb"); |
| 26 | var mstPath = Path.Combine(intermediateFolder, "iii.mst"); |
| 27 | |
| 28 | var result = WixRunner.Execute(new[] |
| 29 | { |
| 30 | "build", |
| 31 | Path.Combine(folder, "Package.wxs"), |
| 32 | Path.Combine(folder, "PackageComponents.wxs"), |
| 33 | "-loc", Path.Combine(folder, "Package.en-us.wxl"), |
| 34 | "-bindpath", Path.Combine(folder, "data"), |
| 35 | "-intermediateFolder", intermediateFolder, |
| 36 | "-o", msiPath |
| 37 | }); |
| 38 | |
| 39 | result.AssertSuccess(); |
| 40 | |
| 41 | var output = WindowsInstallerData.Load(wixpdbPath, false); |
| 42 | var substorage = output.SubStorages.Single(); |
| 43 | Assert.Equal("I1", substorage.Name); |
| 44 | |
| 45 | var data = substorage.Data; |
| 46 | WixAssert.CompareLineByLine(new[] |
| 47 | { |
| 48 | "_SummaryInformation", |
| 49 | "Property", |
| 50 | "Upgrade" |
| 51 | }, data.Tables.Select(t => t.Name).ToArray()); |
| 52 | |
| 53 | WixAssert.CompareLineByLine(new[] |
| 54 | { |
| 55 | "INSTANCEPROPERTY\tI1", |
| 56 | "ProductName\tMsiPackage (Instance 1)", |
| 57 | }, JoinRows(data.Tables["Property"])); |
| 58 | |
| 59 | WixAssert.CompareLineByLine(new[] |
| 60 | { |
| 61 | "{22222222-2222-2222-2222-222222222222}\t\t1.0.0.0\t1033\t1\t\tWIX_UPGRADE_DETECTED", |
| 62 | "{11111111-1111-1111-1111-111111111111}\t\t1.0.0.0\t1033\t1\t0\t0", |
| 63 | "{22222222-2222-2222-2222-222222222222}\t1.0.0.0\t\t1033\t2\t\tWIX_DOWNGRADE_DETECTED", |
| 64 | "{11111111-1111-1111-1111-111111111111}\t1.0.0.0\t\t1033\t2\t0\t0", |
| 65 | }, JoinRows(data.Tables["Upgrade"])); |
| 66 | |
| 67 | var names = Query.GetSubStorageNames(msiPath); |
| 68 | Query.ExtractSubStorage(msiPath, "I1", mstPath); |
| 69 | |
| 70 | using (var db = new Database(msiPath, DatabaseOpenMode.Transact)) |
| 71 | { |
| 72 | db.ApplyTransform(mstPath); |
| 73 | |
| 74 | var results = Query.QueryDatabase(db, new[] { "Property", "Upgrade" }); |
| 75 | var resultsWithoutProductCode = results.Where(s => !s.StartsWith("Property:ProductCode\t{")).ToArray(); |
| 76 | WixAssert.CompareLineByLine(new[] |
| 77 | { |
| 78 | "Property:ALLUSERS\t1", |
| 79 | "Property:INSTANCEPROPERTY\tI1", |
| 80 | "Property:Manufacturer\tExample Corporation", |
| 81 | "Property:ProductLanguage\t1033", |
| 82 | "Property:ProductName\tMsiPackage (Instance 1)", |
| 83 | "Property:ProductVersion\t1.0.0.0", |
| 84 | "Property:SecureCustomProperties\tINSTANCEPROPERTY;WIX_DOWNGRADE_DETECTED;WIX_UPGRADE_DETECTED", |
| 85 | "Property:UpgradeCode\t{22222222-2222-2222-2222-222222222222}", |
| 86 | "Upgrade:{22222222-2222-2222-2222-222222222222}\t\t1.0.0.0\t1033\t1\t\tWIX_UPGRADE_DETECTED", |
| 87 | "Upgrade:{22222222-2222-2222-2222-222222222222}\t1.0.0.0\t\t1033\t2\t\tWIX_DOWNGRADE_DETECTED", |
| 88 | }, resultsWithoutProductCode); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | private static string[] JoinRows(Table table) |
| 94 | { |
| 95 | return table.Rows.Select(r => JoinFields(r.Fields)).ToArray(); |
| 96 | |
| 97 | static string JoinFields(Field[] fields) |
| 98 | { |
| 99 | return String.Join('\t', fields.Select(f => f.ToString())); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |