-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added wrapper for PackageManager and Package class * Added tests for package in development and framework mode * Renamed UWP test file * Improved readability of UWP tests
- Loading branch information
1 parent
ec803d6
commit 653ae77
Showing
12 changed files
with
389 additions
and
39 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
.../Plugins/Microsoft.Plugin.Program.UnitTests/AppxManifests/DevelopmentApp/AppxManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp build" xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build"> | ||
<Identity Name="3b548ab3-3034-4edf-a625-4691c73b43a9" Publisher="CN=divyan" Version="1.0.0.0" ProcessorArchitecture="x86" /> | ||
<mp:PhoneIdentity PhoneProductId="3b548ab3-3034-4edf-a625-4691c73b43a9" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> | ||
<Properties> | ||
<DisplayName>DevelopmentApp</DisplayName> | ||
<PublisherDisplayName>divyan</PublisherDisplayName> | ||
<Logo>Assets\StoreLogo.png</Logo> | ||
</Properties> | ||
<Dependencies> | ||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.18362.0" MaxVersionTested="10.0.18362.0" /> | ||
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.27810.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
<PackageDependency Name="Microsoft.NET.CoreRuntime.2.2" MinVersion="2.2.27902.3" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
<PackageDependency Name="Microsoft.NET.CoreFramework.Debug.2.2" MinVersion="2.2.27909.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
</Dependencies> | ||
<Resources> | ||
<Resource Language="EN-US" /> | ||
</Resources> | ||
<Applications> | ||
<Application Id="App" Executable="DevelopmentApp.exe" EntryPoint="DevelopmentApp.App"> | ||
<uap:VisualElements DisplayName="DevelopmentApp" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="DevelopmentApp" BackgroundColor="transparent"> | ||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" /> | ||
<uap:SplashScreen Image="Assets\SplashScreen.png" /> | ||
</uap:VisualElements> | ||
</Application> | ||
</Applications> | ||
<Capabilities> | ||
<Capability Name="internetClient" /> | ||
</Capabilities> | ||
<Extensions> | ||
<Extension Category="windows.activatableClass.inProcessServer"> | ||
<InProcessServer> | ||
<Path>DevelopmentApp.exe</Path> | ||
<ActivatableClass ActivatableClassId="Microsoft.UI.Xaml.Markup.ReflectionXamlMetadataProvider" ThreadingModel="both" /> | ||
</InProcessServer> | ||
</Extension> | ||
</Extensions> | ||
<build:Metadata> | ||
<build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v5.0" /> | ||
<build:Item Name="VisualStudio" Version="16.0" /> | ||
<build:Item Name="VisualStudioEdition" Value="Microsoft Visual Studio Enterprise 2019" /> | ||
<build:Item Name="OperatingSystem" Version="10.0.18362.1 (WinBuild.160101.0800)" /> | ||
<build:Item Name="Microsoft.Build.AppxPackage.dll" Version="16.0.30009.100" /> | ||
<build:Item Name="ProjectGUID" Value="{A995B1F6-B462-4CC0-8E7F-3C9A9354A700}" /> | ||
<build:Item Name="OptimizingToolset" Value="None" /> | ||
<build:Item Name="TargetRuntime" Value="Managed" /> | ||
<build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="10.0.18362.1" /> | ||
<build:Item Name="MakePri.exe" Version="10.0.18362.1 (WinBuild.160101.0800)" /> | ||
</build:Metadata> | ||
</Package> |
50 changes: 50 additions & 0 deletions
50
...er/Plugins/Microsoft.Plugin.Program.UnitTests/AppxManifests/FrameworkApp/AppxManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp build" xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build"> | ||
<Identity Name="3b548ab3-3034-4edf-a625-4691c73b43a9" Publisher="CN=divyan" Version="1.0.0.0" ProcessorArchitecture="x86" /> | ||
<mp:PhoneIdentity PhoneProductId="3b548ab3-3034-4edf-a625-4691c73b43a9" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> | ||
<Properties> | ||
<DisplayName>FrameworkApp</DisplayName> | ||
<PublisherDisplayName>divyan</PublisherDisplayName> | ||
<Logo>Assets\StoreLogo.png</Logo> | ||
</Properties> | ||
<Dependencies> | ||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.18362.0" MaxVersionTested="10.0.18362.0" /> | ||
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.27810.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
<PackageDependency Name="Microsoft.NET.CoreRuntime.2.2" MinVersion="2.2.27902.3" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
<PackageDependency Name="Microsoft.NET.CoreFramework.Debug.2.2" MinVersion="2.2.27909.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
</Dependencies> | ||
<Resources> | ||
<Resource Language="EN-US" /> | ||
</Resources> | ||
<Applications> | ||
<Application Id="App" Executable="FrameworkApp.exe" EntryPoint="FrameworkApp.App"> | ||
<uap:VisualElements DisplayName="FrameworkApp" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="FrameworkApp" BackgroundColor="transparent"> | ||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" /> | ||
<uap:SplashScreen Image="Assets\SplashScreen.png" /> | ||
</uap:VisualElements> | ||
</Application> | ||
</Applications> | ||
<Capabilities> | ||
<Capability Name="internetClient" /> | ||
</Capabilities> | ||
<Extensions> | ||
<Extension Category="windows.activatableClass.inProcessServer"> | ||
<InProcessServer> | ||
<Path>FrameworkApp.exe</Path> | ||
<ActivatableClass ActivatableClassId="Microsoft.UI.Xaml.Markup.ReflectionXamlMetadataProvider" ThreadingModel="both" /> | ||
</InProcessServer> | ||
</Extension> | ||
</Extensions> | ||
<build:Metadata> | ||
<build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v5.0" /> | ||
<build:Item Name="VisualStudio" Version="16.0" /> | ||
<build:Item Name="VisualStudioEdition" Value="Microsoft Visual Studio Enterprise 2019" /> | ||
<build:Item Name="OperatingSystem" Version="10.0.18362.1 (WinBuild.160101.0800)" /> | ||
<build:Item Name="Microsoft.Build.AppxPackage.dll" Version="16.0.30009.100" /> | ||
<build:Item Name="ProjectGUID" Value="{A995B1F6-B462-4CC0-8E7F-3C9A9354A700}" /> | ||
<build:Item Name="OptimizingToolset" Value="None" /> | ||
<build:Item Name="TargetRuntime" Value="Managed" /> | ||
<build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="10.0.18362.1" /> | ||
<build:Item Name="MakePri.exe" Version="10.0.18362.1 (WinBuild.160101.0800)" /> | ||
</build:Metadata> | ||
</Package> |
50 changes: 50 additions & 0 deletions
50
...her/Plugins/Microsoft.Plugin.Program.UnitTests/AppxManifests/PackagedApp/AppxManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp build" xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build"> | ||
<Identity Name="3b548ab3-3034-4edf-a625-4691c73b43a9" Publisher="CN=divyan" Version="1.0.0.0" ProcessorArchitecture="x86" /> | ||
<mp:PhoneIdentity PhoneProductId="3b548ab3-3034-4edf-a625-4691c73b43a9" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> | ||
<Properties> | ||
<DisplayName>PackagedApp</DisplayName> | ||
<PublisherDisplayName>divyan</PublisherDisplayName> | ||
<Logo>Assets\StoreLogo.png</Logo> | ||
</Properties> | ||
<Dependencies> | ||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.18362.0" MaxVersionTested="10.0.18362.0" /> | ||
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.27810.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
<PackageDependency Name="Microsoft.NET.CoreRuntime.2.2" MinVersion="2.2.27902.3" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
<PackageDependency Name="Microsoft.NET.CoreFramework.Debug.2.2" MinVersion="2.2.27909.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> | ||
</Dependencies> | ||
<Resources> | ||
<Resource Language="EN-US" /> | ||
</Resources> | ||
<Applications> | ||
<Application Id="App" Executable="PackagedApp.exe" EntryPoint="PackagedApp.App"> | ||
<uap:VisualElements DisplayName="PackagedApp" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="PackagedApp" BackgroundColor="transparent"> | ||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" /> | ||
<uap:SplashScreen Image="Assets\SplashScreen.png" /> | ||
</uap:VisualElements> | ||
</Application> | ||
</Applications> | ||
<Capabilities> | ||
<Capability Name="internetClient" /> | ||
</Capabilities> | ||
<Extensions> | ||
<Extension Category="windows.activatableClass.inProcessServer"> | ||
<InProcessServer> | ||
<Path>PackagedApp.exe</Path> | ||
<ActivatableClass ActivatableClassId="Microsoft.UI.Xaml.Markup.ReflectionXamlMetadataProvider" ThreadingModel="both" /> | ||
</InProcessServer> | ||
</Extension> | ||
</Extensions> | ||
<build:Metadata> | ||
<build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v5.0" /> | ||
<build:Item Name="VisualStudio" Version="16.0" /> | ||
<build:Item Name="VisualStudioEdition" Value="Microsoft Visual Studio Enterprise 2019" /> | ||
<build:Item Name="OperatingSystem" Version="10.0.18362.1 (WinBuild.160101.0800)" /> | ||
<build:Item Name="Microsoft.Build.AppxPackage.dll" Version="16.0.30009.100" /> | ||
<build:Item Name="ProjectGUID" Value="{A995B1F6-B462-4CC0-8E7F-3C9A9354A700}" /> | ||
<build:Item Name="OptimizingToolset" Value="None" /> | ||
<build:Item Name="TargetRuntime" Value="Managed" /> | ||
<build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="10.0.18362.1" /> | ||
<build:Item Name="MakePri.exe" Version="10.0.18362.1 (WinBuild.160101.0800)" /> | ||
</build:Metadata> | ||
</Package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Programs/UWPTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Castle.Core.Internal; | ||
using Microsoft.Plugin.Program.Programs; | ||
using Moq; | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Plugin.Program.UnitTests.Programs | ||
{ | ||
[TestFixture] | ||
class UWPTests | ||
{ | ||
static readonly PackageWrapper developmentModeApp = new PackageWrapper( | ||
"DevelopmentApp", | ||
"DevelopmentApp", | ||
"DevelopmentApp", | ||
false, | ||
true, | ||
"AppxManifests/DevelopmentApp" | ||
); | ||
|
||
static readonly PackageWrapper frameworkApp = new PackageWrapper( | ||
"FrameworkApp", | ||
"FrameworkApp", | ||
"FrameworkApp", | ||
true, | ||
false, | ||
"AppxManifests/FrameworkApp" | ||
); | ||
|
||
static readonly PackageWrapper packagedApp = new PackageWrapper( | ||
"PackagedApp", | ||
"PackagedApp", | ||
"PackagedApp", | ||
false, | ||
false, | ||
"AppxManifests/PackagedApp" | ||
); | ||
|
||
[Test] | ||
public void All_ShouldReturnPackagesWithDevelopmentMode_WhenCalled() | ||
{ | ||
// Arrange | ||
Main._settings = new Settings(); | ||
List<IPackage> packages = new List<IPackage>() { developmentModeApp, packagedApp }; | ||
var mock = new Mock<IPackageManager>(); | ||
mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages); | ||
UWP.PackageManagerWrapper = mock.Object; | ||
|
||
// Act | ||
var applications = UWP.All(); | ||
|
||
// Assert | ||
Assert.AreEqual(applications.Length, 2); | ||
Assert.IsTrue(applications.FindAll(x => x.Name == "DevelopmentApp").Length > 0); | ||
Assert.IsTrue(applications.FindAll(x => x.Name == "PackagedApp").Length > 0); | ||
} | ||
|
||
[Test] | ||
public void All_ShouldNotReturnPackageFrameworks_WhenCalled() | ||
{ | ||
// Arrange | ||
Main._settings = new Settings(); | ||
List<IPackage> packages = new List<IPackage>() { frameworkApp, packagedApp }; | ||
var mock = new Mock<IPackageManager>(); | ||
mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages); | ||
UWP.PackageManagerWrapper = mock.Object; | ||
|
||
// Act | ||
var applications = UWP.All(); | ||
|
||
// Assert | ||
Assert.AreEqual(applications.Length, 1); | ||
Assert.IsTrue(applications.FindAll(x => x.Name == "PackagedApp").Length > 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/IPackage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.Plugin.Program.Programs | ||
{ | ||
public interface IPackage | ||
{ | ||
string Name { get; } | ||
|
||
string FullName { get; } | ||
|
||
string FamilyName { get; } | ||
|
||
bool IsFramework { get; } | ||
|
||
bool IsDevelopmentMode { get; } | ||
|
||
string InstalledLocation { get; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/IPackageManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.Plugin.Program.Programs | ||
{ | ||
public interface IPackageManager | ||
{ | ||
IEnumerable<IPackage> FindPackagesForCurrentUser(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/PackageWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Package = Windows.ApplicationModel.Package; | ||
|
||
namespace Microsoft.Plugin.Program.Programs | ||
{ | ||
public class PackageWrapper : IPackage | ||
{ | ||
public string Name { get; } | ||
|
||
public string FullName { get; } | ||
|
||
public string FamilyName { get; } | ||
|
||
public bool IsFramework { get; } | ||
|
||
public bool IsDevelopmentMode { get; } | ||
|
||
public string InstalledLocation { get; } | ||
|
||
public PackageWrapper(string Name, string FullName, string FamilyName, bool IsFramework, bool IsDevelopmentMode, string InstalledLocation) | ||
{ | ||
this.Name = Name; | ||
this.FullName = FullName; | ||
this.FamilyName = FamilyName; | ||
this.IsFramework = IsFramework; | ||
this.IsDevelopmentMode = IsDevelopmentMode; | ||
this.InstalledLocation = InstalledLocation; | ||
} | ||
|
||
public static PackageWrapper GetWrapperFromPackage(Package package) | ||
{ | ||
return new PackageWrapper( | ||
package.Id.Name, | ||
package.Id.FullName, | ||
package.Id.FamilyName, | ||
package.IsFramework, | ||
package.IsDevelopmentMode, | ||
package.InstalledLocation.Path | ||
); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/PackagemanagerWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO.Packaging; | ||
using System.Security.Principal; | ||
using Windows.Management.Deployment; | ||
using Windows.ApplicationModel; | ||
using Package = Windows.ApplicationModel.Package; | ||
|
||
namespace Microsoft.Plugin.Program.Programs | ||
{ | ||
public class PackageManagerWrapper : IPackageManager | ||
{ | ||
readonly PackageManager packageManager; | ||
|
||
public PackageManagerWrapper() | ||
{ | ||
packageManager = new PackageManager(); | ||
} | ||
|
||
public IEnumerable<IPackage> FindPackagesForCurrentUser() | ||
{ | ||
List<PackageWrapper> packages = new List<PackageWrapper>(); | ||
var user = WindowsIdentity.GetCurrent().User; | ||
|
||
if (user != null) | ||
{ | ||
var id = user.Value; | ||
var m = this.packageManager.FindPackagesForUser(id); | ||
foreach (Package p in m) | ||
{ | ||
packages.Add(PackageWrapper.GetWrapperFromPackage(p)); | ||
} | ||
} | ||
|
||
return packages; | ||
} | ||
} | ||
} |
Oops, something went wrong.