| 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 WixInternal.Core.TestPackage |
| 4 | { |
| 5 | using System.Collections.Generic; |
| 6 | using System.IO; |
| 7 | using System.Xml; |
| 8 | using Xunit; |
| 9 | |
| 10 | /// <summary> |
| 11 | /// The result of extracting the BA container. |
| 12 | /// </summary> |
| 13 | public class ExtractBAContainerResult |
| 14 | { |
| 15 | /// <summary> |
| 16 | /// <see cref="XmlDocument"/> for BootstrapperExtensionData.xml. |
| 17 | /// </summary> |
| 18 | public XmlDocument BootstrapperExtensionDataDocument { get; set; } |
| 19 | |
| 20 | /// <summary> |
| 21 | /// <see cref="XmlNamespaceManager"/> for BootstrapperExtensionData.xml. |
| 22 | /// </summary> |
| 23 | public XmlNamespaceManager BootstrapperExtensionDataNamespaceManager { get; set; } |
| 24 | |
| 25 | /// <summary> |
| 26 | /// <see cref="XmlDocument"/> for BootstrapperApplicationData.xml. |
| 27 | /// </summary> |
| 28 | public XmlDocument BADataDocument { get; set; } |
| 29 | |
| 30 | /// <summary> |
| 31 | /// <see cref="XmlNamespaceManager"/> for BootstrapperApplicationData.xml. |
| 32 | /// </summary> |
| 33 | public XmlNamespaceManager BADataNamespaceManager { get; set; } |
| 34 | |
| 35 | /// <summary> |
| 36 | /// <see cref="XmlDocument"/> for the Burn manifest.xml. |
| 37 | /// </summary> |
| 38 | public XmlDocument ManifestDocument { get; set; } |
| 39 | |
| 40 | /// <summary> |
| 41 | /// <see cref="XmlNamespaceManager"/> for the Burn manifest.xml. |
| 42 | /// </summary> |
| 43 | public XmlNamespaceManager ManifestNamespaceManager { get; set; } |
| 44 | |
| 45 | /// <summary> |
| 46 | /// Whether extraction succeeded. |
| 47 | /// </summary> |
| 48 | public bool Success { get; set; } |
| 49 | |
| 50 | /// <summary> |
| 51 | /// Whether attached containers extraction succeeded. |
| 52 | /// </summary> |
| 53 | public bool? AttachedContainersSuccess { get; set; } |
| 54 | |
| 55 | /// <summary> |
| 56 | /// |
| 57 | /// </summary> |
| 58 | /// <returns></returns> |
| 59 | public ExtractBAContainerResult AssertSuccess() |
| 60 | { |
| 61 | Assert.True(this.Success); |
| 62 | Assert.True(!this.AttachedContainersSuccess.HasValue || this.AttachedContainersSuccess.Value); |
| 63 | return this; |
| 64 | } |
| 65 | |
| 66 | /// <summary> |
| 67 | /// Returns the relative path of the BA entry point dll in the given folder. |
| 68 | /// </summary> |
| 69 | /// <param name="extractedBAContainerFolderPath"></param> |
| 70 | /// <returns></returns> |
| 71 | public string GetBAFilePath(string extractedBAContainerFolderPath) |
| 72 | { |
| 73 | var uxPayloads = this.SelectManifestNodes("/burn:BurnManifest/burn:UX/burn:Payload"); |
| 74 | var baPayload = uxPayloads[0]; |
| 75 | var relativeBAPath = baPayload.Attributes["FilePath"].Value; |
| 76 | return Path.Combine(extractedBAContainerFolderPath, relativeBAPath); |
| 77 | } |
| 78 | |
| 79 | /// <summary> |
| 80 | /// Returns the relative path of the BootstrapperExtension entry point dll in the given folder. |
| 81 | /// </summary> |
| 82 | /// <param name="extractedBAContainerFolderPath"></param> |
| 83 | /// <param name="extensionId"></param> |
| 84 | /// <returns></returns> |
| 85 | public string GetBootstrapperExtensionFilePath(string extractedBAContainerFolderPath, string extensionId) |
| 86 | { |
| 87 | var uxPayloads = this.SelectManifestNodes($"/burn:BurnManifest/burn:UX/burn:Payload[@Id='{extensionId}']"); |
| 88 | var bextPayload = uxPayloads[0]; |
| 89 | var relativeBextPath = bextPayload.Attributes["FilePath"].Value; |
| 90 | return Path.Combine(extractedBAContainerFolderPath, relativeBextPath); |
| 91 | } |
| 92 | |
| 93 | /// <summary> |
| 94 | /// |
| 95 | /// </summary> |
| 96 | /// <param name="xpath">elements must have the 'ba' prefix</param> |
| 97 | /// <returns></returns> |
| 98 | public XmlNodeList SelectBADataNodes(string xpath) |
| 99 | { |
| 100 | return this.BADataDocument.SelectNodes(xpath, this.BADataNamespaceManager); |
| 101 | } |
| 102 | |
| 103 | /// <summary> |
| 104 | /// |
| 105 | /// </summary> |
| 106 | /// <param name="xpath">elements must have the 'ba' prefix</param> |
| 107 | /// <param name="ignoredAttributesByElementName">Attributes for which the value should be set to '*'.</param> |
| 108 | /// <returns></returns> |
| 109 | public string[] GetBADataTestXmlLines(string xpath, Dictionary<string, List<string>> ignoredAttributesByElementName = null) |
| 110 | { |
| 111 | return this.SelectBADataNodes(xpath).GetTestXmlLines(ignoredAttributesByElementName); |
| 112 | } |
| 113 | |
| 114 | /// <summary> |
| 115 | /// |
| 116 | /// </summary> |
| 117 | /// <param name="xpath">elements must have the 'be' prefix</param> |
| 118 | /// <returns></returns> |
| 119 | public XmlNodeList SelectBootstrapperExtensionDataNodes(string xpath) |
| 120 | { |
| 121 | return this.BootstrapperExtensionDataDocument.SelectNodes(xpath, this.BootstrapperExtensionDataNamespaceManager); |
| 122 | } |
| 123 | |
| 124 | /// <summary> |
| 125 | /// |
| 126 | /// </summary> |
| 127 | /// <param name="xpath">elements must have the 'be' prefix</param> |
| 128 | /// <param name="ignoredAttributesByElementName">Attributes for which the value should be set to '*'.</param> |
| 129 | /// <returns></returns> |
| 130 | public string[] GetBootstrapperExtensionTestXmlLines(string xpath, Dictionary<string, List<string>> ignoredAttributesByElementName = null) |
| 131 | { |
| 132 | return this.SelectBootstrapperExtensionDataNodes(xpath).GetTestXmlLines(ignoredAttributesByElementName); |
| 133 | } |
| 134 | |
| 135 | /// <summary> |
| 136 | /// |
| 137 | /// </summary> |
| 138 | /// <param name="xpath">elements must have the 'burn' prefix</param> |
| 139 | /// <returns></returns> |
| 140 | public XmlNodeList SelectManifestNodes(string xpath) |
| 141 | { |
| 142 | return this.ManifestDocument.SelectNodes(xpath, this.ManifestNamespaceManager); |
| 143 | } |
| 144 | |
| 145 | /// <summary> |
| 146 | /// |
| 147 | /// </summary> |
| 148 | /// <param name="xpath">elements must have the 'burn' prefix</param> |
| 149 | /// <param name="ignoredAttributesByElementName">Attributes for which the value should be set to '*'.</param> |
| 150 | /// <returns></returns> |
| 151 | public string[] GetManifestTestXmlLines(string xpath, Dictionary<string, List<string>> ignoredAttributesByElementName = null) |
| 152 | { |
| 153 | return this.SelectManifestNodes(xpath).GetTestXmlLines(ignoredAttributesByElementName); |
| 154 | } |
| 155 | } |
| 156 | } |