mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[PT Run] TimeDate plugin (#16662)
* create plugin * Update plugin code * fix deps * last changes * unix * new results and small changes * Update settings name * make spellcheck happy * new time/date formats * add comment * code cleanup, installer, signing pipeline * fix unix result * UnitTests * spell fix * Update tests, Timestamp query feature * new formats * last changes * last changes * unit tests and fixes * cjhanges and fixes * fix installer * fix settings class init * context menu * fix tests * add settings tests * update/fix DateTimeResult tests * small improvements * update pipeline * enable analyzer * fixes and improvements * spell fix * dev docs * doc fixes * spell fix * last changes * changes and fixes * fixes and test updates * improvements * last changes * try to fix tests * remove obsolete code * add info to test log * fix search * tag fix * tests * change tests * update dev docs * fix spelling * fix culture for ui strings * improvements based on feedback * improve global search * improve text * docs improvement * add settings note * fix and update tests * fix spelling
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
// 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.Threading;
|
||||
using Microsoft.PowerToys.Run.Plugin.TimeDate.Components;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class StringParserTests
|
||||
{
|
||||
private CultureInfo originalCulture;
|
||||
private CultureInfo originalUiCulture;
|
||||
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
{
|
||||
// Set culture to 'en-us'
|
||||
originalCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo.CurrentCulture = new CultureInfo("en-us");
|
||||
originalUiCulture = CultureInfo.CurrentUICulture;
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("en-us");
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("10/29/2022 17:05:10", true, "G", "10/29/2022 5:05:10 PM")]
|
||||
[DataRow("Saturday, October 29, 2022 5:05:10 PM", true, "G", "10/29/2022 5:05:10 PM")]
|
||||
[DataRow("10/29/2022", true, "d", "10/29/2022")]
|
||||
[DataRow("Saturday, October 29, 2022", true, "d", "10/29/2022")]
|
||||
[DataRow("17:05:10", true, "T", "5:05:10 PM")]
|
||||
[DataRow("5:05:10 PM", true, "T", "5:05:10 PM")]
|
||||
[DataRow("10456", false, "", "")]
|
||||
[DataRow("u10456", true, "", "")] // Value is UTC and can be different based on system
|
||||
[DataRow("ft10456", true, "", "")] // Value is UTC and can be different based on system
|
||||
public void ConvertStringToDateTime(string typedString, bool expectedBool, string stringType, string expectedString)
|
||||
{
|
||||
// Act
|
||||
bool boolResult = TimeAndDateHelper.ParseStringAsDateTime(in typedString, out DateTime result);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expectedBool, boolResult);
|
||||
if (!string.IsNullOrEmpty(expectedString))
|
||||
{
|
||||
Assert.AreEqual(expectedString, result.ToString(stringType, CultureInfo.CurrentCulture));
|
||||
}
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void CleanUp()
|
||||
{
|
||||
// Set culture to original value
|
||||
CultureInfo.CurrentCulture = originalCulture;
|
||||
CultureInfo.CurrentUICulture = originalUiCulture;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user