Merge pull request #8095 from microsoft/dev/crutkas/SettingUnitTestStyleCop

StyleCop Microsoft.PowerToys.Settings.UI.UnitTests
This commit is contained in:
Clint Rutkas 2020-11-18 11:14:49 -08:00 committed by GitHub
commit 1735be1cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 237 additions and 242 deletions

View File

@ -1,11 +1,15 @@
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Moq;
// 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.Globalization;
using System.IO.Abstractions;
using System.Linq.Expressions;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Moq;
namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
{
@ -16,14 +20,17 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
// Using Ordinal since this is used internally for a path
private static readonly Expression<Func<string, bool>> SettingsFilterExpression = s => s == null || s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
internal class MockSettingsRepository<T> : ISettingsRepository<T> where T : ISettingsConfig, new()
internal class MockSettingsRepository<T> : ISettingsRepository<T>
where T : ISettingsConfig, new()
{
T _settingsConfig;
readonly ISettingsUtils _settingsUtils;
public MockSettingsRepository( ISettingsUtils settingsUtils)
private readonly ISettingsUtils _settingsUtils;
private T _settingsConfig;
public MockSettingsRepository(ISettingsUtils settingsUtils)
{
_settingsUtils = settingsUtils;
}
public T SettingsConfig
{
get
@ -43,10 +50,8 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
}
}
public static Mock<IFile>GetModuleIOProvider(string version, string module, string fileName)
public static Mock<IFile> GetModuleIOProvider(string version, string module, string fileName)
{
var stubSettingsPath = StubSettingsPath(version, module, fileName);
Expression<Func<string, bool>> filterExpression = ModuleFilterExpression(module);
return IIOProviderMocks.GetMockIOReadWithStubFile(stubSettingsPath, filterExpression);
@ -62,9 +67,9 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
return string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, module, fileName);
}
public static void VerifyModuleIOProviderWasRead(Mock<IFile> provider, string module, int expectedCallCount)
public static void VerifyModuleIOProviderWasRead(Mock<IFile> provider, string module, int expectedCallCount)
{
if(provider == null)
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
@ -95,6 +100,5 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
IIOProviderMocks.VerifyIOReadWithStubFile(provider, SettingsFilterExpression, expectedCallCount);
}
}
}

View File

@ -15,6 +15,14 @@
<OutputPath>..\..\..\x64\Release\SettingsTest\</OutputPath>
</PropertyGroup>
<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="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Moq" Version="4.14.7" />
@ -29,6 +37,10 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="12.2.3" />
</ItemGroup>

View File

