Skip to content

Commit 2a85a27

Browse files
committed
Fixing member data sources
Updates TimePicker unit tests to use MethodDataSource with Func to prevent test data from being eagerly evaluated, resolving issues with the test framework.
1 parent eeb3bd3 commit 2a85a27

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

tests/MaterialDesignThemes.Wpf.Tests/TimePickerUnitTests.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace MaterialDesignThemes.Wpf.Tests;
55

6-
76
public class TimePickerUnitTests
87
{
98
private readonly TimePicker _timePicker;
@@ -28,21 +27,21 @@ public async Task DontOverwriteDate()
2827
[Test, STAThreadExecutor]
2928
[MethodDataSource(nameof(GetDisplaysExpectedTextData))]
3029
public async Task DisplaysExpectedText(CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds,
31-
DateTime? selectedTime, string expectedText)
30+
DateTime selectedTime, string expectedText)
3231
{
3332
_timePicker.Language = XmlLanguage.GetLanguage(culture.IetfLanguageTag);
3433
_timePicker.SelectedTimeFormat = format;
3534
_timePicker.Is24Hours = is24Hour;
3635
_timePicker.WithSeconds = withSeconds;
3736
_timePicker.SelectedTime = selectedTime;
3837

39-
await Assert.That(_timePicker.Text).IsEqualTo(expectedText);
38+
await Assert.That(_timePicker.Text).IsEqualTo( expectedText);
4039
}
4140

4241
[Test, STAThreadExecutor]
4342
[MethodDataSource(nameof(GetParseLocalizedTimeStringData))]
4443
public async Task CanParseLocalizedTimeString(CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds,
45-
string timeString, DateTime? expectedTime)
44+
string timeString, DateTime expectedTime)
4645
{
4746
_timePicker.Language = XmlLanguage.GetLanguage(culture.IetfLanguageTag);
4847
_timePicker.SelectedTimeFormat = format;
@@ -57,15 +56,15 @@ public async Task CanParseLocalizedTimeString(CultureInfo culture, DatePickerFor
5756
await Assert.That(_timePicker.SelectedTime).IsEqualTo(expectedTime);
5857
}
5958

60-
public static IEnumerable<(CultureInfo culture,
59+
public static IEnumerable<Func<(CultureInfo culture,
6160
DatePickerFormat format,
6261
bool is24Hour,
6362
bool withSeconds,
6463
string timeString,
65-
DateTime expectedTime)> GetParseLocalizedTimeStringData()
64+
DateTime expectedTime)>> GetParseLocalizedTimeStringData()
6665
{
6766
//for now just using the same set of data to make sure we can go both directions.
68-
foreach ((CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds, DateTime date, string timeString) in GetDisplaysExpectedTextData())
67+
foreach ((CultureInfo culture, DatePickerFormat format, bool is24Hour, bool withSeconds, DateTime date, string timeString) in GetDisplaysExpectedTextData().Select(x => x()))
6968
{
7069
//Convert the date to Today
7170
var newDate = DateTime.MinValue.AddHours(date.Hour).AddMinutes(date.Minute).AddSeconds(withSeconds ? date.Second : 0);
@@ -79,18 +78,18 @@ public async Task CanParseLocalizedTimeString(CultureInfo culture, DatePickerFor
7978
}
8079

8180
//Invert the order of the parameters.
82-
yield return (culture, format, is24Hour, withSeconds, timeString, date);
81+
yield return () => (culture, format, is24Hour, withSeconds, timeString, date);
8382
}
8483
}
8584

86-
public static IEnumerable<
85+
public static IEnumerable<Func<
8786
(CultureInfo culture,
8887
DatePickerFormat format,
8988
bool is24Hour,
9089
bool withSeconds,
9190
DateTime dateTime,
9291
string expectedText)
93-
> GetDisplaysExpectedTextData()
92+
>> GetDisplaysExpectedTextData()
9493
{
9594
//AM intentionally picks values with only a single digit to verify the DatePickerFormat is applied
9695
var am = new DateTime(2000, 1, 1, 3, 5, 9);
@@ -104,15 +103,15 @@ public static IEnumerable<
104103
"3:05", "3:05:09", //24 hour short
105104
"03:05", "03:05:09")) //24 hour long
106105
{
107-
yield return data;
106+
yield return () => data;
108107
}
109108
foreach (var data in GetDisplaysExpectedTextDataForCulture(CultureInfo.InvariantCulture, pm,
110109
"4:30 PM", "4:30:25 PM", //12 hour short
111110
"04:30 PM", "04:30:25 PM", //12 hour long
112111
"16:30", "16:30:25", //24 hour short
113112
"16:30", "16:30:25")) //24 hour long
114113
{
115-
yield return data;
114+
yield return () => data;
116115
}
117116

