mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Unit tests getting up-to-par for StyleCop (#5364)
Co-authored-by: Clint Rutkas <crutkas@microsoft.com>
This commit is contained in:
@@ -210,6 +210,21 @@
|
|||||||
<Version>16.6.1</Version>
|
<Version>16.6.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="..\..\codeAnalysis\GlobalSuppressions.cs">
|
||||||
|
<Link>GlobalSuppressions.cs</Link>
|
||||||
|
</Compile>
|
||||||
|
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json">
|
||||||
|
<Link>StyleCop.json</Link>
|
||||||
|
</AdditionalFiles>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="StyleCop.Analyzers">
|
||||||
|
<Version>1.1.118</Version>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\Telemetry.csproj">
|
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\Telemetry.csproj">
|
||||||
<Project>{5d00d290-4016-4cfe-9e41-1e7c724509ba}</Project>
|
<Project>{5d00d290-4016-4cfe-9e41-1e7c724509ba}</Project>
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UnitTest;
|
using Microsoft.PowerToys.Settings.UnitTest;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Newtonsoft.Json.Schema;
|
using Newtonsoft.Json.Schema;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace CommonLibTest
|
namespace CommonLibTest
|
||||||
{
|
{
|
||||||
@@ -17,7 +21,7 @@ namespace CommonLibTest
|
|||||||
[Obsolete]
|
[Obsolete]
|
||||||
public void ToJsonString_ShouldReturnValidJSONOfModel_WhenSuccessful()
|
public void ToJsonString_ShouldReturnValidJSONOfModel_WhenSuccessful()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string file_name = "test\\BasePTModuleSettingsTest";
|
string file_name = "test\\BasePTModuleSettingsTest";
|
||||||
string expectedSchemaText = @"
|
string expectedSchemaText = @"
|
||||||
{
|
{
|
||||||
@@ -46,4 +50,4 @@ namespace CommonLibTest
|
|||||||
Assert.IsTrue(valid);
|
Assert.IsTrue(valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UnitTest
|
namespace Microsoft.PowerToys.Settings.UnitTest
|
||||||
{
|
{
|
||||||
@@ -10,4 +14,4 @@ namespace Microsoft.PowerToys.Settings.UnitTest
|
|||||||
Version = string.Empty;
|
Version = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
// Copyright (c) Microsoft Corporation
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace CommonLibTest
|
namespace CommonLibTest
|
||||||
{
|
{
|
||||||
@@ -13,7 +17,6 @@ namespace CommonLibTest
|
|||||||
Assert.IsTrue(res < 0);
|
Assert.IsTrue(res < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void TestStringsAreEqual(string v1, string v2)
|
public static void TestStringsAreEqual(string v1, string v2)
|
||||||
{
|
{
|
||||||
var res = Helper.CompareVersions(v1, v2);
|
var res = Helper.CompareVersions(v1, v2);
|
||||||
@@ -46,7 +49,7 @@ namespace CommonLibTest
|
|||||||
[ExpectedException(typeof(FormatException))]
|
[ExpectedException(typeof(FormatException))]
|
||||||
public void Helper_CompareVersions_ShouldThrowBadFormat_WhenNoVersionString()
|
public void Helper_CompareVersions_ShouldThrowBadFormat_WhenNoVersionString()
|
||||||
{
|
{
|
||||||
Helper.CompareVersions("v0.0.1", "");
|
Helper.CompareVersions("v0.0.1", string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
using Microsoft.PowerToys.Settings.UnitTest;
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
|
using Microsoft.PowerToys.Settings.UnitTest;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace CommonLibTest
|
namespace CommonLibTest
|
||||||
{
|
{
|
||||||
@@ -22,7 +24,7 @@ namespace CommonLibTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCleanup()]
|
[TestCleanup]
|
||||||
public void Cleanup()
|
public void Cleanup()
|
||||||
{
|
{
|
||||||
string file_name = "\\test";
|
string file_name = "\\test";
|
||||||
@@ -50,7 +52,7 @@ namespace CommonLibTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task SaveSettings_ShouldCreateFile_WhenFilePathIsNotFoundAsync()
|
public void SaveSettings_ShouldCreateFile_WhenFilePathIsNotFound()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string file_name = "test\\Test Folder";
|
string file_name = "test\\Test Folder";
|
||||||
@@ -113,6 +115,7 @@ namespace CommonLibTest
|
|||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
int length = 20;
|
int length = 20;
|
||||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
|
||||||
return new string(Enumerable.Repeat(chars, length)
|
return new string(Enumerable.Repeat(chars, length)
|
||||||
.Select(s => s[random.Next(s.Length)]).ToArray());
|
.Select(s => s[random.Next(s.Length)]).ToArray());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
using System;
|
// Copyright (c) Microsoft Corporation
|
||||||
using System.Collections.Generic;
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
using System.IO;
|
// See the LICENSE file in the project root for more information.
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
using System;
|
||||||
using Windows.ApplicationModel;
|
using Windows.ApplicationModel;
|
||||||
using Windows.ApplicationModel.Activation;
|
using Windows.ApplicationModel.Activation;
|
||||||
using Windows.Foundation;
|
|
||||||
using Windows.Foundation.Collections;
|
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Controls.Primitives;
|
|
||||||
using Windows.UI.Xaml.Data;
|
|
||||||
using Windows.UI.Xaml.Input;
|
|
||||||
using Windows.UI.Xaml.Media;
|
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UnitTest
|
namespace Microsoft.PowerToys.Settings.UnitTest
|
||||||
@@ -20,16 +14,17 @@ namespace Microsoft.PowerToys.Settings.UnitTest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides application-specific behavior to supplement the default Application class.
|
/// Provides application-specific behavior to supplement the default Application class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
sealed partial class App : Application
|
public sealed partial class App : Application
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the singleton application object. This is the first line of authored code
|
/// Initializes a new instance of the <see cref="App"/> class.
|
||||||
|
/// This is the first line of authored code
|
||||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
InitializeComponent();
|
||||||
this.Suspending += OnSuspending;
|
Suspending += OnSuspending;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,11 +34,10 @@ namespace Microsoft.PowerToys.Settings.UnitTest
|
|||||||
/// <param name="e">Details about the launch request and process.</param>
|
/// <param name="e">Details about the launch request and process.</param>
|
||||||
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (System.Diagnostics.Debugger.IsAttached)
|
if (System.Diagnostics.Debugger.IsAttached)
|
||||||
{
|
{
|
||||||
this.DebugSettings.EnableFrameRateCounter = true;
|
DebugSettings.EnableFrameRateCounter = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -60,7 +54,7 @@ namespace Microsoft.PowerToys.Settings.UnitTest
|
|||||||
|
|
||||||
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
||||||
{
|
{
|
||||||
//TODO: Load state from previously suspended application
|
// TODO: Load state from previously suspended application
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place the frame in the current Window
|
// Place the frame in the current Window
|
||||||
@@ -80,7 +74,7 @@ namespace Microsoft.PowerToys.Settings.UnitTest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender">The Frame which failed navigation</param>
|
/// <param name="sender">The Frame which failed navigation</param>
|
||||||
/// <param name="e">Details about the navigation failure</param>
|
/// <param name="e">Details about the navigation failure</param>
|
||||||
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
|
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||||
{
|
{
|
||||||
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
|
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
|
||||||
}
|
}
|
||||||
@@ -95,7 +89,8 @@ namespace Microsoft.PowerToys.Settings.UnitTest
|
|||||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||||
{
|
{
|
||||||
var deferral = e.SuspendingOperation.GetDeferral();
|
var deferral = e.SuspendingOperation.GetDeferral();
|
||||||
//TODO: Save application state and stop any background activity
|
|
||||||
|
// TODO: Save application state and stop any background activity
|
||||||
deferral.Complete();
|
deferral.Complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System.IO;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Windows.UI;
|
using Windows.UI;
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
@@ -326,7 +325,7 @@ namespace ViewModelTests
|
|||||||
{
|
{
|
||||||
// arrange
|
// arrange
|
||||||
FancyZonesViewModel viewModel = new FancyZonesViewModel();
|
FancyZonesViewModel viewModel = new FancyZonesViewModel();
|
||||||
Assert.AreEqual("", viewModel.ExcludedApps);
|
Assert.AreEqual(string.Empty, viewModel.ExcludedApps);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
ShellPage.DefaultSndMSGCallback = msg =>
|
ShellPage.DefaultSndMSGCallback = msg =>
|
||||||
@@ -357,7 +356,7 @@ namespace ViewModelTests
|
|||||||
viewModel.HighlightOpacity = 60;
|
viewModel.HighlightOpacity = 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String ToRGBHex(Color color)
|
private string ToRGBHex(Color color)
|
||||||
{
|
{
|
||||||
return "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
|
return "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
{
|
{
|
||||||
@@ -16,6 +16,7 @@ namespace ViewModelTests
|
|||||||
public class ImageResizer
|
public class ImageResizer
|
||||||
{
|
{
|
||||||
public const string Module = "ImageResizer";
|
public const string Module = "ImageResizer";
|
||||||
|
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
@@ -138,7 +139,6 @@ namespace ViewModelTests
|
|||||||
Assert.AreEqual(true, settings.Properties.ImageresizerKeepDateModified.Value);
|
Assert.AreEqual(true, settings.Properties.ImageresizerKeepDateModified.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Encoder_ShouldUpdateValue_WhenSuccessful()
|
public void Encoder_ShouldUpdateValue_WhenSuccessful()
|
||||||
{
|
{
|
||||||
@@ -201,7 +201,7 @@ namespace ViewModelTests
|
|||||||
double negativeWidth = -2.0;
|
double negativeWidth = -2.0;
|
||||||
double negativeHeight = -2.0;
|
double negativeHeight = -2.0;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
imageSize.Width = negativeWidth;
|
imageSize.Width = negativeWidth;
|
||||||
imageSize.Height = negativeHeight;
|
imageSize.Height = negativeHeight;
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ namespace ViewModelTests
|
|||||||
Assert.AreEqual(0, imageSize.Width);
|
Assert.AreEqual(0, imageSize.Width);
|
||||||
Assert.AreEqual(0, imageSize.Height);
|
Assert.AreEqual(0, imageSize.Height);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
imageSize.Width = 50;
|
imageSize.Width = 50;
|
||||||
imageSize.Height = 50;
|
imageSize.Height = 50;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
// See the LICENSE file in the project root for more information.
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Windows.System;
|
using Windows.System;
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
@@ -17,11 +18,13 @@ namespace ViewModelTests
|
|||||||
|
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
[TestCleanup]
|
[TestCleanup]
|
||||||
public void CleanUp()
|
public void CleanUp()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CombineShortcutLists_ShouldReturnEmptyList_WhenBothArgumentsAreEmptyLists()
|
public void CombineShortcutLists_ShouldReturnEmptyList_WhenBothArgumentsAreEmptyLists()
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
// Copyright (c) Microsoft Corporation
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using System;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using System.Collections.Generic;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class PowerLauncher
|
public class PowerLauncherViewModelTest
|
||||||
{
|
{
|
||||||
class SendCallbackMock
|
private class SendCallbackMock
|
||||||
{
|
{
|
||||||
public int TimesSent { get; set; }
|
public int TimesSent { get; set; }
|
||||||
|
|
||||||
public void OnSend(PowerLauncherSettings settings)
|
public void OnSend(PowerLauncherSettings settings)
|
||||||
{
|
{
|
||||||
TimesSent++;
|
TimesSent++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PowerLauncherViewModel viewModel;
|
private PowerLauncherViewModel viewModel;
|
||||||
private PowerLauncherSettings mockSettings;
|
private PowerLauncherSettings mockSettings;
|
||||||
private SendCallbackMock sendCallbackMock;
|
private SendCallbackMock sendCallbackMock;
|
||||||
|
|
||||||
|
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
@@ -34,8 +33,7 @@ namespace ViewModelTests
|
|||||||
|
|
||||||
viewModel = new PowerLauncherViewModel(
|
viewModel = new PowerLauncherViewModel(
|
||||||
mockSettings,
|
mockSettings,
|
||||||
new PowerLauncherViewModel.SendCallback(sendCallbackMock.OnSend)
|
new PowerLauncherViewModel.SendCallback(sendCallbackMock.OnSend));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -65,7 +63,6 @@ namespace ViewModelTests
|
|||||||
openPowerLauncher.Win = true;
|
openPowerLauncher.Win = true;
|
||||||
openPowerLauncher.Code = (int)Windows.System.VirtualKey.S;
|
openPowerLauncher.Code = (int)Windows.System.VirtualKey.S;
|
||||||
|
|
||||||
|
|
||||||
var openFileLocation = new HotkeySettings();
|
var openFileLocation = new HotkeySettings();
|
||||||
openFileLocation.Ctrl = true;
|
openFileLocation.Ctrl = true;
|
||||||
openFileLocation.Code = (int)Windows.System.VirtualKey.A;
|
openFileLocation.Code = (int)Windows.System.VirtualKey.A;
|
||||||
@@ -91,32 +88,28 @@ namespace ViewModelTests
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
(int)Windows.System.VirtualKey.S
|
(int)Windows.System.VirtualKey.S);
|
||||||
);
|
|
||||||
AssertHotkeySettings(
|
AssertHotkeySettings(
|
||||||
mockSettings.Properties.OpenFileLocation,
|
mockSettings.Properties.OpenFileLocation,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
(int)Windows.System.VirtualKey.A
|
(int)Windows.System.VirtualKey.A);
|
||||||
);
|
|
||||||
AssertHotkeySettings(
|
AssertHotkeySettings(
|
||||||
mockSettings.Properties.OpenConsole,
|
mockSettings.Properties.OpenConsole,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
(int)Windows.System.VirtualKey.D
|
(int)Windows.System.VirtualKey.D);
|
||||||
);
|
|
||||||
AssertHotkeySettings(
|
AssertHotkeySettings(
|
||||||
mockSettings.Properties.CopyPathLocation,
|
mockSettings.Properties.CopyPathLocation,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
(int)Windows.System.VirtualKey.F
|
(int)Windows.System.VirtualKey.F);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -125,7 +118,6 @@ namespace ViewModelTests
|
|||||||
viewModel.OverrideWinRKey = true;
|
viewModel.OverrideWinRKey = true;
|
||||||
viewModel.OverrideWinSKey = false;
|
viewModel.OverrideWinSKey = false;
|
||||||
|
|
||||||
|
|
||||||
Assert.AreEqual(1, sendCallbackMock.TimesSent);
|
Assert.AreEqual(1, sendCallbackMock.TimesSent);
|
||||||
|
|
||||||
Assert.IsTrue(mockSettings.Properties.OverrideWinkeyR);
|
Assert.IsTrue(mockSettings.Properties.OverrideWinkeyR);
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
{
|
{
|
||||||
@@ -16,7 +15,6 @@ namespace ViewModelTests
|
|||||||
public class PowerRename
|
public class PowerRename
|
||||||
{
|
{
|
||||||
public const string ModuleName = "PowerRename";
|
public const string ModuleName = "PowerRename";
|
||||||
public string schemaText = null;
|
|
||||||
|
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
@@ -101,7 +99,6 @@ namespace ViewModelTests
|
|||||||
viewModel.IsEnabled = false;
|
viewModel.IsEnabled = false;
|
||||||
viewModel.MRUEnabled = true;
|
viewModel.MRUEnabled = true;
|
||||||
|
|
||||||
|
|
||||||
Assert.IsFalse(viewModel.GlobalAndMruEnabled);
|
Assert.IsFalse(viewModel.GlobalAndMruEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Newtonsoft.Json.Schema;
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text.Json;
|
|
||||||
using Windows.UI.Popups;
|
|
||||||
|
|
||||||
namespace ViewModelTests
|
namespace ViewModelTests
|
||||||
{
|
{
|
||||||
@@ -119,6 +118,7 @@ namespace ViewModelTests
|
|||||||
ShellPage.DefaultSndMSGCallback = msg =>
|
ShellPage.DefaultSndMSGCallback = msg =>
|
||||||
{
|
{
|
||||||
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
|
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
|
||||||
|
|
||||||
// Serialisation not working as expected in the test project:
|
// Serialisation not working as expected in the test project:
|
||||||
Assert.AreEqual(100, snd.Powertoys.ShortcutGuide.Properties.OverlayOpacity.Value);
|
Assert.AreEqual(100, snd.Powertoys.ShortcutGuide.Properties.OverlayOpacity.Value);
|
||||||
};
|
};
|
||||||
@@ -127,4 +127,4 @@ namespace ViewModelTests
|
|||||||
viewModel.OverlayOpacity = 100;
|
viewModel.OverlayOpacity = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user