diff options
author | Nir Bar <nir.bar@panel-sw.co.il> | 2020-12-21 05:05:45 -0600 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2020-12-21 16:49:04 -0600 |
commit | d085e938317c80f62a3b484d20ed1a6cf89bb59d (patch) | |
tree | d993e2bf90bc754d62b9731981b3cb056e1bb7b9 | |
parent | 85deb61f666f6817c1a137ace4d666c8ae2940fb (diff) | |
download | wix-d085e938317c80f62a3b484d20ed1a6cf89bb59d.tar.gz wix-d085e938317c80f62a3b484d20ed1a6cf89bb59d.tar.bz2 wix-d085e938317c80f62a3b484d20ed1a6cf89bb59d.zip |
Add CanExtractBundleWithDetachedContainer test.
10 files changed, 130 insertions, 5 deletions
diff --git a/src/WixToolset.Core.Burn/BundleBackend.cs b/src/WixToolset.Core.Burn/BundleBackend.cs index 4a2f44b1..081e4464 100644 --- a/src/WixToolset.Core.Burn/BundleBackend.cs +++ b/src/WixToolset.Core.Burn/BundleBackend.cs | |||
@@ -62,8 +62,9 @@ namespace WixToolset.Core.Burn | |||
62 | { | 62 | { |
63 | var uxExtractPath = Path.Combine(context.ExportBasePath, "UX"); | 63 | var uxExtractPath = Path.Combine(context.ExportBasePath, "UX"); |
64 | var acExtractPath = Path.Combine(context.ExportBasePath, "AttachedContainer"); | 64 | var acExtractPath = Path.Combine(context.ExportBasePath, "AttachedContainer"); |
65 | var messaging = context.ServiceProvider.GetService<IMessaging>(); | ||
65 | 66 | ||
66 | using (var reader = BurnReader.Open(context.InputFilePath)) | 67 | using (var reader = BurnReader.Open(messaging, context.InputFilePath)) |
67 | { | 68 | { |
68 | reader.ExtractUXContainer(uxExtractPath, context.IntermediateFolder); | 69 | reader.ExtractUXContainer(uxExtractPath, context.IntermediateFolder); |
69 | reader.ExtractAttachedContainer(acExtractPath, context.IntermediateFolder); | 70 | reader.ExtractAttachedContainer(acExtractPath, context.IntermediateFolder); |
diff --git a/src/WixToolset.Core.TestPackage/BundleExtractor.cs b/src/WixToolset.Core.TestPackage/BundleExtractor.cs index ad97f113..8c9f31e6 100644 --- a/src/WixToolset.Core.TestPackage/BundleExtractor.cs +++ b/src/WixToolset.Core.TestPackage/BundleExtractor.cs | |||
@@ -45,6 +45,23 @@ namespace WixToolset.Core.TestPackage | |||
45 | } | 45 | } |
46 | 46 | ||
47 | /// <summary> | 47 | /// <summary> |
48 | /// Extracts the attached container. | ||
49 | /// </summary> | ||
50 | /// <param name="messaging"></param> | ||
51 | /// <param name="bundleFilePath">Path to the bundle.</param> | ||
52 | /// <param name="destinationFolderPath">Path to extract to.</param> | ||
53 | /// <param name="tempFolderPath">Temp path for extraction.</param> | ||
54 | /// <returns>True if there was an attached container.</returns> | ||
55 | public static bool ExtractAttachedContainer(IMessaging messaging, string bundleFilePath, string destinationFolderPath, string tempFolderPath) | ||
56 | { | ||
57 | Directory.CreateDirectory(tempFolderPath); | ||
58 | using (var burnReader = BurnReader.Open(messaging, bundleFilePath)) | ||
59 | { | ||
60 | return burnReader.ExtractAttachedContainer(destinationFolderPath, tempFolderPath); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
48 | /// Gets an <see cref="XmlNamespaceManager"/> for BootstrapperApplicationData.xml with the given prefix assigned to the root namespace. | 65 | /// Gets an <see cref="XmlNamespaceManager"/> for BootstrapperApplicationData.xml with the given prefix assigned to the root namespace. |
49 | /// </summary> | 66 | /// </summary> |
50 | /// <param name="document"></param> | 67 | /// <param name="document"></param> |
diff --git a/src/WixToolset.Core.TestPackage/WixRunnerResult.cs b/src/WixToolset.Core.TestPackage/WixRunnerResult.cs index 13e3a9e0..6a3d714c 100644 --- a/src/WixToolset.Core.TestPackage/WixRunnerResult.cs +++ b/src/WixToolset.Core.TestPackage/WixRunnerResult.cs | |||
@@ -28,10 +28,20 @@ namespace WixToolset.Core.TestPackage | |||
28 | /// <returns></returns> | 28 | /// <returns></returns> |
29 | public WixRunnerResult AssertSuccess() | 29 | public WixRunnerResult AssertSuccess() |
30 | { | 30 | { |
31 | Assert.True(0 == this.ExitCode, $"\r\n\r\nWixRunner failed with exit code: {this.ExitCode}\r\n Output: {String.Join("\r\n ", FormatMessages(this.Messages))}\r\n"); | 31 | AssertSuccess(this.ExitCode, this.Messages); |
32 | return this; | 32 | return this; |
33 | } | 33 | } |
34 | 34 | ||
35 | /// <summary> | ||
36 | /// | ||
37 | /// </summary> | ||
38 | /// <param name="exitCode"></param> | ||
39 | /// <param name="messages"></param> | ||
40 | public static void AssertSuccess(int exitCode, IEnumerable<Message> messages) | ||
41 | { | ||
42 | Assert.True(0 == exitCode, $"\r\n\r\nWixRunner failed with exit code: {exitCode}\r\n Output: {String.Join("\r\n ", FormatMessages(messages))}\r\n"); | ||
43 | } | ||
44 | |||
35 | private static IEnumerable<string> FormatMessages(IEnumerable<Message> messages) | 45 | private static IEnumerable<string> FormatMessages(IEnumerable<Message> messages) |
36 | { | 46 | { |
37 | foreach (var message in messages) | 47 | foreach (var message in messages) |
diff --git a/src/WixToolset.Core.WindowsInstaller/Unbinder.cs b/src/WixToolset.Core.WindowsInstaller/Unbinder.cs index a2f02269..99caaba9 100644 --- a/src/WixToolset.Core.WindowsInstaller/Unbinder.cs +++ b/src/WixToolset.Core.WindowsInstaller/Unbinder.cs | |||
@@ -11,8 +11,16 @@ namespace WixToolset.Core | |||
11 | /// <summary> | 11 | /// <summary> |
12 | /// Unbinder core of the WiX toolset. | 12 | /// Unbinder core of the WiX toolset. |
13 | /// </summary> | 13 | /// </summary> |
14 | internal sealed class Unbinder | 14 | internal sealed class Unbinder : IUnbinder |
15 | { | 15 | { |
16 | public Unbinder(IWixToolsetServiceProvider serviceProvider) | ||
17 | { | ||
18 | this.ServiceProvider = serviceProvider; | ||
19 | |||
20 | var extensionManager = this.ServiceProvider.GetService<IExtensionManager>(); | ||
21 | this.BackendFactories = extensionManager.GetServices<IBackendFactory>(); | ||
22 | } | ||
23 | |||
16 | public IEnumerable<IBackendFactory> BackendFactories { get; } | 24 | public IEnumerable<IBackendFactory> BackendFactories { get; } |
17 | 25 | ||
18 | /// <summary> | 26 | /// <summary> |
diff --git a/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs b/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs index c69f1af1..e013cefb 100644 --- a/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs +++ b/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs | |||
@@ -31,6 +31,7 @@ namespace WixToolset.Core.WindowsInstaller | |||
31 | { | 31 | { |
32 | // Singletons. | 32 | // Singletons. |
33 | coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerBackendHelper>(singletons, new WindowsInstallerBackendHelper())); | 33 | coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerBackendHelper>(singletons, new WindowsInstallerBackendHelper())); |
34 | coreProvider.AddService<IUnbinder>((provider, singletons) => new Unbinder(provider)); | ||
34 | } | 35 | } |
35 | 36 | ||
36 | private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service) where T : class | 37 | private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service) where T : class |
diff --git a/src/WixToolset.Core/Compiler_Bundle.cs b/src/WixToolset.Core/Compiler_Bundle.cs index 86fec16e..b8386138 100644 --- a/src/WixToolset.Core/Compiler_Bundle.cs +++ b/src/WixToolset.Core/Compiler_Bundle.cs | |||
@@ -566,9 +566,17 @@ namespace WixToolset.Core | |||
566 | break; | 566 | break; |
567 | case "Type": | 567 | case "Type": |
568 | var typeString = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 568 | var typeString = this.Core.GetAttributeValue(sourceLineNumbers, attrib); |
569 | if (!Enum.TryParse<ContainerType>(typeString, out type)) | 569 | switch (typeString) |
570 | { | 570 | { |
571 | this.Core.Write(ErrorMessages.IllegalAttributeValueWithLegalList(sourceLineNumbers, node.Name.LocalName, "Type", typeString, "attached, detached")); | 571 | case "attached": |
572 | type = ContainerType.Attached; | ||
573 | break; | ||
574 | case "detached": | ||
575 | type = ContainerType.Detached; | ||
576 | break; | ||
577 | default: | ||
578 | this.Core.Write(ErrorMessages.IllegalAttributeValueWithLegalList(sourceLineNumbers, node.Name.LocalName, "Type", typeString, "attached, detached")); | ||
579 | break; | ||
572 | } | 580 | } |
573 | break; | 581 | break; |
574 | default: | 582 | default: |
diff --git a/src/WixToolset.Core/IUnbinder.cs b/src/WixToolset.Core/IUnbinder.cs new file mode 100644 index 00000000..2b4daaa5 --- /dev/null +++ b/src/WixToolset.Core/IUnbinder.cs | |||
@@ -0,0 +1,12 @@ | |||
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 WixToolset.Core | ||
4 | { | ||
5 | using WixToolset.Data; | ||
6 | |||
7 | #pragma warning disable 1591 // TODO: add documentation, move into Extensibility | ||
8 | public interface IUnbinder | ||
9 | { | ||
10 | Intermediate Unbind(string file, OutputType outputType, string exportBasePath); | ||
11 | } | ||
12 | } | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs new file mode 100644 index 00000000..5c37c25b --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs | |||
@@ -0,0 +1,57 @@ | |||
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.IO; | ||
6 | using System.Linq; | ||
7 | using WixBuildTools.TestSupport; | ||
8 | using WixToolset.Core; | ||
9 | using WixToolset.Core.TestPackage; | ||
10 | using WixToolset.Data; | ||
11 | using Xunit; | ||
12 | |||
13 | public class BundleExtractionFixture | ||
14 | { | ||
15 | [Fact] | ||
16 | public void CanExtractBundleWithDetachedContainer() | ||
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 | var pdbPath = Path.Combine(baseFolder, @"bin\test.wixpdb"); | ||
26 | var extractFolderPath = Path.Combine(baseFolder, "extract"); | ||
27 | var baFolderPath = Path.Combine(extractFolderPath, "UX"); | ||
28 | var attachedContainerFolderPath = Path.Combine(extractFolderPath, "AttachedContainer"); | ||
29 | |||
30 | // TODO: use WixRunner.Execute(string[]) to always go through the command line. | ||
31 | var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); | ||
32 | var result = WixRunner.Execute(new[] | ||
33 | { | ||
34 | "build", | ||
35 | Path.Combine(folder, "BundleWithDetachedContainer", "Bundle.wxs"), | ||
36 | Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), | ||
37 | Path.Combine(folder, "BundleWithPackageGroupRef", "MinimalPackageGroup.wxs"), | ||
38 | "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), | ||
39 | "-bindpath", Path.Combine(folder, ".Data"), | ||
40 | "-intermediateFolder", intermediateFolder, | ||
41 | "-o", exePath, | ||
42 | }, serviceProvider, out var messages).Result; | ||
43 | |||
44 | WixRunnerResult.AssertSuccess(result, messages); | ||
45 | Assert.Empty(messages.Where(m => m.Level == MessageLevel.Warning)); | ||
46 | |||
47 | Assert.True(File.Exists(exePath)); | ||
48 | |||
49 | var unbinder = serviceProvider.GetService<IUnbinder>(); | ||
50 | unbinder.Unbind(exePath, OutputType.Bundle, extractFolderPath); | ||
51 | |||
52 | Assert.True(File.Exists(Path.Combine(baFolderPath, "manifest.xml"))); | ||
53 | Assert.False(Directory.Exists(attachedContainerFolderPath)); | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | } | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs new file mode 100644 index 00000000..a93b23ef --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs | |||
@@ -0,0 +1,10 @@ | |||
1 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | ||
2 | <Fragment> | ||
3 | <PackageGroup Id="BundlePackages"> | ||
4 | <PackageGroupRef Id="MinimalPackageGroup"/> | ||
5 | </PackageGroup> | ||
6 | <Container Id="_1" Type="detached"> | ||
7 | <PackageGroupRef Id="MinimalPackageGroup"/> | ||
8 | </Container> | ||
9 | </Fragment> | ||
10 | </Wix> \ No newline at end of file | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj index a38e89ce..918635e9 100644 --- a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj +++ b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj | |||
@@ -32,6 +32,7 @@ | |||
32 | <Content Include="TestData\BundleExtension\BundleExtensionSearches.wxs" CopyToOutputDirectory="PreserveNewest" /> | 32 | <Content Include="TestData\BundleExtension\BundleExtensionSearches.wxs" CopyToOutputDirectory="PreserveNewest" /> |
33 | <Content Include="TestData\BundleExtension\BundleWithSearches.wxs" CopyToOutputDirectory="PreserveNewest" /> | 33 | <Content Include="TestData\BundleExtension\BundleWithSearches.wxs" CopyToOutputDirectory="PreserveNewest" /> |
34 | <Content Include="TestData\BundleExtension\SimpleBundleExtension.wxs" CopyToOutputDirectory="PreserveNewest" /> | 34 | <Content Include="TestData\BundleExtension\SimpleBundleExtension.wxs" CopyToOutputDirectory="PreserveNewest" /> |
35 | <Content Include="TestData\BundleWithDetachedContainer\Bundle.wxs" CopyToOutputDirectory="PreserveNewest" /> | ||
35 | <Content Include="TestData\BundleWithPackageGroupRef\Bundle.wxs" CopyToOutputDirectory="PreserveNewest" /> | 36 | <Content Include="TestData\BundleWithPackageGroupRef\Bundle.wxs" CopyToOutputDirectory="PreserveNewest" /> |
36 | <Content Include="TestData\BundleWithPackageGroupRef\MinimalPackageGroup.wxs" CopyToOutputDirectory="PreserveNewest" /> | 37 | <Content Include="TestData\BundleWithPackageGroupRef\MinimalPackageGroup.wxs" CopyToOutputDirectory="PreserveNewest" /> |
37 | <Content Include="TestData\Class\DecompiledOldClassTableDef.wxs" CopyToOutputDirectory="PreserveNewest" /> | 38 | <Content Include="TestData\Class\DecompiledOldClassTableDef.wxs" CopyToOutputDirectory="PreserveNewest" /> |