@ -1,19 +1,21 @@
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Moq;
// 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.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Linq.Expressions;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Moq;
namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
{
internal static class IIOProviderMocks
{
/// <summary>
/// This method mocks an IO provider to validate tests wich required saving to a file, and then reading the contents of that file, or verifying it exists
/// </summary>
/// <returns></returns>
/// <returns>Mocked IO Provider</returns>
internal static Mock<IIOProvider> GetMockIOProviderForSaveLoadExists()
{
string savePath = string.Empty;
@ -25,12 +27,15 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
savePath = path;
saveContent = content;
});
// Using Ordinal since this is used internally for a path
mockIOProvider.Setup(x => x.ReadAllText(It.Is<string>(x => x.Equals(savePath, StringComparison.Ordinal))))
.Returns(() => saveContent);
// Using Ordinal since this is used internally for a path
mockIOProvider.Setup(x => x.FileExists(It.Is<string>(x => x.Equals(savePath, StringComparison.Ordinal))))
.Returns(true);
// Using Ordinal since this is used internally for a path
mockIOProvider.Setup(x => x.FileExists(It.Is<string>(x => !x.Equals(savePath, StringComparison.Ordinal))))
.Returns(false);
@ -38,27 +43,24 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
return mockIOProvider;
}
private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IFile File = FileSystem.File;
/// <summary>
/// This method mocks an IO provider so that it will always return data at the savePath location.
/// This method mocks an IO provider so that it will always return data at the savePath location.
/// This mock is specific to a given module, and is verifiable that the stub file was read.
/// </summary>
/// <param name="savePath">The path to the stub settings file</param>
/// <param name="expectedPathSubstring">The substring in the path that identifies the module eg. Microsoft\\PowerToys\\ColorPicker</param>
/// <returns></returns>
/// <param name="filterExpression">The substring in the path that identifies the module eg. Microsoft\\PowerToys\\ColorPicker</param>
/// <returns>Mocked IFile</returns>
internal static Mock<IFile> GetMockIOReadWithStubFile(string savePath, Expression<Func<string, bool>> filterExpression)
{
string saveContent = File.ReadAllText(savePath);
var fileMock = new Mock<IFile>();
fileMock.Setup(x => x.ReadAllText(It.Is<string>(filterExpression)))
.Returns(() => saveContent).Verifiable();
fileMock.Setup(x => x.Exists(It.Is<string>(filterExpression)))
.Returns(true);

View File

@ -1,13 +1,16 @@
using Microsoft.PowerToys.Settings.UI.Library;
// 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.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Moq;
using System;
namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
{
internal static class ISettingsUtilsMocks
{
//Stubs out empty values for imageresizersettings and general settings as needed by the imageresizer viewmodel
// Stubs out empty values for imageresizersettings and general settings as needed by the imageresizer viewmodel
internal static Mock<ISettingsUtils> GetStubSettingsUtils<T>()
where T : ISettingsConfig, new()
{

View File

@ -3,10 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using System.IO.Abstractions.TestingHelpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UnitTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
@ -24,7 +22,7 @@ namespace CommonLibTest
[ObsoleteAttribute("This test method is obsolete.", true)]
public void ToJsonStringShouldReturnValidJSONOfModelWhenSuccessful()
{
//Mock Disk access
// Mock Disk access
var mockFileSystem = new MockFileSystem();
var settingsUtils = new SettingsUtils(mockFileSystem);

View File

@ -5,8 +5,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommonLibTest
{
@ -15,14 +15,12 @@ namespace CommonLibTest
{
private static Task<SettingsRepository<GeneralSettings>> GetSettingsRepository(ISettingsUtils settingsUtils)
{
return Task.Run(() =>
{
return SettingsRepository<GeneralSettings>.GetInstance(settingsUtils);
});
}
[TestMethod]
public void SettingsRepositoryInstanceWhenCalledMustReturnSameObject()
{
@ -47,7 +45,7 @@ namespace CommonLibTest
List<Task<SettingsRepository<GeneralSettings>>> settingsRepoTasks = new List<Task<SettingsRepository<GeneralSettings>>>();
int numberOfTasks = 100;
for(int i = 0; i < numberOfTasks; i++)
for (int i = 0; i < numberOfTasks; i++)
{
settingsRepoTasks.Add(GetSettingsRepository(mockSettingsUtils.Object));
}
@ -56,11 +54,10 @@ namespace CommonLibTest
Task.WaitAll(settingsRepoTasks.ToArray());
// Assert
for(int i=0; i< numberOfTasks-1; i++)
for (int i = 0; i < numberOfTasks - 1; i++)
{
Assert.IsTrue(object.ReferenceEquals(settingsRepoTasks[i].Result, settingsRepoTasks[i + 1].Result));
}
}
}
}

View File

@ -3,25 +3,19 @@
// See the LICENSE file in the project root for more information.
using System;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Linq;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.PowerToys.Settings.UnitTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace CommonLibTest
{
[TestClass]
public class SettingsUtilsTests
{
[TestMethod]
public void SaveSettingsSaveSettingsToFileWhenFilePathExists()
{
@ -106,9 +100,10 @@ namespace CommonLibTest
.Select(s => s[random.Next(s.Length)]).ToArray());
}
partial class TestClass : ISettingsConfig
private partial class TestClass : ISettingsConfig
{
public int TestInt { get; set; } = 100;
public string TestString { get; set; } = "test";
public string GetModuleName()

View File

@ -19,12 +19,12 @@ namespace ViewModelTests
/// Test if the original settings files were modified.
/// </summary>
[TestMethod]
[DataRow("v0.20.1", "settings.json")] //Color picker was introduced in .20
[DataRow("v0.20.1", "settings.json")] // Color picker was introduced in .20
[DataRow("v0.21.1", "settings.json")]
[DataRow("v0.22.0", "settings.json")]
public void OriginalFilesModificationTest(string version, string fileName)
{
//Arrange
// Arrange
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, ColorPickerSettings.ModuleName, fileName);
var settingPathMock = new Mock<ISettingsPath>();
@ -37,18 +37,18 @@ namespace ViewModelTests
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
//Act
// Act
// Initialise View Model with test Config files
ColorPickerViewModel viewModel = new ColorPickerViewModel(mockSettingsUtils, generalSettingsRepository, ColorPickerIsEnabledByDefaultIPC);
//Assert
// Assert
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.Enabled.ColorPicker, viewModel.IsEnabled);
Assert.AreEqual(originalSettings.Properties.ActivationShortcut.ToString(), viewModel.ActivationShortcut.ToString());
Assert.AreEqual(originalSettings.Properties.ChangeCursor, viewModel.ChangeCursor);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, ColorPickerSettings.ModuleName, expectedCallCount);
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
}
@ -68,6 +68,5 @@ namespace ViewModelTests
Assert.IsTrue(snd.GeneralSettings.Enabled.ColorPicker);
return 0;
}
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.Text.Json;
using CommonLibTest;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
@ -69,8 +68,8 @@ namespace ViewModelTests
Assert.AreEqual(originalSettings.Properties.FancyzonesZoneSetChangeMoveWindows.Value, viewModel.ZoneSetChangeMoveWindows);
Assert.AreEqual(originalSettings.Properties.UseCursorposEditorStartupscreen.Value, viewModel.UseCursorPosEditorStartupScreen);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, FancyZonesSettings.ModuleName, expectedCallCount);
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
}
@ -96,7 +95,7 @@ namespace ViewModelTests
[TestMethod]
public void IsEnabledShouldDisableModuleWhenSuccessful()
{
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsFalse(snd.GeneralSettings.Enabled.FancyZones);
@ -104,7 +103,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsTrue(viewModel.IsEnabled); // check if the module is enabled.
// act
@ -115,7 +114,7 @@ namespace ViewModelTests
public void ShiftDragShouldSetValue2FalseWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsFalse(snd.Powertoys.FancyZones.Properties.FancyzonesShiftDrag.Value);
@ -123,7 +122,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsTrue(viewModel.ShiftDrag); // check if value was initialized to false.
// act
@ -134,7 +133,7 @@ namespace ViewModelTests
public void OverrideSnapHotkeysShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOverrideSnapHotkeys.Value);
@ -142,7 +141,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.OverrideSnapHotkeys); // check if value was initialized to false.
// act
@ -153,7 +152,7 @@ namespace ViewModelTests
public void MoveWindowsBasedOnPositionShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMoveWindowsBasedOnPosition.Value);
@ -161,7 +160,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.MoveWindowsBasedOnPosition); // check if value was initialized to false.
// act
@ -172,7 +171,7 @@ namespace ViewModelTests
public void ZoneSetChangeFlashZonesShouldSetValue2FalseWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMakeDraggedWindowTransparent.Value);
@ -180,7 +179,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.MakeDraggedWindowsTransparent); // check if value was initialized to false.
// act
@ -191,7 +190,7 @@ namespace ViewModelTests
public void MouseSwitchShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMouseSwitch.Value);
@ -199,7 +198,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.MouseSwitch); // check if value was initialized to false.
// act
@ -210,7 +209,7 @@ namespace ViewModelTests
public void DisplayChangeMoveWindowsShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesDisplayChangeMoveWindows.Value);
@ -218,7 +217,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.DisplayChangeMoveWindows); // check if value was initialized to false.
// act
@ -229,7 +228,7 @@ namespace ViewModelTests
public void ZoneSetChangeMoveWindowsShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesZoneSetChangeMoveWindows.Value);
@ -237,7 +236,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.ZoneSetChangeMoveWindows); // check if value was initialized to false.
// act
@ -248,7 +247,7 @@ namespace ViewModelTests
public void AppLastZoneMoveWindowsShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesAppLastZoneMoveWindows.Value);
@ -256,7 +255,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.AppLastZoneMoveWindows); // check if value was initialized to false.
// act
@ -266,7 +265,7 @@ namespace ViewModelTests
public void OpenWindowOnActiveMonitorShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOpenWindowOnActiveMonitor.Value);
@ -274,7 +273,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.OpenWindowOnActiveMonitor); // check if value was initialized to false.
// act
@ -285,7 +284,7 @@ namespace ViewModelTests
public void RestoreSizeShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesRestoreSize.Value);
@ -293,7 +292,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.RestoreSize); // check if value was initialized to false.
// act
@ -304,7 +303,7 @@ namespace ViewModelTests
public void UseCursorPosEditorStartupScreenShouldSetValue2FalseWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.UseCursorposEditorStartupscreen.Value);
@ -312,7 +311,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsTrue(viewModel.UseCursorPosEditorStartupScreen); // check if value was initialized to false.
// act
@ -323,7 +322,7 @@ namespace ViewModelTests
public void ShowOnAllMonitorsShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesShowOnAllMonitors.Value);
@ -331,7 +330,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.IsFalse(viewModel.ShowOnAllMonitors); // check if value was initialized to false.
// act
@ -342,7 +341,7 @@ namespace ViewModelTests
public void ZoneHighlightColorShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesZoneHighlightColor.Value);
@ -350,7 +349,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(ConfigDefaults.DefaultFancyZonesZoneHighlightColor, viewModel.ZoneHighlightColor);
// act
@ -361,7 +360,7 @@ namespace ViewModelTests
public void ZoneBorderColorShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesBorderColor.Value);
@ -369,7 +368,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(ConfigDefaults.DefaultFancyzonesBorderColor, viewModel.ZoneBorderColor);
// act
@ -380,7 +379,7 @@ namespace ViewModelTests
public void ZoneInActiveColorShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesInActiveColor.Value);
@ -388,7 +387,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(ConfigDefaults.DefaultFancyZonesInActiveColor, viewModel.ZoneInActiveColor);
// act
@ -399,7 +398,7 @@ namespace ViewModelTests
public void ExcludedAppsShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("Sample", snd.Powertoys.FancyZones.Properties.FancyzonesExcludedApps.Value);
@ -407,7 +406,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(string.Empty, viewModel.ExcludedApps);
// act
@ -418,7 +417,7 @@ namespace ViewModelTests
public void HighlightOpacityShouldSetOpacityValueTo60WhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual(60, snd.Powertoys.FancyZones.Properties.FancyzonesHighlightOpacity.Value);
@ -426,7 +425,7 @@ namespace ViewModelTests
};
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), SendMockIPCConfigMSG, FancyZonesTestFolderName);
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(50, viewModel.HighlightOpacity);
// act

