mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
PowerLauncherSettings unit tests (#2276)
This commit is contained in:
parent
ca7b6f139f
commit
7ec8d02c1f
@ -2,10 +2,14 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Lib
|
namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||||
{
|
{
|
||||||
public class PowerLauncherSettings : BasePTModuleSettings
|
public class PowerLauncherSettings : BasePTModuleSettings
|
||||||
{
|
{
|
||||||
|
public const string POWERTOYNAME = "PowerLauncher";
|
||||||
|
|
||||||
public PowerLauncherProperties properties { get; set; }
|
public PowerLauncherProperties properties { get; set; }
|
||||||
|
|
||||||
public PowerLauncherSettings()
|
public PowerLauncherSettings()
|
||||||
@ -14,5 +18,16 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
|||||||
version = "1";
|
version = "1";
|
||||||
name = "_unset_";
|
name = "_unset_";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Save()
|
||||||
|
{
|
||||||
|
// Save settings to file
|
||||||
|
var options = new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
WriteIndented = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), POWERTOYNAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,19 +12,36 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
{
|
{
|
||||||
public class PowerLauncherViewModel : Observable
|
public class PowerLauncherViewModel : Observable
|
||||||
{
|
{
|
||||||
private const string POWERTOYNAME = "PowerLauncher";
|
|
||||||
private PowerLauncherSettings settings;
|
private PowerLauncherSettings settings;
|
||||||
|
|
||||||
|
public delegate void SendCallback(PowerLauncherSettings settings);
|
||||||
|
|
||||||
|
private readonly SendCallback callback;
|
||||||
|
|
||||||
public PowerLauncherViewModel()
|
public PowerLauncherViewModel()
|
||||||
{
|
{
|
||||||
if (SettingsUtils.SettingsExists(POWERTOYNAME))
|
if (SettingsUtils.SettingsExists(PowerLauncherSettings.POWERTOYNAME))
|
||||||
{
|
{
|
||||||
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
|
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.POWERTOYNAME);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
settings = new PowerLauncherSettings();
|
settings = new PowerLauncherSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback = (PowerLauncherSettings settings) =>
|
||||||
|
{
|
||||||
|
// Propagate changes to Power Launcher through IPC
|
||||||
|
var propertiesJson = JsonSerializer.Serialize(settings.properties);
|
||||||
|
ShellPage.DefaultSndMSGCallback(
|
||||||
|
string.Format("{{ \"{0}\": {1} }}", PowerLauncherSettings.POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
|
||||||
|
{
|
||||||
|
this.settings = settings;
|
||||||
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
||||||
@ -32,17 +49,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
// Notify UI of property change
|
// Notify UI of property change
|
||||||
OnPropertyChanged(propertyName);
|
OnPropertyChanged(propertyName);
|
||||||
|
|
||||||
// Save settings to file
|
settings.Save();
|
||||||
var options = new JsonSerializerOptions
|
callback(settings);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
};
|
|
||||||
SettingsUtils.SaveSettings(JsonSerializer.Serialize(settings, options), POWERTOYNAME);
|
|
||||||
|
|
||||||
// Propagate changes to Power Launcher through IPC
|
|
||||||
var propertiesJson = JsonSerializer.Serialize(settings.properties);
|
|
||||||
ShellPage.DefaultSndMSGCallback(
|
|
||||||
string.Format("{{ \"{0}\": {1} }}", POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool EnablePowerLauncher
|
public bool EnablePowerLauncher
|
||||||
|
@ -1,184 +1,185 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
<ProjectGuid>{A80355C2-780D-4245-BD80-25B8DE698EE3}</ProjectGuid>
|
<ProjectGuid>{A80355C2-780D-4245-BD80-25B8DE698EE3}</ProjectGuid>
|
||||||
<OutputType>AppContainerExe</OutputType>
|
<OutputType>AppContainerExe</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>Microsoft.PowerToys.Settings.UnitTest</RootNamespace>
|
<RootNamespace>Microsoft.PowerToys.Settings.UnitTest</RootNamespace>
|
||||||
<AssemblyName>Microsoft.PowerToys.Settings.UnitTest</AssemblyName>
|
<AssemblyName>Microsoft.PowerToys.Settings.UnitTest</AssemblyName>
|
||||||
<DefaultLanguage>en-US</DefaultLanguage>
|
<DefaultLanguage>en-US</DefaultLanguage>
|
||||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||||
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
|
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
|
||||||
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
|
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
|
||||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
<UnitTestPlatformVersion Condition="'$(UnitTestPlatformVersion)' == ''">$(VisualStudioVersion)</UnitTestPlatformVersion>
|
<UnitTestPlatformVersion Condition="'$(UnitTestPlatformVersion)' == ''">$(VisualStudioVersion)</UnitTestPlatformVersion>
|
||||||
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
|
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||||
<OutputPath>bin\x86\Release\</OutputPath>
|
<OutputPath>bin\x86\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<OutputPath>bin\ARM\Debug\</OutputPath>
|
<OutputPath>bin\ARM\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<PlatformTarget>ARM</PlatformTarget>
|
<PlatformTarget>ARM</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
||||||
<OutputPath>bin\ARM\Release\</OutputPath>
|
<OutputPath>bin\ARM\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>ARM</PlatformTarget>
|
<PlatformTarget>ARM</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<OutputPath>bin\ARM64\Debug\</OutputPath>
|
<OutputPath>bin\ARM64\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<PlatformTarget>ARM64</PlatformTarget>
|
<PlatformTarget>ARM64</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
|
||||||
<OutputPath>bin\ARM64\Release\</OutputPath>
|
<OutputPath>bin\ARM64\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>ARM64</PlatformTarget>
|
<PlatformTarget>ARM64</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<OutputPath>bin\x64\Debug\Test\</OutputPath>
|
<OutputPath>bin\x64\Debug\Test\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
<OutputPath>bin\x64\Release\</OutputPath>
|
<OutputPath>bin\x64\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<NoWarn>;2008</NoWarn>
|
<NoWarn>;2008</NoWarn>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
|
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
|
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
|
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ModelsTests\BasePTModuleSettingsTest.cs" />
|
<Compile Include="ModelsTests\BasePTModuleSettingsTest.cs" />
|
||||||
<Compile Include="ModelsTests\BasePTSettingsTest.cs" />
|
<Compile Include="ModelsTests\BasePTSettingsTest.cs" />
|
||||||
<Compile Include="ModelsTests\SettingsUtilsTests.cs" />
|
<Compile Include="ModelsTests\SettingsUtilsTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="UnitTestApp.xaml.cs">
|
<Compile Include="UnitTestApp.xaml.cs">
|
||||||
<DependentUpon>UnitTestApp.xaml</DependentUpon>
|
<DependentUpon>UnitTestApp.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="ViewModelTests\ShortcutGuideViewModelTest.cs" />
|
<Compile Include="ViewModelTests\PowerLauncherViewModelTest.cs" />
|
||||||
</ItemGroup>
|
<Compile Include="ViewModelTests\ShortcutGuideViewModelTest.cs" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<ApplicationDefinition Include="UnitTestApp.xaml">
|
<ItemGroup>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<ApplicationDefinition Include="UnitTestApp.xaml">
|
||||||
<SubType>Designer</SubType>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</ApplicationDefinition>
|
<SubType>Designer</SubType>
|
||||||
</ItemGroup>
|
</ApplicationDefinition>
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<AppxManifest Include="Package.appxmanifest">
|
<ItemGroup>
|
||||||
<SubType>Designer</SubType>
|
<AppxManifest Include="Package.appxmanifest">
|
||||||
</AppxManifest>
|
<SubType>Designer</SubType>
|
||||||
</ItemGroup>
|
</AppxManifest>
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
<ItemGroup>
|
||||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||||
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
||||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||||
<Content Include="Assets\StoreLogo.png" />
|
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
<Content Include="Assets\StoreLogo.png" />
|
||||||
</ItemGroup>
|
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
<ItemGroup>
|
||||||
<Version>6.2.9</Version>
|
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||||
</PackageReference>
|
<Version>6.2.9</Version>
|
||||||
<PackageReference Include="MSTest.TestAdapter">
|
</PackageReference>
|
||||||
<Version>2.1.1</Version>
|
<PackageReference Include="MSTest.TestAdapter">
|
||||||
</PackageReference>
|
<Version>2.1.1</Version>
|
||||||
<PackageReference Include="MSTest.TestFramework">
|
</PackageReference>
|
||||||
<Version>2.1.1</Version>
|
<PackageReference Include="MSTest.TestFramework">
|
||||||
</PackageReference>
|
<Version>2.1.1</Version>
|
||||||
</ItemGroup>
|
</PackageReference>
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj">
|
<ItemGroup>
|
||||||
<Project>{b1bcc8c6-46b5-4bfa-8f22-20f32d99ec6a}</Project>
|
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj">
|
||||||
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
|
<Project>{b1bcc8c6-46b5-4bfa-8f22-20f32d99ec6a}</Project>
|
||||||
</ProjectReference>
|
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
|
||||||
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj">
|
</ProjectReference>
|
||||||
<Project>{a7d5099e-f0fd-4bf3-8522-5a682759f915}</Project>
|
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj">
|
||||||
<Name>Microsoft.PowerToys.Settings.UI</Name>
|
<Project>{a7d5099e-f0fd-4bf3-8522-5a682759f915}</Project>
|
||||||
</ProjectReference>
|
<Name>Microsoft.PowerToys.Settings.UI</Name>
|
||||||
</ItemGroup>
|
</ProjectReference>
|
||||||
<ItemGroup />
|
</ItemGroup>
|
||||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
<ItemGroup />
|
||||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||||
</PropertyGroup>
|
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
</PropertyGroup>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
<Target Name="BeforeBuild">
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
</Target>
|
<Target Name="BeforeBuild">
|
||||||
<Target Name="AfterBuild">
|
</Target>
|
||||||
</Target>
|
<Target Name="AfterBuild">
|
||||||
-->
|
</Target>
|
||||||
|
-->
|
||||||
</Project>
|
</Project>
|
@ -0,0 +1,159 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class PowerLauncherViewModelTest
|
||||||
|
{
|
||||||
|
class PowerLauncherSettingsMock : PowerLauncherSettings
|
||||||
|
{
|
||||||
|
public int TimesSaved { get; set; }
|
||||||
|
public override void Save()
|
||||||
|
{
|
||||||
|
TimesSaved++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SendCallbackMock
|
||||||
|
{
|
||||||
|
public int TimesSent { get; set; }
|
||||||
|
public void OnSend(PowerLauncherSettings settings)
|
||||||
|
{
|
||||||
|
TimesSent++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private PowerLauncherViewModel viewModel;
|
||||||
|
private PowerLauncherSettingsMock mockSettings;
|
||||||
|
private SendCallbackMock sendCallbackMock;
|
||||||
|
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
mockSettings = new PowerLauncherSettingsMock();
|
||||||
|
sendCallbackMock = new SendCallbackMock();
|
||||||
|
|
||||||
|
viewModel = new PowerLauncherViewModel(
|
||||||
|
mockSettings,
|
||||||
|
new PowerLauncherViewModel.SendCallback(sendCallbackMock.OnSend)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void IsEnabled_ShouldEnableModule()
|
||||||
|
{
|
||||||
|
viewModel.EnablePowerLauncher = true;
|
||||||
|
|
||||||
|
Assert.AreEqual(sendCallbackMock.TimesSent, 1);
|
||||||
|
Assert.AreEqual(mockSettings.TimesSaved, 1);
|
||||||
|
|
||||||
|
Assert.IsTrue(mockSettings.properties.enable_powerlauncher == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SearchPreference_ShouldUpdatePreferences()
|
||||||
|
{
|
||||||
|
viewModel.SearchResultPreference = "SearchOptionsAreNotValidated";
|
||||||
|
viewModel.SearchTypePreference = "SearchOptionsAreNotValidated";
|
||||||
|
|
||||||
|
Assert.AreEqual(sendCallbackMock.TimesSent, 2);
|
||||||
|
Assert.AreEqual(mockSettings.TimesSaved, 2);
|
||||||
|
|
||||||
|
Assert.IsTrue(mockSettings.properties.search_result_preference == "SearchOptionsAreNotValidated");
|
||||||
|
Assert.IsTrue(mockSettings.properties.search_type_preference == "SearchOptionsAreNotValidated");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AssertHotkeySettings(HotkeySettings setting, bool win, bool ctrl, bool alt, bool shift, int code)
|
||||||
|
{
|
||||||
|
Assert.AreEqual(setting.Win, win);
|
||||||
|
Assert.AreEqual(setting.Ctrl, ctrl);
|
||||||
|
Assert.AreEqual(setting.Alt, alt);
|
||||||
|
Assert.AreEqual(setting.Shift, shift);
|
||||||
|
Assert.AreEqual(setting.Code, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Hotkeys_ShouldUpdateHotkeys()
|
||||||
|
{
|
||||||
|
var openPowerLauncher = new HotkeySettings();
|
||||||
|
openPowerLauncher.Win = true;
|
||||||
|
openPowerLauncher.Code = (int)Windows.System.VirtualKey.S;
|
||||||
|
|
||||||
|
|
||||||
|
var openFileLocation = new HotkeySettings();
|
||||||
|
openFileLocation.Ctrl = true;
|
||||||
|
openFileLocation.Code = (int)Windows.System.VirtualKey.A;
|
||||||
|
|
||||||
|
var openConsole = new HotkeySettings();
|
||||||
|
openConsole.Alt = true;
|
||||||
|
openConsole.Code = (int)Windows.System.VirtualKey.D;
|
||||||
|
|
||||||
|
var copyFileLocation = new HotkeySettings();
|
||||||
|
copyFileLocation.Shift = true;
|
||||||
|
copyFileLocation.Code = (int)Windows.System.VirtualKey.F;
|
||||||
|
|
||||||
|
viewModel.OpenPowerLauncher = openPowerLauncher;
|
||||||
|
viewModel.OpenFileLocation = openFileLocation;
|
||||||
|
viewModel.OpenConsole = openConsole;
|
||||||
|
viewModel.CopyPathLocation = copyFileLocation;
|
||||||
|
|
||||||
|
Assert.AreEqual(mockSettings.TimesSaved, 4);
|
||||||
|
Assert.AreEqual(sendCallbackMock.TimesSent, 4);
|
||||||
|
|
||||||
|
AssertHotkeySettings(
|
||||||
|
mockSettings.properties.open_powerlauncher,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
(int)Windows.System.VirtualKey.S
|
||||||
|
);
|
||||||
|
AssertHotkeySettings(
|
||||||
|
mockSettings.properties.open_file_location,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
(int)Windows.System.VirtualKey.A
|
||||||
|
);
|
||||||
|
AssertHotkeySettings(
|
||||||
|
mockSettings.properties.open_console,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
(int)Windows.System.VirtualKey.D
|
||||||
|
);
|
||||||
|
AssertHotkeySettings(
|
||||||
|
mockSettings.properties.copy_path_location,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
(int)Windows.System.VirtualKey.F
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Override_ShouldUpdateOverrides()
|
||||||
|
{
|
||||||
|
viewModel.OverrideWinRKey = true;
|
||||||
|
viewModel.OverrideWinSKey = false;
|
||||||
|
|
||||||
|
|
||||||
|
Assert.AreEqual(sendCallbackMock.TimesSent, 1);
|
||||||
|
Assert.AreEqual(mockSettings.TimesSaved, 1);
|
||||||
|
|
||||||
|
Assert.IsTrue(mockSettings.properties.override_win_r_key);
|
||||||
|
Assert.IsFalse(mockSettings.properties.override_win_s_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -52,6 +52,8 @@
|
|||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user