// 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 WixToolset.Core.TestPackage { using System.IO; using System.Xml; using Xunit; /// /// The result of extracting the BA container. /// public class ExtractBAContainerResult { /// /// for BundleExtensionData.xml. /// public XmlDocument BundleExtensionDataDocument { get; set; } /// /// for BundleExtensionData.xml. /// public XmlNamespaceManager BundleExtensionDataNamespaceManager { get; set; } /// /// for BootstrapperApplicationData.xml. /// public XmlDocument BADataDocument { get; set; } /// /// for BootstrapperApplicationData.xml. /// public XmlNamespaceManager BADataNamespaceManager { get; set; } /// /// for the Burn manifest.xml. /// public XmlDocument ManifestDocument { get; set; } /// /// for the Burn manifest.xml. /// public XmlNamespaceManager ManifestNamespaceManager { get; set; } /// /// Whether extraction succeeded. /// public bool Success { get; set; } /// /// /// /// public ExtractBAContainerResult AssertSuccess() { Assert.True(this.Success); return this; } /// /// Returns the relative path of the BA entry point dll in the given folder. /// /// /// public string GetBAFilePath(string extractedBAContainerFolderPath) { var uxPayloads = this.SelectManifestNodes("/burn:BurnManifest/burn:UX/burn:Payload"); var baPayload = uxPayloads[0]; var relativeBAPath = baPayload.Attributes["FilePath"].Value; return Path.Combine(extractedBAContainerFolderPath, relativeBAPath); } /// /// Returns the relative path of the BundleExtension entry point dll in the given folder. /// /// /// /// public string GetBundleExtensionFilePath(string extractedBAContainerFolderPath, string extensionId) { var uxPayloads = this.SelectManifestNodes($"/burn:BurnManifest/burn:UX/burn:Payload[@Id='{extensionId}']"); var bextPayload = uxPayloads[0]; var relativeBextPath = bextPayload.Attributes["FilePath"].Value; return Path.Combine(extractedBAContainerFolderPath, relativeBextPath); } /// /// /// /// elements must have the 'ba' prefix /// public XmlNodeList SelectBADataNodes(string xpath) { return this.BADataDocument.SelectNodes(xpath, this.BADataNamespaceManager); } /// /// /// /// elements must have the 'be' prefix /// public XmlNodeList SelectBundleExtensionDataNodes(string xpath) { return this.BundleExtensionDataDocument.SelectNodes(xpath, this.BundleExtensionDataNamespaceManager); } /// /// /// /// elements must have the 'burn' prefix /// public XmlNodeList SelectManifestNodes(string xpath) { return this.ManifestDocument.SelectNodes(xpath, this.ManifestNamespaceManager); } } }