Add CanExtractBundleWithDetachedContainer test.
Nir Bar committed
Dec 21, 2020 at 05:05 UTC
d085e938317c80f62a3b484d20ed1a6cf89bb59d
10 files changed
+130
-5
src/WixToolset.Core.Burn/BundleBackend.cs
+2
-1
@@ -62,8 +62,9 @@ namespace WixToolset.Core.Burn
62
{
63
var uxExtractPath = Path.Combine(context.ExportBasePath, "UX");
64
var acExtractPath = Path.Combine(context.ExportBasePath, "AttachedContainer");
65
+ var messaging = context.ServiceProvider.GetService<IMessaging>();
66
66
- using (var reader = BurnReader.Open(context.InputFilePath))
67
+ using (var reader = BurnReader.Open(messaging, context.InputFilePath))
68
{
69
reader.ExtractUXContainer(uxExtractPath, context.IntermediateFolder);
70
reader.ExtractAttachedContainer(acExtractPath, context.IntermediateFolder);
src/WixToolset.Core.TestPackage/BundleExtractor.cs
+17
@@ -44,6 +44,23 @@ namespace WixToolset.Core.TestPackage
44
return result;
45
}
46
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>
65
/// Gets an <see cref="XmlNamespaceManager"/> for BootstrapperApplicationData.xml with the given prefix assigned to the root namespace.
66
/// </summary>
src/WixToolset.Core.TestPackage/WixRunnerResult.cs
+11
-1
@@ -28,10 +28,20 @@ namespace WixToolset.Core.TestPackage
28
/// <returns></returns>
29
public WixRunnerResult AssertSuccess()
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;
33
}
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
+
45
private static IEnumerable<string> FormatMessages(IEnumerable<Message> messages)
46
{
47
foreach (var message in messages)
src/WixToolset.Core.WindowsInstaller/Unbinder.cs
+9
-1
@@ -11,8 +11,16 @@ namespace WixToolset.Core
11
/// <summary>
12
/// Unbinder core of the WiX toolset.
13
/// </summary>
14
- internal sealed class Unbinder
14
+ internal sealed class Unbinder : IUnbinder
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
+
24
public IEnumerable<IBackendFactory> BackendFactories { get; }
25
26
/// <summary>
src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs
+1
@@ -31,6 +31,7 @@ namespace WixToolset.Core.WindowsInstaller
31
{
32
// Singletons.
33
coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerBackendHelper>(singletons, new WindowsInstallerBackendHelper()));
34
+ coreProvider.AddService<IUnbinder>((provider, singletons) => new Unbinder(provider));
35
}
36
37
private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service) where T : class
src/WixToolset.Core/Compiler_Bundle.cs
+10
-2
@@ -566,9 +566,17 @@ namespace WixToolset.Core
566
break;
567
case "Type":
568
var typeString = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
569
- if (!Enum.TryParse<ContainerType>(typeString, out type))
569
+ switch (typeString)
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;
580
}
581
break;
582
default:
src/WixToolset.Core/IUnbinder.cs
new
+12
@@ -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
+}
src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs
new
+57
@@ -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
+}
src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs
new
+10
@@ -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
src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj
+1
@@ -32,6 +32,7 @@
32
<Content Include="TestData\BundleExtension\BundleExtensionSearches.wxs" CopyToOutputDirectory="PreserveNewest" />
33
<Content Include="TestData\BundleExtension\BundleWithSearches.wxs" CopyToOutputDirectory="PreserveNewest" />
34
<Content Include="TestData\BundleExtension\SimpleBundleExtension.wxs" CopyToOutputDirectory="PreserveNewest" />
35
+ <Content Include="TestData\BundleWithDetachedContainer\Bundle.wxs" CopyToOutputDirectory="PreserveNewest" />
36
<Content Include="TestData\BundleWithPackageGroupRef\Bundle.wxs" CopyToOutputDirectory="PreserveNewest" />
37
<Content Include="TestData\BundleWithPackageGroupRef\MinimalPackageGroup.wxs" CopyToOutputDirectory="PreserveNewest" />
38
<Content Include="TestData\Class\DecompiledOldClassTableDef.wxs" CopyToOutputDirectory="PreserveNewest" />