118117
//US English
@@ -123,15 +122,15 @@ public static IEnumerable<
123122
"3:05", "3:05:09", //24 hour short
124123
"03:05", "03:05:09")) //24 hour long
125124
{
126-
yield return data;
125+
yield return () => data;
127126
}
128127
foreach (var data in GetDisplaysExpectedTextDataForCulture(usEnglish, pm,
129128
"4:30 PM", "4:30:25 PM", //12 hour short
130129
"04:30 PM", "04:30:25 PM", //12 hour long
131130
"16:30", "16:30:25", //24 hour short
132131
"16:30", "16:30:25")) //24 hour long
133132
{
134-
yield return data;
133+
yield return () => data;
135134
}
136135

137136
//Spain Spanish
@@ -143,15 +142,15 @@ public static IEnumerable<
143142
"3:05", "3:05:09", //24 hour short
144143
"03:05", "03:05:09")) //24 hour long
145144
{
146-
yield return data;
145+
yield return () => data;
147146
}
148147
foreach (var data in GetDisplaysExpectedTextDataForCulture(spainSpanish, pm,
149148
"4:30 p. m.", "4:30:25 p. m.", //12 hour short
150149
"04:30 p. m.", "04:30:25 p. m.", //12 hour long
151150
"16:30", "16:30:25", //24 hour short
152151
"16:30", "16:30:25")) //24 hour long
153152
{
154-
yield return data;
153+
yield return () => data;
155154
}
156155
#else
157156
foreach (var data in GetDisplaysExpectedTextDataForCulture(spainSpanish, am,
@@ -160,15 +159,15 @@ public static IEnumerable<
160159
"3:05", "3:05:09", //24 hour short
161160
"03:05", "03:05:09")) //24 hour long
162161
{
163-
yield return data;
162+
yield return () => data;
164163
}
165164
foreach (var data in GetDisplaysExpectedTextDataForCulture(spainSpanish, pm,
166165
"4:30", "4:30:25", //12 hour short
167166
"04:30", "04:30:25", //12 hour long
168167
"16:30", "16:30:25", //24 hour short
169168
"16:30", "16:30:25")) //24 hour long
170169
{
171-
yield return data;
170+
yield return () => data;
172171
}
173172
#endif
174173

@@ -181,15 +180,15 @@ public static IEnumerable<
181180
"3:05", "3:05:09", //24 hour short
182181
"03:05", "03:05:09")) //24 hour long
183182
{
184-
yield return data;
183+
yield return () => data;
185184
}
186185
foreach (var data in GetDisplaysExpectedTextDataForCulture(iranFarsi, pm,
187186
"4:30 بعدازظهر", "4:30:25 بعدازظهر", //12 hour short
188187
"04:30 بعدازظهر", "04:30:25 بعدازظهر", //12 hour long
189188
"16:30", "16:30:25", //24 hour short
190189
"16:30", "16:30:25")) //24 hour long
191190
{
192-
yield return data;
191+
yield return () => data;
193192
}
194193
#else
195194
foreach (var data in GetDisplaysExpectedTextDataForCulture(iranFarsi, am,
@@ -198,15 +197,15 @@ public static IEnumerable<
198197
"3:05", "3:05:09", //24 hour short
199198
"03:05", "03:05:09")) //24 hour long
200199
{
201-
yield return data;
200+
yield return () => data;
202201
}
203202
foreach (var data in GetDisplaysExpectedTextDataForCulture(iranFarsi, pm,
204203
"4:30 ب.ظ", "4:30:25 ب.ظ", //12 hour short
205204
"04:30 ب.ظ", "04:30:25 ب.ظ", //12 hour long
206205
"16:30", "16:30:25", //24 hour short
207206
"16:30", "16:30:25")) //24 hour long
208207
{
209-
yield return data;
208+
yield return () => data;
210209
}
211210
#endif
212211

0 commit comments

Comments
 (0)