Skip to content

Commit

Permalink
Add basic test for Msmq install/uninstall.
Browse files Browse the repository at this point in the history
Fix up lack of WIX CUSTOM_ACTION_DECORATION wrappers

Add new RuntimeTest skipper for Server Features / Optional Features.


Signed-off-by: Bevan Weiss <[email protected]>
  • Loading branch information
bevanweiss committed Jul 18, 2024
1 parent 733886e commit b4cb6f1
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ext/Msmq/ca/mqsched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern "C" UINT __stdcall MessageQueuingInstall(MSIHANDLE hInstall)
hr = MqiMessageQueueInstall(&lstMessageQueues, TRUE, &pwzRollbackActionData);
ExitOnFailure(hr, "Failed to add message queues to rollback action data");

hr = WcaDoDeferredAction(L"MessageQueuingRollbackInstall", pwzRollbackActionData, 0);
hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"MessageQueuingRollbackInstall"), pwzRollbackActionData, 0);
ExitOnFailure(hr, "Failed to schedule MessageQueuingRollbackInstall");

// schedule execute action
Expand All @@ -80,7 +80,7 @@ extern "C" UINT __stdcall MessageQueuingInstall(MSIHANDLE hInstall)
ExitOnFailure(hr, "Failed to add message queue permissions to execute action data");
iCost += lstMessageQueues.iInstallCount * COST_MESSAGE_QUEUE_PERMISSION_ADD;

hr = WcaDoDeferredAction(L"MessageQueuingExecuteInstall", pwzExecuteActionData, iCost);
hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"MessageQueuingExecuteInstall"), pwzExecuteActionData, iCost);
ExitOnFailure(hr, "Failed to schedule MessageQueuingExecuteInstall");
}

Expand Down Expand Up @@ -163,7 +163,7 @@ extern "C" UINT __stdcall MessageQueuingUninstall(MSIHANDLE hInstall)
hr = MqiMessageQueuePermissionUninstall(&lstMessageQueuePermissions, &pwzRollbackActionData);
ExitOnFailure(hr, "Failed to add message queue permissions to rollback action data");

hr = WcaDoDeferredAction(L"MessageQueuingRollbackUninstall", pwzRollbackActionData, 0);
hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"MessageQueuingRollbackUninstall"), pwzRollbackActionData, 0);
ExitOnFailure(hr, "Failed to schedule MessageQueuingRollbackUninstall");

// schedule execute action
Expand All @@ -174,7 +174,7 @@ extern "C" UINT __stdcall MessageQueuingUninstall(MSIHANDLE hInstall)
ExitOnFailure(hr, "Failed to add message queues to execute action data");
iCost += lstMessageQueues.iUninstallCount * COST_MESSAGE_QUEUE_DELETE;

hr = WcaDoDeferredAction(L"MessageQueuingExecuteUninstall", pwzExecuteActionData, iCost);
hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"MessageQueuingExecuteUninstall"), pwzExecuteActionData, iCost);
ExitOnFailure(hr, "Failed to schedule MessageQueuingExecuteUninstall");
}

Expand Down
2 changes: 2 additions & 0 deletions src/ext/Msmq/ca/precomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
#include "mqqueuesched.h"
#include "mqutilexec.h"
#include "mqqueueexec.h"

#include "..\..\caDecor.h"
2 changes: 2 additions & 0 deletions src/internal/SetBuildNumber/Directory.Packages.props.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
<PackageVersion Include="WixToolset.UI.wixext" Version="{packageversion}" />
<PackageVersion Include="WixToolset.Util.wixext" Version="{packageversion}" />
<PackageVersion Include="WixToolset.Firewall.wixext" Version="{packageversion}" />
<PackageVersion Include="WixToolset.Msmq.wixext" Version="{packageversion}" />
</ItemGroup>