View File

@ -3,8 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
@ -18,19 +16,16 @@ namespace ViewModelTests
[TestClass]
public class General
{
public const string generalSettingsFileName = "Test\\GenealSettings";
public const string GeneralSettingsFileName = "Test\\GeneralSettings";
private Mock<ISettingsUtils> mockGeneralSettingsUtils;
[TestInitialize]
public void SetUpStubSettingUtils()
{
mockGeneralSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>();
}
/// </summary>
[TestMethod]
[DataRow("v0.18.2")]
[DataRow("v0.19.2")]
@ -47,12 +42,11 @@ namespace ViewModelTests
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
// Initialise View Model with test Config files
// Arrange
Func<string, int> SendMockIPCConfigMSG = msg => 0;
Func<string, int> SendRestartAdminIPCMessage = msg => 0;
Func<string, int> SendCheckForUpdatesIPCMessage = msg => 0;
Func<string, int> sendMockIPCConfigMSG = msg => 0;
Func<string, int> sendRestartAdminIPCMessage = msg => 0;
Func<string, int> sendCheckForUpdatesIPCMessage = msg => 0;
var viewModel = new GeneralViewModel(
settingsRepository: generalSettingsRepository,
runAsAdminText: "GeneralSettings_RunningAsAdminText",
@ -60,9 +54,9 @@ namespace ViewModelTests
isElevated: false,
isAdmin: false,
updateTheme: UpdateUIThemeMethod,
ipcMSGCallBackFunc: SendMockIPCConfigMSG,
ipcMSGRestartAsAdminMSGCallBackFunc: SendRestartAdminIPCMessage,
ipcMSGCheckForUpdatesCallBackFunc: SendCheckForUpdatesIPCMessage,
ipcMSGCallBackFunc: sendMockIPCConfigMSG,
ipcMSGRestartAsAdminMSGCallBackFunc: sendRestartAdminIPCMessage,
ipcMSGCheckForUpdatesCallBackFunc: sendCheckForUpdatesIPCMessage,
configFileSubfolder: string.Empty);
// Verify that the old settings persisted
@ -72,8 +66,8 @@ namespace ViewModelTests
Assert.AreEqual(originalGeneralSettings.RunElevated, viewModel.RunElevated);
Assert.AreEqual(originalGeneralSettings.Startup, viewModel.Startup);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(fileMock, expectedCallCount);
}
@ -81,9 +75,9 @@ namespace ViewModelTests
public void IsElevatedShouldUpdateRunasAdminStatusAttrsWhenSuccessful()
{
// Arrange
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
GeneralViewModel viewModel = new GeneralViewModel(
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
@ -91,10 +85,10 @@ namespace ViewModelTests
false,
false,
UpdateUIThemeMethod,
SendMockIPCConfigMSG,
SendRestartAdminIPCMessage,
SendCheckForUpdatesIPCMessage,
generalSettingsFileName);
sendMockIPCConfigMSG,
sendRestartAdminIPCMessage,
sendCheckForUpdatesIPCMessage,
GeneralSettingsFileName);
Assert.AreEqual(viewModel.RunningAsUserDefaultText, viewModel.RunningAsText);
Assert.IsFalse(viewModel.IsElevated);
@ -111,7 +105,7 @@ namespace ViewModelTests
public void StartupShouldEnableRunOnStartUpWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsTrue(snd.GeneralSettings.Startup);
@ -119,8 +113,8 @@ namespace ViewModelTests
};
// Arrange
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
GeneralViewModel viewModel = new GeneralViewModel(
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
@ -128,10 +122,10 @@ namespace ViewModelTests
false,
false,
UpdateUIThemeMethod,
SendMockIPCConfigMSG,
SendRestartAdminIPCMessage,
SendCheckForUpdatesIPCMessage,
generalSettingsFileName);
sendMockIPCConfigMSG,
sendRestartAdminIPCMessage,
sendCheckForUpdatesIPCMessage,
GeneralSettingsFileName);
Assert.IsFalse(viewModel.Startup);
// act
@ -142,15 +136,15 @@ namespace ViewModelTests
public void RunElevatedShouldEnableAlwaysRunElevatedWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsTrue(snd.GeneralSettings.RunElevated);
return 0;
};
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
// Arrange
GeneralViewModel viewModel = new GeneralViewModel(
@ -160,10 +154,10 @@ namespace ViewModelTests
false,
false,
UpdateUIThemeMethod,
SendMockIPCConfigMSG,
SendRestartAdminIPCMessage,
SendCheckForUpdatesIPCMessage,
generalSettingsFileName);
sendMockIPCConfigMSG,
sendRestartAdminIPCMessage,
sendCheckForUpdatesIPCMessage,
GeneralSettingsFileName);
Assert.IsFalse(viewModel.RunElevated);
@ -176,16 +170,17 @@ namespace ViewModelTests
{
// Arrange
GeneralViewModel viewModel = null;
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.AreEqual("light", snd.GeneralSettings.Theme);
return 0;
};
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
viewModel = new GeneralViewModel(
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
@ -193,10 +188,10 @@ namespace ViewModelTests
false,
false,
UpdateUIThemeMethod,
SendMockIPCConfigMSG,
SendRestartAdminIPCMessage,
SendCheckForUpdatesIPCMessage,
generalSettingsFileName);
sendMockIPCConfigMSG,
sendRestartAdminIPCMessage,
sendCheckForUpdatesIPCMessage,
GeneralSettingsFileName);
Assert.IsFalse(viewModel.IsLightThemeRadioButtonChecked);
// act
@ -208,15 +203,15 @@ namespace ViewModelTests
{
// Arrange
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.AreEqual("dark", snd.GeneralSettings.Theme);
return 0;
};
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
Func<string, int> sendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> sendCheckForUpdatesIPCMessage = msg => { return 0; };
GeneralViewModel viewModel = new GeneralViewModel(
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
@ -224,14 +219,12 @@ namespace ViewModelTests
false,
false,
UpdateUIThemeMethod,
SendMockIPCConfigMSG,
SendRestartAdminIPCMessage,
SendCheckForUpdatesIPCMessage,
generalSettingsFileName);
sendMockIPCConfigMSG,
sendRestartAdminIPCMessage,
sendCheckForUpdatesIPCMessage,
GeneralSettingsFileName);
Assert.IsFalse(viewModel.IsDarkThemeRadioButtonChecked);
// act
viewModel.IsDarkThemeRadioButtonChecked = true;
}
@ -239,11 +232,10 @@ namespace ViewModelTests
[TestMethod]
public void AllModulesAreEnabledByDefault()
{
//arrange
// arrange
EnabledModules modules = new EnabledModules();
//Assert
// Assert
Assert.IsTrue(modules.FancyZones);
Assert.IsTrue(modules.ImageResizer);
Assert.IsTrue(modules.FileExplorerPreview);

View File

@ -3,12 +3,10 @@
// See the LICENSE file in the project root for more information.
using System;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Linq;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
@ -31,7 +29,6 @@ namespace ViewModelTests
_mockImgResizerSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
}
/// <summary>
/// Test if the original settings files were modified.
/// </summary>
@ -57,8 +54,8 @@ namespace ViewModelTests
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
// Initialise View Model with test Config files
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG);
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.Enabled.ImageResizer, viewModel.IsEnabled);
@ -70,8 +67,8 @@ namespace ViewModelTests
Assert.AreEqual(originalSettings.Properties.ImageresizerSizes.Value.Count, viewModel.Sizes.Count);
Assert.AreEqual(originalSettings.Properties.ImageresizerTiffCompressOption.Value, viewModel.TiffCompressOption);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, ImageResizerSettings.ModuleName, expectedCallCount);
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralFileMock, expectedCallCount);
}
@ -80,7 +77,7 @@ namespace ViewModelTests
public void IsEnabledShouldEnableModuleWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsTrue(snd.GeneralSettings.Enabled.ImageResizer);
@ -88,7 +85,7 @@ namespace ViewModelTests
};
// arrange
ImageResizerViewModel viewModel = new ImageResizerViewModel(_mockImgResizerSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
ImageResizerViewModel viewModel = new ImageResizerViewModel(_mockImgResizerSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
// act
viewModel.IsEnabled = true;
@ -100,14 +97,14 @@ namespace ViewModelTests
// arrange
var fileSystemMock = new MockFileSystem();
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
// act
viewModel.JPEGQualityLevel = 10;
// Assert
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
Assert.AreEqual(10, viewModel.JPEGQualityLevel);
}
@ -117,14 +114,14 @@ namespace ViewModelTests
// arrange
var fileSystemMock = new MockFileSystem();
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
// act
viewModel.PngInterlaceOption = 10;
// Assert
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
Assert.AreEqual(10, viewModel.PngInterlaceOption);
}
@ -134,14 +131,14 @@ namespace ViewModelTests
// arrange
var fileSystemMock = new MockFileSystem();
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
// act
viewModel.TiffCompressOption = 10;
// Assert
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
Assert.AreEqual(10, viewModel.TiffCompressOption);
}
@ -151,15 +148,15 @@ namespace ViewModelTests
// arrange
var fileSystemMock = new MockFileSystem();
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
string expectedValue = "%1 (%3)";
// act
viewModel.FileName = expectedValue;
// Assert
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
Assert.AreEqual(expectedValue, viewModel.FileName);
}
@ -170,6 +167,7 @@ namespace ViewModelTests
var settingUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
var expectedSettingsString = new ImageResizerSettings() { Properties = new ImageResizerProperties() { ImageresizerKeepDateModified = new BoolProperty() { Value = true } } }.ToJsonString();
// Using Ordinal since this is used internally
settingUtils.Setup(x => x.SaveSettings(
It.Is<string>(content => content.Equals(expectedSettingsString, StringComparison.Ordinal)),
@ -177,8 +175,8 @@ namespace ViewModelTests
It.IsAny<string>()))
.Verifiable();
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
// act
viewModel.KeepDateModified = true;
@ -193,14 +191,14 @@ namespace ViewModelTests
// arrange
var fileSystemMock = new MockFileSystem();
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
// act
viewModel.Encoder = 3;
// Assert
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
Assert.AreEqual("163bcc30-e2e9-4f0b-961d-a3e9fdb788a3", viewModel.EncoderGuid);
Assert.AreEqual(3, viewModel.Encoder);
}
@ -210,8 +208,8 @@ namespace ViewModelTests
{
// arrange
var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
int sizeOfOriginalArray = viewModel.Sizes.Count;
// act
@ -226,8 +224,8 @@ namespace ViewModelTests
{
// arrange
var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
int sizeOfOriginalArray = viewModel.Sizes.Count;
ImageSize deleteCandidate = viewModel.Sizes.Where<ImageSize>(x => x.Id == 0).First();

View File

@ -2,15 +2,12 @@
// 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.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Moq;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using System.Globalization;
using System.IO.Abstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace ViewModelTests
{
@ -23,6 +20,7 @@ namespace ViewModelTests
// PowerLauncherSettings is unused, but required according to SendCallback's signature.
// Naming parameter with discard symbol to suppress FxCop warnings.
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "We actually don't validate setting, just calculate it was sent")]
public void OnSend(PowerLauncherSettings _)
{
TimesSent++;
@ -32,6 +30,7 @@ namespace ViewModelTests
private PowerLauncherViewModel viewModel;
private PowerLauncherSettings mockSettings;
private SendCallbackMock sendCallbackMock;
[TestInitialize]
public void Initialize()
{
@ -66,8 +65,8 @@ namespace ViewModelTests
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
// Initialise View Model with test Config files
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
PowerLauncherViewModel viewModel = new PowerLauncherViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG, 32);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
PowerLauncherViewModel viewModel = new PowerLauncherViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG, 32);
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.Enabled.PowerLauncher, viewModel.EnablePowerLauncher);
@ -82,8 +81,8 @@ namespace ViewModelTests
Assert.AreEqual(originalSettings.Properties.SearchResultPreference, viewModel.SearchResultPreference);
Assert.AreEqual(originalSettings.Properties.SearchTypePreference, viewModel.SearchTypePreference);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerLauncherSettings.ModuleName, expectedCallCount);
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
}
@ -108,7 +107,8 @@ namespace ViewModelTests
Assert.AreEqual(alt, setting.Alt);
Assert.AreEqual(shift, setting.Shift);
Assert.AreEqual(code, setting.Code);
} else
}
else
{
Assert.Fail("setting parameter is null");
}

