Skip to content

Commit

Permalink
fix tests?
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft committed Feb 20, 2025
1 parent f51a297 commit 37e8633
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
6 changes: 2 additions & 4 deletions src/AppInstallerCLIE2ETests/Helpers/TestCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,8 @@ public static void VerifyPortablePackage(
isAddedToPath = currentPathValue.Contains(portablePathValue);
}

if (shouldExist)
{
RunAICLICommand("uninstall", $"--product-code {productCode} --force");
}
// Always clean up as best effort.
RunAICLICommand("uninstall", $"--product-code {productCode} --force");

Assert.AreEqual(shouldExist, exeExists, $"Expected portable exe path: {exePath}");
Assert.AreEqual(shouldExist && !installDirectoryAddedToPath, symlinkExists, $"Expected portable symlink path: {symlinkPath}");
Expand Down
7 changes: 5 additions & 2 deletions src/AppInstallerCLIE2ETests/Interop/UninstallInterop.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// <copyright file="UninstallInterop.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
Expand Down Expand Up @@ -277,7 +277,10 @@ public async Task UninstallPortableModifiedSymlink()
Assert.True(modifiedSymlinkInfo.Exists, "Modified symlink should still exist");

// Remove modified symlink as to not interfere with other tests
modifiedSymlinkInfo.Delete();
modifiedSymlinkInfo.Delete();

// Uninstall again to clean up.
await this.packageManager.UninstallPackageAsync(searchResult.CatalogPackage, this.TestFactory.CreateUninstallOptions());
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions src/AppInstallerCLIE2ETests/Interop/UpgradeInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ public async Task TestIsUpdateAvailable_ApplicableTrue()
// Find and install the test package. Install the version 1.0.0.0.
var installDir = TestCommon.GetRandomTestDir();
var searchResult = this.FindOnePackage(this.compositeSource, PackageMatchField.Id, PackageFieldMatchOption.Equals, "AppInstallerTest.TestExeInstaller");
var installVersion = searchResult.CatalogPackage.AvailableVersions.Single(v => v.Version == "1.0.0.0");
var installOptions = this.TestFactory.CreateInstallOptions();
installOptions.PreferredInstallLocation = installDir;
installOptions.PackageVersionId = searchResult.CatalogPackage.AvailableVersions.Single(v => v.Version == "1.0.0.0");
installOptions.PackageVersionId = installVersion;
var installResult = await this.packageManager.InstallPackageAsync(searchResult.CatalogPackage, installOptions);
Assert.AreEqual(InstallResultStatus.Ok, installResult.Status);

Expand All @@ -272,10 +273,11 @@ public async Task TestIsUpdateAvailable_ApplicableFalse()
{
// Find and install the test package. Install the version 1.0.0.0.
var installDir = TestCommon.GetRandomTestDir();
var searchResult = this.FindOnePackage(this.compositeSource, PackageMatchField.Id, PackageFieldMatchOption.Equals, "AppInstallerTest.TestUpgradeApplicability");
var searchResult = this.FindOnePackage(this.compositeSource, PackageMatchField.Id, PackageFieldMatchOption.Equals, "AppInstallerTest.TestUpgradeApplicability");
var installVersion = searchResult.CatalogPackage.AvailableVersions.Single(v => v.Version == "1.0.0.0");
var installOptions = this.TestFactory.CreateInstallOptions();
installOptions.PreferredInstallLocation = installDir;
installOptions.PackageVersionId = searchResult.CatalogPackage.AvailableVersions.Single(v => v.Version == "1.0.0.0");
installOptions.PackageVersionId = installVersion;
var installResult = await this.packageManager.InstallPackageAsync(searchResult.CatalogPackage, installOptions);
Assert.AreEqual(InstallResultStatus.Ok, installResult.Status);

Expand Down
13 changes: 12 additions & 1 deletion src/Microsoft.Management.Deployment/PackageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,18 @@ namespace winrt::Microsoft::Management::Deployment::implementation
}
else
{
packageVersionInfo = package.DefaultInstallVersion();
if constexpr (std::is_same_v<TOptions, winrt::Microsoft::Management::Deployment::InstallOptions>)
{
packageVersionInfo = package.DefaultInstallVersion();
}
else if constexpr (std::is_same_v<TOptions, winrt::Microsoft::Management::Deployment::DownloadOptions>)
{
// For download, applicability check is not needed. Just use latest.
if (package.AvailableVersions().Size() > 0)
{
packageVersionInfo = package.GetPackageVersionInfo(package.AvailableVersions().GetAt(0));
}
}
}
// If the specified version wasn't found then return a failure. This is unusual, since all packages that came from a non-local catalog have a default version,
// and the versionId is strongly typed and comes from the CatalogPackage.GetAvailableVersions.
Expand Down
6 changes: 2 additions & 4 deletions src/Microsoft.Management.Deployment/PackageManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,7 @@ namespace Microsoft.Management.Deployment
{
UninstallOptions();

/// Optionally specifies the version from the package to uninstall. If unspecified the version matching
/// CatalogPackage.GetLatestVersion() is used.
/// This property is not currently used. The version of CatalogPackage.InstalledVersion is used for uninstall.
PackageVersionId PackageVersionId;

/// Silent, Interactive, or Default
Expand Down Expand Up @@ -1234,8 +1233,7 @@ namespace Microsoft.Management.Deployment
{
RepairOptions();

/// Optionally specifies the version from the package to repair. If unspecified the version matching
/// CatalogPackage.GetLatestVersion() is used.
/// This property is not currently used. The version of CatalogPackage.InstalledVersion is used for repair.
PackageVersionId PackageVersionId;

/// The package Repair scope.
Expand Down

0 comments on commit 37e8633

Please sign in to comment.