Skip to content

Commit

Permalink
Packaged apps test (#4921)
Browse files Browse the repository at this point in the history
* 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
dsrivastavv committed Jul 10, 2020
1 parent ec803d6 commit 653ae77
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 39 deletions.
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>
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>
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>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<IsPackable>false</IsPackable>

<Platforms>x64</Platforms>

<ApplicationManifest>AppxManifests\developmentApp\AppxManifest.xml</ApplicationManifest>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -23,4 +25,16 @@
<ProjectReference Include="..\Microsoft.Plugin.Program\Microsoft.Plugin.Program.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="AppxManifests\DevelopmentApp\AppxManifest.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="AppxManifests\FrameworkApp\AppxManifest.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="AppxManifests\PackagedApp\AppxManifest.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,11 @@
<PackageReference Include="NLog" Version="4.7.0" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.Plugin.Program.UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
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; }
}
}
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();
}
}
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
);
}
}
}
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;
}
}
}

0 comments on commit 653ae77

Please sign in to comment.