View File

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.IO.Abstractions;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
@ -17,7 +16,6 @@ namespace ViewModelTests
[TestClass]
public class PowerPreview
{
private Mock<ISettingsUtils> mockPowerPreviewSettingsUtils;
private Mock<ISettingsUtils> mockGeneralSettingsUtils;
@ -53,8 +51,8 @@ namespace ViewModelTests
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
// Initialise View Model with test Config files
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(repository, generalSettingsRepository, SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(repository, generalSettingsRepository, sendMockIPCConfigMSG);
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.IsElevated, viewModel.IsElevated);
@ -62,17 +60,16 @@ namespace ViewModelTests
Assert.AreEqual(originalSettings.Properties.EnableSvgPreview, viewModel.SVGRenderIsEnabled);
Assert.AreEqual(originalSettings.Properties.EnableSvgThumbnail, viewModel.SVGThumbnailIsEnabled);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, PowerPreviewSettings.ModuleName, expectedCallCount);
}
[TestMethod]
public void SVGRenderIsEnabledShouldPrevHandlerWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableSvgPreview);
@ -80,7 +77,7 @@ namespace ViewModelTests
};
// arrange
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
// act
viewModel.SVGRenderIsEnabled = true;
@ -90,7 +87,7 @@ namespace ViewModelTests
public void SVGThumbnailIsEnabledShouldPrevHandlerWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableSvgThumbnail);
@ -98,7 +95,7 @@ namespace ViewModelTests
};
// arrange
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
// act
viewModel.SVGThumbnailIsEnabled = true;
@ -108,7 +105,7 @@ namespace ViewModelTests
public void MDRenderIsEnabledShouldPrevHandlerWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableMdPreview);
@ -116,7 +113,7 @@ namespace ViewModelTests
};
// arrange
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, PowerPreviewSettings.ModuleName); ;
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
// act
viewModel.MDRenderIsEnabled = true;

