/ src / modules / launcher / Plugins / Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests / ImageTests.cs
ImageTests.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Globalization; 6 using System.Linq; 7 8 using Microsoft.VisualStudio.TestTools.UnitTesting; 9 using Moq; 10 using Wox.Infrastructure; 11 using Wox.Plugin; 12 13 namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests 14 { 15 [TestClass] 16 public class ImageTests 17 { 18 private CultureInfo originalCulture; 19 private CultureInfo originalUiCulture; 20 21 [TestInitialize] 22 public void Setup() 23 { 24 StringMatcher.Instance = new StringMatcher(); 25 26 // Set culture to 'en-us' 27 originalCulture = CultureInfo.CurrentCulture; 28 CultureInfo.CurrentCulture = new CultureInfo("en-us", false); 29 originalUiCulture = CultureInfo.CurrentUICulture; 30 CultureInfo.CurrentUICulture = new CultureInfo("en-us", false); 31 } 32 33 [DataTestMethod] 34 [DataRow("time", "Time -", "Images\\time.dark.png")] 35 [DataRow("time u", "Time UTC -", "Images\\time.dark.png")] 36 [DataRow("date", "Date -", "Images\\calendar.dark.png")] 37 [DataRow("now", "Now -", "Images\\timeDate.dark.png")] 38 [DataRow("now u", "Now UTC -", "Images\\timeDate.dark.png")] 39 [DataRow("unix", "Unix epoch time -", "Images\\timeDate.dark.png")] 40 [DataRow("unix epoch time in", "Unix epoch time in milliseconds -", "Images\\timeDate.dark.png")] 41 [DataRow("hour", "Hour -", "Images\\time.dark.png")] 42 [DataRow("minute", "Minute -", "Images\\time.dark.png")] 43 [DataRow("second", "Second -", "Images\\time.dark.png")] 44 [DataRow("millisecond", "Millisecond -", "Images\\time.dark.png")] 45 [DataRow("file", "Windows file time (Int64 number) -", "Images\\timeDate.dark.png")] 46 [DataRow("day", "Day (Week day) -", "Images\\calendar.dark.png")] 47 [DataRow("day of week", "Day of the week (Week day) -", "Images\\calendar.dark.png")] 48 [DataRow("day of month", "Day of the month -", "Images\\calendar.dark.png")] 49 [DataRow("day of year", "Day of the year -", "Images\\calendar.dark.png")] 50 [DataRow("week of month", "Week of the month -", "Images\\calendar.dark.png")] 51 [DataRow("week of year", "Week of the year (Calendar week, Week number) -", "Images\\calendar.dark.png")] 52 [DataRow("month", "Month -", "Images\\calendar.dark.png")] 53 [DataRow("month of year", "Month of the year -", "Images\\calendar.dark.png")] 54 [DataRow("month and", "Month and day -", "Images\\calendar.dark.png")] 55 [DataRow("year", "Year -", "Images\\calendar.dark.png")] 56 [DataRow("era", "Era -", "Images\\calendar.dark.png")] 57 [DataRow("era abb", "Era abbreviation -", "Images\\calendar.dark.png")] 58 [DataRow("month and", "Month and year -", "Images\\calendar.dark.png")] 59 [DataRow("universal", "Universal time format: YYYY-MM-DD hh:mm:ss -", "Images\\timeDate.dark.png")] 60 [DataRow("iso", "ISO 8601 -", "Images\\timeDate.dark.png")] 61 [DataRow("iso utc", "ISO 8601 UTC - ", "Images\\timeDate.dark.png")] 62 [DataRow("iso zone", "ISO 8601 with time zone - ", "Images\\timeDate.dark.png")] 63 [DataRow("iso utc zone", "ISO 8601 UTC with time zone - ", "Images\\timeDate.dark.png")] 64 [DataRow("rfc", "RFC1123 -", "Images\\timeDate.dark.png")] 65 [DataRow("compatible", "Date and time in filename-compatible format", "Images\\timeDate.dark.png")] 66 public void IconThemeDarkTest(string typedString, string subTitleMatch, string expectedResult) 67 { 68 // Setup 69 Mock<Main> main = new(); 70 main.Object.IconTheme = "dark"; 71 Query expectedQuery = new("(" + typedString, "("); 72 73 // Act 74 string result = main.Object.Query(expectedQuery).FirstOrDefault(predicate: x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath; 75 76 // Assert 77 Assert.AreEqual(expectedResult, result); 78 } 79 80 [DataTestMethod] 81 [DataRow("time", "Time -", "Images\\time.light.png")] 82 [DataRow("time u", "Time UTC -", "Images\\time.light.png")] 83 [DataRow("date", "Date -", "Images\\calendar.light.png")] 84 [DataRow("now", "Now -", "Images\\timeDate.light.png")] 85 [DataRow("now u", "Now UTC -", "Images\\timeDate.light.png")] 86 [DataRow("unix", "Unix epoch time -", "Images\\timeDate.light.png")] 87 [DataRow("unix epoch time in", "Unix epoch time in milliseconds -", "Images\\timeDate.light.png")] 88 [DataRow("hour", "Hour -", "Images\\time.light.png")] 89 [DataRow("minute", "Minute -", "Images\\time.light.png")] 90 [DataRow("second", "Second -", "Images\\time.light.png")] 91 [DataRow("millisecond", "Millisecond -", "Images\\time.light.png")] 92 [DataRow("file", "Windows file time (Int64 number) -", "Images\\timeDate.light.png")] 93 [DataRow("day", "Day (Week day) -", "Images\\calendar.light.png")] 94 [DataRow("day of week", "Day of the week (Week day) -", "Images\\calendar.light.png")] 95 [DataRow("day of month", "Day of the month -", "Images\\calendar.light.png")] 96 [DataRow("day of year", "Day of the year -", "Images\\calendar.light.png")] 97 [DataRow("week of month", "Week of the month -", "Images\\calendar.light.png")] 98 [DataRow("week of year", "Week of the year (Calendar week, Week number) -", "Images\\calendar.light.png")] 99 [DataRow("month", "Month -", "Images\\calendar.light.png")] 100 [DataRow("month of year", "Month of the year -", "Images\\calendar.light.png")] 101 [DataRow("month and", "Month and day -", "Images\\calendar.light.png")] 102 [DataRow("year", "Year -", "Images\\calendar.light.png")] 103 [DataRow("era", "Era -", "Images\\calendar.light.png")] 104 [DataRow("era abb", "Era abbreviation -", "Images\\calendar.light.png")] 105 [DataRow("Month and", "Month and year -", "Images\\calendar.light.png")] 106 [DataRow("universal", "Universal time format: YYYY-MM-DD hh:mm:ss -", "Images\\timeDate.light.png")] 107 [DataRow("iso", "ISO 8601 -", "Images\\timeDate.light.png")] 108 [DataRow("iso utc", "ISO 8601 UTC - ", "Images\\timeDate.light.png")] 109 [DataRow("iso zone", "ISO 8601 with time zone - ", "Images\\timeDate.light.png")] 110 [DataRow("iso utc zone", "ISO 8601 UTC with time zone - ", "Images\\timeDate.light.png")] 111 [DataRow("rfc", "RFC1123 -", "Images\\timeDate.light.png")] 112 [DataRow("compatible", "Date and time in filename-compatible format", "Images\\timeDate.light.png")] 113 public void IconThemeLightTest(string typedString, string subTitleMatch, string expectedResult) 114 { 115 // Setup 116 Mock<Main> main = new(); 117 main.Object.IconTheme = "light"; 118 Query expectedQuery = new("(" + typedString, "("); 119 120 // Act 121 var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath; 122 123 // Assert 124 Assert.AreEqual(expectedResult, result); 125 } 126 127 [TestCleanup] 128 public void CleanUp() 129 { 130 // Set culture to original value 131 CultureInfo.CurrentCulture = originalCulture; 132 CultureInfo.CurrentUICulture = originalUiCulture; 133 } 134 } 135 }