Merging in Theme changes and moving win32Tests to Microsoft.Plugin.Program.UnitTests

This commit is contained in:
ryanbodrug-microsoft
2020-06-26 10:45:40 -07:00
parent 3295ea84a4
commit 030dfc2370
17 changed files with 1014 additions and 731 deletions

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using Windows.ApplicationModel;
using Windows.Foundation;
namespace Microsoft.Plugin.Program.Programs
{
internal interface IPackageCatalog
{
event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling;
event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling;
event TypedEventHandler<PackageCatalog, PackageUpdatingEventArgs> PackageUpdating;
}
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Text;
using Windows.ApplicationModel;
using Windows.Foundation;
namespace Microsoft.Plugin.Program.Programs
{
/// <summary>
/// This is a simple wrapper class around the PackageCatalog to facilitate unit testing.
/// </summary>
internal class PackageCatalogWrapper : IPackageCatalog
{
PackageCatalog _packageCatalog;
public PackageCatalogWrapper()
{
//Opens the catalog of packages that is available for the current user.
_packageCatalog = PackageCatalog.OpenForCurrentUser();
}
//
// Summary:
// Indicates that an app package is installing.
public event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling
{
add
{
_packageCatalog.PackageInstalling += value;
}
remove
{
_packageCatalog.PackageInstalling -= value;
}
}
//
// Summary:
// Indicates that an app package is installing.
public event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling
{
add
{
_packageCatalog.PackageUninstalling += value;
}
remove
{
_packageCatalog.PackageUninstalling -= value;
}
}
//
// Summary:
// Indicates that an app package is installing.
public event TypedEventHandler<PackageCatalog, PackageUpdatingEventArgs> PackageUpdating
{
add
{
_packageCatalog.PackageUpdating += value;
}
remove
{
_packageCatalog.PackageUpdating -= value;
}
}
}
}

View File

@@ -31,7 +31,7 @@ namespace Microsoft.Plugin.Program.Programs
{
public string Name { get; }
public string FullName { get; }
public string FamilyName { get; }
public string FamilyName { get; }
public string Location { get; set; }
public Application[] Apps { get; set; }
@@ -40,24 +40,17 @@ namespace Microsoft.Plugin.Program.Programs
public UWP(Package package)
{
Location = package.InstalledLocation.Path;
Name = package.Id.Name;
FullName = package.Id.FullName;
FamilyName = package.Id.FamilyName;
InitializeAppInfo();
Apps = Apps.Where(a =>
{
var valid =
!string.IsNullOrEmpty(a.UserModelId) &&
!string.IsNullOrEmpty(a.DisplayName);
return valid;
}).ToArray();
}
private void InitializeAppInfo()
public void InitializeAppInfo(string installedLocation)
{
Location = installedLocation;
AppxPackageHelper _helper = new AppxPackageHelper();
var path = Path.Combine(Location, "AppxManifest.xml");
var path = Path.Combine(installedLocation, "AppxManifest.xml");
var namespaces = XmlNamespaces(path);
InitPackageVersion(namespaces);
@@ -154,21 +147,14 @@ namespace Microsoft.Plugin.Program.Programs
try
{
u = new UWP(p);
u.InitializeAppInfo(p.InstalledLocation.Path);
}
#if !DEBUG
catch (Exception e)
{
ProgramLogger.LogException($"|UWP|All|{p.InstalledLocation}|An unexpected error occurred and "
+ $"unable to convert Package to UWP for {p.Id.FullName}", e);
return new Application[] { };
}
#endif
#if DEBUG //make developer aware and implement handling
catch
{
throw;
}
#endif
return u.Apps;
}).ToArray();