View File

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.IO.Abstractions;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
@ -17,7 +16,7 @@ namespace ViewModelTests
[TestClass]
public class PowerRename
{
public const string generalSettingsFileName = "Test\\PowerRename";
public const string GeneralSettingsFileName = "Test\\PowerRename";
private Mock<ISettingsUtils> mockGeneralSettingsUtils;
@ -42,11 +41,10 @@ namespace ViewModelTests
{
var settingPathMock = new Mock<ISettingsPath>();
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerRenameSettings.ModuleName, fileName);
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
PowerRenameLocalProperties originalSettings = mockSettingsUtils.GetSettings<PowerRenameLocalProperties>(PowerRenameSettings.ModuleName);
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
@ -54,8 +52,8 @@ namespace ViewModelTests
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
// Initialise View Model with test Config files
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG);
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.Enabled.PowerRename, viewModel.IsEnabled);
@ -63,8 +61,8 @@ namespace ViewModelTests
Assert.AreEqual(originalSettings.MRUEnabled, viewModel.MRUEnabled);
Assert.AreEqual(originalSettings.ShowIcon, viewModel.EnabledOnContextMenu);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerRenameSettings.ModuleName, expectedCallCount);
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
}
@ -73,7 +71,7 @@ namespace ViewModelTests
public void IsEnabledShouldEnableModuleWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsTrue(snd.GeneralSettings.Enabled.PowerRename);
@ -81,7 +79,7 @@ namespace ViewModelTests
};
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
// act
viewModel.IsEnabled = true;
@ -91,7 +89,7 @@ namespace ViewModelTests
public void MRUEnabledShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.Properties.MRUEnabled.Value);
@ -99,7 +97,7 @@ namespace ViewModelTests
};
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
// act
viewModel.MRUEnabled = true;
@ -108,8 +106,8 @@ namespace ViewModelTests
[TestMethod]
public void WhenIsEnabledIsOffAndMRUEnabledIsOffGlobalAndMruShouldBeOff()
{
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
viewModel.IsEnabled = false;
viewModel.MRUEnabled = false;
@ -120,8 +118,8 @@ namespace ViewModelTests
[TestMethod]
public void WhenIsEnabledIsOffAndMRUEnabledIsOnGlobalAndMruShouldBeOff()
{
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
viewModel.IsEnabled = false;
viewModel.MRUEnabled = true;
@ -132,8 +130,8 @@ namespace ViewModelTests
[TestMethod]
public void WhenIsEnabledIsOnAndMRUEnabledIsOffGlobalAndMruShouldBeOff()
{
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
viewModel.IsEnabled = true;
viewModel.MRUEnabled = false;
@ -144,8 +142,8 @@ namespace ViewModelTests
[TestMethod]
public void WhenIsEnabledIsOnAndMRUEnabledIsOnGlobalAndMruShouldBeOn()
{
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
viewModel.IsEnabled = true;
viewModel.MRUEnabled = true;
@ -157,7 +155,7 @@ namespace ViewModelTests
public void EnabledOnContextMenuShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.Properties.ShowIcon.Value);
@ -165,7 +163,7 @@ namespace ViewModelTests
};
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
// act
viewModel.EnabledOnContextMenu = true;
@ -175,7 +173,7 @@ namespace ViewModelTests
public void EnabledOnContextExtendedMenuShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.Properties.ShowIcon.Value);
@ -183,7 +181,7 @@ namespace ViewModelTests
};
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
// act
viewModel.EnabledOnContextMenu = true;
@ -193,7 +191,7 @@ namespace ViewModelTests
public void RestoreFlagsOnLaunchShouldSetValue2TrueWhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.PowerRename.Properties.PersistState.Value);
@ -201,7 +199,7 @@ namespace ViewModelTests
};
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
// act
viewModel.RestoreFlagsOnLaunch = true;
@ -211,7 +209,7 @@ namespace ViewModelTests
public void MaxDispListNumShouldSetMaxSuggListTo20WhenSuccessful()
{
// Assert
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
PowerRenameSettingsIPCMessage snd = JsonSerializer.Deserialize<PowerRenameSettingsIPCMessage>(msg);
Assert.AreEqual(20, snd.Powertoys.PowerRename.Properties.MaxMRUSize.Value);
@ -219,7 +217,7 @@ namespace ViewModelTests
};
// arrange
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG, generalSettingsFileName);
PowerRenameViewModel viewModel = new PowerRenameViewModel(mockPowerRenamePropertiesUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, GeneralSettingsFileName);
// act
viewModel.MaxDispListNum = 20;

