From 1f590c45be67ae39e2d785d7f7d70c0af84035b5 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Tue, 4 Aug 2020 14:01:37 -0700 Subject: [PATCH] Unit tests getting up-to-par for StyleCop (#5364) Co-authored-by: Clint Rutkas --- ...crosoft.PowerToys.Settings.UnitTest.csproj | 15 ++++++++ .../ModelsTests/BasePTModuleSettingsTest.cs | 10 +++-- .../ModelsTests/BasePTSettingsTest.cs | 8 +++- .../ModelsTests/HelperTest.cs | 11 ++++-- .../ModelsTests/SettingsUtilsTests.cs | 17 +++++---- .../UnitTestApp.xaml.cs | 35 ++++++++--------- .../ViewModelTests/ColorPicker.cs | 10 +++-- .../ViewModelTests/FancyZones.cs | 19 +++++----- .../ViewModelTests/General.cs | 15 ++++---- .../ViewModelTests/ImageResizer.cs | 22 +++++------ .../ViewModelTests/KeyboardManager.cs | 19 ++++++---- .../PowerLauncherViewModelTest.cs | 38 ++++++++----------- .../ViewModelTests/PowerPreview.cs | 15 ++++---- .../ViewModelTests/PowerRename.cs | 17 ++++----- .../ViewModelTests/ShortcutGuide.cs | 18 ++++----- 15 files changed, 143 insertions(+), 126 deletions(-) diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj b/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj index 5d55b1a27f..25f5bead5e 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/Microsoft.PowerToys.Settings.UnitTest.csproj @@ -210,6 +210,21 @@ 16.6.1 + + + GlobalSuppressions.cs + + + StyleCop.json + + + + + 1.1.118 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + {5d00d290-4016-4cfe-9e41-1e7c724509ba} diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTModuleSettingsTest.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTModuleSettingsTest.cs index 42e351d1ee..84bba538c8 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTModuleSettingsTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTModuleSettingsTest.cs @@ -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.UnitTest; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Schema; -using System; namespace CommonLibTest { @@ -17,7 +21,7 @@ namespace CommonLibTest [Obsolete] public void ToJsonString_ShouldReturnValidJSONOfModel_WhenSuccessful() { - // Arrange + // Arrange string file_name = "test\\BasePTModuleSettingsTest"; string expectedSchemaText = @" { @@ -46,4 +50,4 @@ namespace CommonLibTest Assert.IsTrue(valid); } } -} \ No newline at end of file +} diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTSettingsTest.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTSettingsTest.cs index 72bf7a8809..2bec4be724 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTSettingsTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/BasePTSettingsTest.cs @@ -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 { @@ -10,4 +14,4 @@ namespace Microsoft.PowerToys.Settings.UnitTest Version = string.Empty; } } -} \ No newline at end of file +} diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/HelperTest.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/HelperTest.cs index fff7a51f23..7e4306e087 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/HelperTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/HelperTest.cs @@ -1,6 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.PowerToys.Settings.UI.Lib.Utilities; +// 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.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace CommonLibTest { @@ -13,7 +17,6 @@ namespace CommonLibTest Assert.IsTrue(res < 0); } - public static void TestStringsAreEqual(string v1, string v2) { var res = Helper.CompareVersions(v1, v2); @@ -46,7 +49,7 @@ namespace CommonLibTest [ExpectedException(typeof(FormatException))] public void Helper_CompareVersions_ShouldThrowBadFormat_WhenNoVersionString() { - Helper.CompareVersions("v0.0.1", ""); + Helper.CompareVersions("v0.0.1", string.Empty); } [TestMethod] diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/SettingsUtilsTests.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/SettingsUtilsTests.cs index b8ac78dd95..dcb83fcba8 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/SettingsUtilsTests.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ModelsTests/SettingsUtilsTests.cs @@ -1,12 +1,14 @@ -using Microsoft.PowerToys.Settings.UI.Lib; -using Microsoft.PowerToys.Settings.UnitTest; -using Microsoft.VisualStudio.TestTools.UnitTesting; +// 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 System.Diagnostics; using System.IO; using System.Linq; 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 { @@ -22,7 +24,7 @@ namespace CommonLibTest } } - [TestCleanup()] + [TestCleanup] public void Cleanup() { string file_name = "\\test"; @@ -50,7 +52,7 @@ namespace CommonLibTest } [TestMethod] - public async Task SaveSettings_ShouldCreateFile_WhenFilePathIsNotFoundAsync() + public void SaveSettings_ShouldCreateFile_WhenFilePathIsNotFound() { // Arrange string file_name = "test\\Test Folder"; @@ -113,6 +115,7 @@ namespace CommonLibTest Random random = new Random(); int length = 20; const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + return new string(Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]).ToArray()); } diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/UnitTestApp.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/UnitTestApp.xaml.cs index 9e66dc7034..c7c710a438 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/UnitTestApp.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/UnitTestApp.xaml.cs @@ -1,18 +1,12 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; +// 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 Windows.ApplicationModel; using Windows.ApplicationModel.Activation; -using Windows.Foundation; -using Windows.Foundation.Collections; using Windows.UI.Xaml; 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; namespace Microsoft.PowerToys.Settings.UnitTest @@ -20,16 +14,17 @@ namespace Microsoft.PowerToys.Settings.UnitTest /// /// Provides application-specific behavior to supplement the default Application class. /// - sealed partial class App : Application + public sealed partial class App : Application { /// - /// Initializes the singleton application object. This is the first line of authored code + /// Initializes a new instance of the class. + /// This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// public App() { - this.InitializeComponent(); - this.Suspending += OnSuspending; + InitializeComponent(); + Suspending += OnSuspending; } /// @@ -39,11 +34,10 @@ namespace Microsoft.PowerToys.Settings.UnitTest /// Details about the launch request and process. protected override void OnLaunched(LaunchActivatedEventArgs e) { - #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { - this.DebugSettings.EnableFrameRateCounter = true; + DebugSettings.EnableFrameRateCounter = true; } #endif @@ -60,7 +54,7 @@ namespace Microsoft.PowerToys.Settings.UnitTest 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 @@ -80,7 +74,7 @@ namespace Microsoft.PowerToys.Settings.UnitTest /// /// The Frame which failed navigation /// Details about the navigation failure - void OnNavigationFailed(object sender, NavigationFailedEventArgs e) + private void OnNavigationFailed(object sender, NavigationFailedEventArgs e) { 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) { 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(); } } diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ColorPicker.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ColorPicker.cs index 09d47f81c0..d129d86590 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ColorPicker.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ColorPicker.cs @@ -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.Views; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.IO; -using System.Text.Json; namespace ViewModelTests { diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/FancyZones.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/FancyZones.cs index 908b53807c..ae08ef08f1 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/FancyZones.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/FancyZones.cs @@ -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.Views; 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; namespace ViewModelTests @@ -326,7 +325,7 @@ namespace ViewModelTests { // arrange FancyZonesViewModel viewModel = new FancyZonesViewModel(); - Assert.AreEqual("", viewModel.ExcludedApps); + Assert.AreEqual(string.Empty, viewModel.ExcludedApps); // Assert ShellPage.DefaultSndMSGCallback = msg => @@ -357,7 +356,7 @@ namespace ViewModelTests 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"); } diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs index 84d2d03511..29a86171d4 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/General.cs @@ -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.Views; 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 { diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ImageResizer.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ImageResizer.cs index 109e9227ea..fa742b48aa 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ImageResizer.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ImageResizer.cs @@ -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.Views; 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 { @@ -16,6 +16,7 @@ namespace ViewModelTests public class ImageResizer { public const string Module = "ImageResizer"; + [TestInitialize] public void Setup() { @@ -138,7 +139,6 @@ namespace ViewModelTests Assert.AreEqual(true, settings.Properties.ImageresizerKeepDateModified.Value); } - [TestMethod] public void Encoder_ShouldUpdateValue_WhenSuccessful() { @@ -201,7 +201,7 @@ namespace ViewModelTests double negativeWidth = -2.0; double negativeHeight = -2.0; - // Act + // Act imageSize.Width = negativeWidth; imageSize.Height = negativeHeight; @@ -209,7 +209,7 @@ namespace ViewModelTests Assert.AreEqual(0, imageSize.Width); Assert.AreEqual(0, imageSize.Height); - // Act + // Act imageSize.Width = 50; imageSize.Height = 50; diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/KeyboardManager.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/KeyboardManager.cs index e775be32a8..797927ee04 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/KeyboardManager.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/KeyboardManager.cs @@ -1,11 +1,12 @@ -using Microsoft.PowerToys.Settings.UI.Lib; -using Microsoft.PowerToys.Settings.UI.ViewModels; -using Microsoft.PowerToys.Settings.UI.Views; -using Microsoft.VisualStudio.TestTools.UnitTesting; +// 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.Collections.Generic; -using System.IO; 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; namespace ViewModelTests @@ -17,11 +18,13 @@ namespace ViewModelTests [TestInitialize] public void Setup() - { } + { + } [TestCleanup] public void CleanUp() - { } + { + } [TestMethod] public void CombineShortcutLists_ShouldReturnEmptyList_WhenBothArgumentsAreEmptyLists() diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs index 6727062fa5..51fe04d17a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerLauncherViewModelTest.cs @@ -1,31 +1,30 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.PowerToys.Settings.UI.ViewModels; +// 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; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Text.Json; +using Microsoft.PowerToys.Settings.UI.ViewModels; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ViewModelTests { [TestClass] - public class PowerLauncher + public class PowerLauncherViewModelTest { - class SendCallbackMock + private class SendCallbackMock { public int TimesSent { get; set; } + public void OnSend(PowerLauncherSettings settings) { TimesSent++; } } + private PowerLauncherViewModel viewModel; private PowerLauncherSettings mockSettings; private SendCallbackMock sendCallbackMock; - [TestInitialize] public void Initialize() { @@ -34,8 +33,7 @@ namespace ViewModelTests viewModel = new PowerLauncherViewModel( mockSettings, - new PowerLauncherViewModel.SendCallback(sendCallbackMock.OnSend) - ); + new PowerLauncherViewModel.SendCallback(sendCallbackMock.OnSend)); } [TestMethod] @@ -65,7 +63,6 @@ namespace ViewModelTests openPowerLauncher.Win = true; openPowerLauncher.Code = (int)Windows.System.VirtualKey.S; - var openFileLocation = new HotkeySettings(); openFileLocation.Ctrl = true; openFileLocation.Code = (int)Windows.System.VirtualKey.A; @@ -91,32 +88,28 @@ namespace ViewModelTests false, false, false, - (int)Windows.System.VirtualKey.S - ); + (int)Windows.System.VirtualKey.S); AssertHotkeySettings( mockSettings.Properties.OpenFileLocation, false, true, false, false, - (int)Windows.System.VirtualKey.A - ); + (int)Windows.System.VirtualKey.A); AssertHotkeySettings( mockSettings.Properties.OpenConsole, false, false, true, false, - (int)Windows.System.VirtualKey.D - ); + (int)Windows.System.VirtualKey.D); AssertHotkeySettings( mockSettings.Properties.CopyPathLocation, false, false, false, true, - (int)Windows.System.VirtualKey.F - ); + (int)Windows.System.VirtualKey.F); } [TestMethod] @@ -125,7 +118,6 @@ namespace ViewModelTests viewModel.OverrideWinRKey = true; viewModel.OverrideWinSKey = false; - Assert.AreEqual(1, sendCallbackMock.TimesSent); Assert.IsTrue(mockSettings.Properties.OverrideWinkeyR); diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs index be6d8dfb1d..9d4681c8ce 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerPreview.cs @@ -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.Views; 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 { diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerRename.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerRename.cs index b1a0b7c681..586ba111fc 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerRename.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/PowerRename.cs @@ -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.Views; 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 { @@ -16,7 +15,6 @@ namespace ViewModelTests public class PowerRename { public const string ModuleName = "PowerRename"; - public string schemaText = null; [TestInitialize] public void Setup() @@ -101,7 +99,6 @@ namespace ViewModelTests viewModel.IsEnabled = false; viewModel.MRUEnabled = true; - Assert.IsFalse(viewModel.GlobalAndMruEnabled); } diff --git a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ShortcutGuide.cs b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ShortcutGuide.cs index 6381692d57..2279c6a8ee 100644 --- a/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ShortcutGuide.cs +++ b/src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ShortcutGuide.cs @@ -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.Views; 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 { @@ -119,6 +118,7 @@ namespace ViewModelTests ShellPage.DefaultSndMSGCallback = msg => { ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize(msg); + // Serialisation not working as expected in the test project: Assert.AreEqual(100, snd.Powertoys.ShortcutGuide.Properties.OverlayOpacity.Value); }; @@ -127,4 +127,4 @@ namespace ViewModelTests viewModel.OverlayOpacity = 100; } } -} \ No newline at end of file +}