<ItemGroup>
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="4.7.0" />
<PackageVersion Include="System.DirectoryServices" Version="4.7.0" />
<PackageVersion Include="System.DirectoryServices.AccountManagement" Version="4.7.0" />
<PackageVersion Include="System.Management" Version="4.7.0" />
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="4.7.0" />
<PackageVersion Include="System.Net.NetworkInformation" Version="4.3.0" />
Expand Down
56 changes: 56 additions & 0 deletions src/test/burn/WixTestTools/RuntimePrereqFeatureFactAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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 WixTestTools
{
using System;
using System.Globalization;
using System.Linq;
using System.Management;
using System.Collections.Generic;
using System.Security.Principal;
using WixInternal.TestSupport.XunitExtensions;

public class RuntimePrereqFeatureFactAttribute : RuntimeFactAttribute
{
public static HashSet<string> OptionalFeatures = new(StringComparer.OrdinalIgnoreCase);
public static HashSet<string> ServerFeatures = new(StringComparer.OrdinalIgnoreCase);
static RuntimePrereqFeatureFactAttribute()
{
AddFeaturesToSet(ServerFeatures, "Win32_ServerFeature");
AddFeaturesToSet(OptionalFeatures, "Win32_OptionalFeature");
}

private static void AddFeaturesToSet(HashSet<string> featureSet, string featureSetName)
{
try
{
var objMC = new ManagementClass(featureSetName);
var objMOC = objMC?.GetInstances();
if (objMOC is not null)
{
foreach (var objMO in objMOC)
{
string featureName = (string)objMO.Properties["Name"].Value;
if ((uint)objMO.Properties["InstallState"].Value == 1)
{
featureSet.Add(featureName);
}
}
}
}
catch
{
}
}

public RuntimePrereqFeatureFactAttribute(params string[] prerequisiteFeatures) : base()
{
var missingRequirements = prerequisiteFeatures.Select(x => x).Where(x => !ServerFeatures.Contains(x) && !OptionalFeatures.Contains(x));

if (missingRequirements.Any())
{
this.Skip = "This test is missing the following Feature pre-requisites: " + String.Join(", ", missingRequirements);
}
}
}
}
1 change: 1 addition & 0 deletions src/test/burn/WixTestTools/WixTestTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="Microsoft.Win32.Registry" />
<PackageReference Include="System.DirectoryServices" />
<PackageReference Include="System.DirectoryServices.AccountManagement" />
<PackageReference Include="System.Management" />
<PackageReference Include="System.Security.Principal.Windows" />
<PackageReference Include="WixInternal.TestSupport" />
<PackageReference Include="WixToolset.Data" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<UpgradeCode>{A75B81F4-3335-4B4D-B766-303E136ED374}</UpgradeCode>
<ProductComponentsRef>true</ProductComponentsRef>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Templates\Product.wxs" Link="Product.wxs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Msmq.wixext" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions src/test/msi/TestData/MsmqExtensionTests/MsmqInstall/product.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- 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. -->


<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:msmq="http://wixtoolset.org/schemas/v4/wxs/msmq">
<Fragment>
<ComponentGroup Id="ProductComponents">
<ComponentRef Id="Component1" />
</ComponentGroup>
</Fragment>

<Fragment>
<Component Id="Component1">
<File Source="$(sys.SOURCEFILEPATH)" KeyPath="yes" />
<msmq:MessageQueue Id="ExampleQueue" PathName=".\private$\example-queue" Label="Example Queue" Transactional="yes" />
</Component>
</Fragment>
</Wix>
27 changes: 27 additions & 0 deletions src/test/msi/WixToolsetTest.MsiE2E/MsmqExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 WixToolsetTest.MsiE2E
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WixTestTools;
using Xunit.Abstractions;

public class MsmqExtensionTests : MsiE2ETests
{
public MsmqExtensionTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
}

[RuntimePrereqFeatureFact("MSMQ-Container", "MSMQ-Server")]
public void CanInstallAndUninstallMsmq()
{
var product = this.CreatePackageInstaller("MsmqInstall");
product.InstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
product.UninstallProduct(MSIExec.MSIExecReturnCode.SUCCESS);
}
}
}

0 comments on commit b4cb6f1

Please sign in to comment.