View File

@ -41,16 +41,16 @@ namespace ViewModelTests
var shortcutSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<ShortcutGuideSettings>(mockSettingsUtils);
// Initialise View Model with test Config files
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(generalSettingsRepository, shortcutSettingsRepository, SendMockIPCConfigMSG);
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(generalSettingsRepository, shortcutSettingsRepository, sendMockIPCConfigMSG);
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.Enabled.ShortcutGuide, viewModel.IsEnabled);
Assert.AreEqual(originalSettings.Properties.OverlayOpacity.Value, viewModel.OverlayOpacity);
Assert.AreEqual(originalSettings.Properties.PressTime.Value, viewModel.PressTime);
//Verify that the stub file was used
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, ShortcutGuideSettings.ModuleName, expectedCallCount);
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
}
@ -71,7 +71,7 @@ namespace ViewModelTests
{
// Assert
// Initialize mock function of sending IPC message.
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsTrue(snd.GeneralSettings.Enabled.ShortcutGuide);
@ -79,7 +79,7 @@ namespace ViewModelTests
};
// Arrange
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName);
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName);
// Act
viewModel.IsEnabled = true;
@ -90,7 +90,7 @@ namespace ViewModelTests
{
// Assert
// Initialize mock function of sending IPC message.
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
Assert.AreEqual("dark", snd.Powertoys.ShortcutGuide.Properties.Theme.Value);
@ -98,7 +98,8 @@ namespace ViewModelTests
};
// Arrange
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName);
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName);
// Initialize shortcut guide settings theme to 'system' to be in sync with shortcut_guide.h.
Assert.AreEqual(2, viewModel.ThemeIndex);
@ -111,7 +112,7 @@ namespace ViewModelTests
{
// Assert
// Initialize mock function of sending IPC message.
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
Assert.AreEqual(100, snd.Powertoys.ShortcutGuide.Properties.PressTime.Value);
@ -119,7 +120,7 @@ namespace ViewModelTests
};
// Arrange
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName);
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName);
Assert.AreEqual(900, viewModel.PressTime);
// Act
@ -131,7 +132,7 @@ namespace ViewModelTests
{
// Assert
// Initialize mock function of sending IPC message.
Func<string, int> SendMockIPCConfigMSG = msg =>
Func<string, int> sendMockIPCConfigMSG = msg =>
{
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
@ -141,7 +142,7 @@ namespace ViewModelTests
};
// Arrange
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), SendMockIPCConfigMSG, ShortCutGuideTestFolderName);
ShortcutGuideViewModel viewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<ShortcutGuideSettings>.GetInstance(mockShortcutGuideSettingsUtils.Object), sendMockIPCConfigMSG, ShortCutGuideTestFolderName);
Assert.AreEqual(90, viewModel.OverlayOpacity);
// Act