2022-03-17 20:33:05 +01:00
|
|
|
|
// 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;
|
2025-04-01 15:31:35 +02:00
|
|
|
|
using System.Collections.Generic;
|
2022-03-17 20:33:05 +01:00
|
|
|
|
using System.Reflection;
|
2024-09-16 16:09:43 -04:00
|
|
|
|
|
2022-03-17 20:33:05 +01:00
|
|
|
|
using Microsoft.PowerToys.Run.Plugin.TimeDate.Components;
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
|
public class PluginSettingsTests
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void SettingsCount()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Setup
|
|
|
|
|
|
PropertyInfo[] settings = TimeDateSettings.Instance?.GetType()?.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var result = settings?.Length;
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
2025-04-01 15:31:35 +02:00
|
|
|
|
Assert.AreEqual(7, result);
|
2022-03-17 20:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DataTestMethod]
|
2024-07-18 15:29:01 +02:00
|
|
|
|
[DataRow("CalendarFirstWeekRule")]
|
|
|
|
|
|
[DataRow("FirstDayOfWeek")]
|
2022-03-17 20:33:05 +01:00
|
|
|
|
[DataRow("OnlyDateTimeNowGlobal")]
|
|
|
|
|
|
[DataRow("TimeWithSeconds")]
|
|
|
|
|
|
[DataRow("DateWithWeekday")]
|
|
|
|
|
|
[DataRow("HideNumberMessageOnGlobalQuery")]
|
2025-04-01 15:31:35 +02:00
|
|
|
|
[DataRow("CustomFormats")]
|
2022-03-17 20:33:05 +01:00
|
|
|
|
public void DoesSettingExist(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Setup
|
|
|
|
|
|
Type settings = TimeDateSettings.Instance?.GetType();
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var result = settings?.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DataTestMethod]
|
|
|
|
|
|
[DataRow("OnlyDateTimeNowGlobal", true)]
|
|
|
|
|
|
[DataRow("TimeWithSeconds", false)]
|
|
|
|
|
|
[DataRow("DateWithWeekday", false)]
|
|
|
|
|
|
[DataRow("HideNumberMessageOnGlobalQuery", false)]
|
|
|
|
|
|
public void DefaultValues(string name, bool valueExpected)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Setup
|
|
|
|
|
|
TimeDateSettings setting = TimeDateSettings.Instance;
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
PropertyInfo propertyInfo = setting?.GetType()?.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
var result = propertyInfo?.GetValue(setting);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.AreEqual(valueExpected, result);
|
|
|
|
|
|
}
|
2024-07-18 15:29:01 +02:00
|
|
|
|
|
|
|
|
|
|
[DataTestMethod]
|
|
|
|
|
|
[DataRow("CalendarFirstWeekRule", -1)]
|
|
|
|
|
|
[DataRow("FirstDayOfWeek", -1)]
|
|
|
|
|
|
public void DefaultEnumValues(string name, int valueExpected)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Setup
|
|
|
|
|
|
TimeDateSettings setting = TimeDateSettings.Instance;
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
PropertyInfo propertyInfo = setting?.GetType()?.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
var result = propertyInfo?.GetValue(setting);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.AreEqual(valueExpected, result);
|
|
|
|
|
|
}
|
2025-04-01 15:31:35 +02:00
|
|
|
|
|
|
|
|
|
|
[DataTestMethod]
|
|
|
|
|
|
[DataRow("CustomFormats")]
|
|
|
|
|
|
public void DefaultEmptyMultilineTextValues(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Setup
|
|
|
|
|
|
TimeDateSettings setting = TimeDateSettings.Instance;
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
PropertyInfo propertyInfo = setting?.GetType()?.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
List<string> result = (List<string>)propertyInfo?.GetValue(setting);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.AreEqual(0, result.Count);
|
|
|
|
|
|
}
|
2022-03-17 20:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|