Files
PowerToys/src/settings-ui/Microsoft.PowerToys.Settings.UI.UnitTests/ViewModelTests/FancyZones.cs

436 lines
23 KiB
C#
Raw Normal View History

// 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.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace ViewModelTests
{
[TestClass]
public class FancyZones
{
public const string FancyZonesTestFolderName = "Test\\FancyZones";
/// <summary>
/// Test if the original settings files were modified.
/// </summary>
[TestMethod]
[DataRow("v0.18.2", "settings.json")]
[DataRow("v0.19.2", "settings.json")]
[DataRow("v0.20.1", "settings.json")]
[DataRow("v0.21.1", "settings.json")]
[DataRow("v0.22.0", "settings.json")]
public void OriginalFilesModificationTest(string version, string fileName)
{
var settingPathMock = new Mock<ISettingsPath>();
var fileMock = BackCompatTestProperties.GetModuleIOProvider(version, FancyZonesSettings.ModuleName, fileName);
var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
FancyZonesSettings originalSettings = mockSettingsUtils.GetSettings<FancyZonesSettings>(FancyZonesSettings.ModuleName);
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
var fancyZonesRepository = new BackCompatTestProperties.MockSettingsRepository<FancyZonesSettings>(mockSettingsUtils);
// Initialise View Model with test Config files
FancyZonesViewModel viewModel = new FancyZonesViewModel(generalSettingsRepository, fancyZonesRepository, ColorPickerIsEnabledByDefault_IPC);
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.Enabled.FancyZones, viewModel.IsEnabled);
Assert.AreEqual(originalSettings.Properties.FancyzonesAppLastZoneMoveWindows.Value, viewModel.AppLastZoneMoveWindows);
Assert.AreEqual(originalSettings.Properties.FancyzonesBorderColor.Value, viewModel.ZoneBorderColor);
Assert.AreEqual(originalSettings.Properties.FancyzonesDisplayChangeMoveWindows.Value, viewModel.DisplayChangeMoveWindows);
Assert.AreEqual(originalSettings.Properties.FancyzonesEditorHotkey.Value.ToString(), viewModel.EditorHotkey.ToString());
Assert.AreEqual(originalSettings.Properties.FancyzonesExcludedApps.Value, viewModel.ExcludedApps);
Assert.AreEqual(originalSettings.Properties.FancyzonesHighlightOpacity.Value, viewModel.HighlightOpacity);
Assert.AreEqual(originalSettings.Properties.FancyzonesInActiveColor.Value, viewModel.ZoneInActiveColor);
Assert.AreEqual(originalSettings.Properties.FancyzonesMakeDraggedWindowTransparent.Value, viewModel.MakeDraggedWindowsTransparent);
Assert.AreEqual(originalSettings.Properties.FancyzonesMouseSwitch.Value, viewModel.MouseSwitch);
Assert.AreEqual(originalSettings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value, viewModel.MoveWindowsAcrossMonitors);
Assert.AreEqual(originalSettings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value, viewModel.MoveWindowsBasedOnPosition);
Assert.AreEqual(originalSettings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value, viewModel.OpenWindowOnActiveMonitor);
Assert.AreEqual(originalSettings.Properties.FancyzonesOverrideSnapHotkeys.Value, viewModel.OverrideSnapHotkeys);
Assert.AreEqual(originalSettings.Properties.FancyzonesRestoreSize.Value, viewModel.RestoreSize);
Assert.AreEqual(originalSettings.Properties.FancyzonesShiftDrag.Value, viewModel.ShiftDrag);
Assert.AreEqual(originalSettings.Properties.FancyzonesShowOnAllMonitors.Value, viewModel.ShowOnAllMonitors);
Assert.AreEqual(originalSettings.Properties.FancyzonesSpanZonesAcrossMonitors.Value, viewModel.SpanZonesAcrossMonitors);
Assert.AreEqual(originalSettings.Properties.FancyzonesZoneHighlightColor.Value, viewModel.ZoneHighlightColor);
Assert.AreEqual(originalSettings.Properties.FancyzonesZoneSetChangeMoveWindows.Value, viewModel.ZoneSetChangeMoveWindows);
Assert.AreEqual(originalSettings.Properties.UseCursorposEditorStartupscreen.Value, viewModel.UseCursorPosEditorStartupScreen);
2020-11-17 15:29:21 -08:00
// 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);
}
private int ColorPickerIsEnabledByDefault_IPC(string msg)
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsTrue(snd.GeneralSettings.Enabled.ColorPicker);
return 0;
}
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 13:20:32 -07:00
private Mock<ISettingsUtils> mockGeneralSettingsUtils;
private Mock<ISettingsUtils> mockFancyZonesSettingsUtils;
[TestInitialize]
public void SetUpStubSettingUtils()
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 13:20:32 -07:00
{
mockGeneralSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>();
mockFancyZonesSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<FancyZonesSettings>();
}
[TestMethod]
public void IsEnabledShouldDisableModuleWhenSuccessful()
{
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
Assert.IsFalse(snd.GeneralSettings.Enabled.FancyZones);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.IsEnabled = false;
}
[TestMethod]
public void ShiftDragShouldSetValue2FalseWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsFalse(snd.Powertoys.FancyZones.Properties.FancyzonesShiftDrag.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.ShiftDrag = false;
}
[TestMethod]
public void OverrideSnapHotkeysShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOverrideSnapHotkeys.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.OverrideSnapHotkeys = true;
}
[TestMethod]
public void MoveWindowsBasedOnPositionShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMoveWindowsBasedOnPosition.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.MoveWindowsBasedOnPosition = true;
}
[TestMethod]
public void ZoneSetChangeFlashZonesShouldSetValue2FalseWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMakeDraggedWindowTransparent.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.MakeDraggedWindowsTransparent = true;
}
[TestMethod]
public void MouseSwitchShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesMouseSwitch.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.MouseSwitch = true;
}
[TestMethod]
public void DisplayChangeMoveWindowsShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesDisplayChangeMoveWindows.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.DisplayChangeMoveWindows = true;
}
[TestMethod]
public void ZoneSetChangeMoveWindowsShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesZoneSetChangeMoveWindows.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.ZoneSetChangeMoveWindows = true;
}
[TestMethod]
public void AppLastZoneMoveWindowsShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesAppLastZoneMoveWindows.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.AppLastZoneMoveWindows = true;
}
public void OpenWindowOnActiveMonitorShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOpenWindowOnActiveMonitor.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.OpenWindowOnActiveMonitor = true;
}
[TestMethod]
public void RestoreSizeShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesRestoreSize.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.RestoreSize = true;
}
[TestMethod]
public void UseCursorPosEditorStartupScreenShouldSetValue2FalseWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.UseCursorposEditorStartupscreen.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.UseCursorPosEditorStartupScreen = true;
}
[TestMethod]
public void ShowOnAllMonitorsShouldSetValue2TrueWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesShowOnAllMonitors.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
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
viewModel.ShowOnAllMonitors = true;
}
[TestMethod]
public void ZoneHighlightColorShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesZoneHighlightColor.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(ConfigDefaults.DefaultFancyZonesZoneHighlightColor, viewModel.ZoneHighlightColor);
// act
viewModel.ZoneHighlightColor = "#FFFFFF";
}
[TestMethod]
public void ZoneBorderColorShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesBorderColor.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(ConfigDefaults.DefaultFancyzonesBorderColor, viewModel.ZoneBorderColor);
// act
viewModel.ZoneBorderColor = "#FFFFFF";
}
[TestMethod]
public void ZoneInActiveColorShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("#FFFFFF", snd.Powertoys.FancyZones.Properties.FancyzonesInActiveColor.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(ConfigDefaults.DefaultFancyZonesInActiveColor, viewModel.ZoneInActiveColor);
// act
viewModel.ZoneInActiveColor = "#FFFFFF";
}
[TestMethod]
public void ExcludedAppsShouldSetColorValue2WhiteWhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual("Sample", snd.Powertoys.FancyZones.Properties.FancyzonesExcludedApps.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(string.Empty, viewModel.ExcludedApps);
// act
viewModel.ExcludedApps = "Sample";
}
[TestMethod]
public void HighlightOpacityShouldSetOpacityValueTo60WhenSuccessful()
{
// Assert
2020-11-17 15:29:21 -08:00
Func<string, int> sendMockIPCConfigMSG = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.AreEqual(60, snd.Powertoys.FancyZones.Properties.FancyzonesHighlightOpacity.Value);
return 0;
};
// arrange
2020-11-17 15:29:21 -08:00
FancyZonesViewModel viewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SettingsRepository<FancyZonesSettings>.GetInstance(mockFancyZonesSettingsUtils.Object), sendMockIPCConfigMSG, FancyZonesTestFolderName);
Assert.AreEqual(50, viewModel.HighlightOpacity);
// act
viewModel.HighlightOpacity = 60;
}
}
}