Skip to content

Commit 574167f

Browse files
authored
Fixing unit tests (#2584)
* Fixing failing unit tests from localization * Fixing NRT warnings
1 parent dfbb682 commit 574167f

14 files changed

+67
-18
lines changed

MaterialDesignColors.Wpf.Tests/MaterialDesignColors.Wpf.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net472;netcoreapp3.1;net5.0-windows</TargetFrameworks>
4+
<TargetFrameworks>net472;netcoreapp3.1;net6.0-windows</TargetFrameworks>
55
<AssemblyTitle>MaterialDesignColors.Wpf.Tests</AssemblyTitle>
66
<Product>MaterialDesignColors.Wpf.Tests</Product>
77
</PropertyGroup>

MaterialDesignColors.Wpf/MaterialDesignColors.Wpf.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<RootNamespace>MaterialDesignColors</RootNamespace>
44
<AssemblyName>MaterialDesignColors</AssemblyName>
5-
<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks>
5+
<TargetFrameworks>net452;netcoreapp3.1;net6.0-windows</TargetFrameworks>
66
<UseWPF>true</UseWPF>
77
<MDIXColorsVersion Condition="$(MDIXColorsVersion) == '' Or $(MDIXColorsVersion) == '*Undefined*'">1.0.1</MDIXColorsVersion>
88
<AssemblyTitle>MaterialDesignColors.Wpf</AssemblyTitle>

MaterialDesignColors.Wpf/SwatchesProvider.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public SwatchesProvider(Assembly assembly)
2626
var resourcesName = assembly.GetName().Name + ".g";
2727
var manager = new ResourceManager(resourcesName, assembly);
2828
var resourceSet = manager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
29-
var dictionaryEntries = resourceSet.OfType<DictionaryEntry>().ToList();
29+
var dictionaryEntries = resourceSet?.OfType<DictionaryEntry>().ToList();
3030
string? assemblyName = assembly.GetName().Name;
3131

3232
var regex = new Regex(@"^themes\/materialdesigncolor\.(?<name>[a-z]+)\.(?<type>primary|accent)\.baml$");
3333

3434
Swatches =
35-
dictionaryEntries
36-
.Select(x => new { key = x.Key.ToString(), match = regex.Match(x.Key.ToString()) })
35+
dictionaryEntries?
36+
.Select(x => new { key = x.Key.ToString(), match = regex.Match(x.Key.ToString() ?? "") })
3737
.Where(x => x.match.Success && x.match.Groups["name"].Value != "black")
3838
.GroupBy(x => x.match.Groups["name"].Value)
3939
.Select(x =>
@@ -43,7 +43,12 @@ public SwatchesProvider(Assembly assembly)
4343
Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "primary")?.key),
4444
Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "accent")?.key)
4545
))
46-
.ToList();
46+
.ToList() ??
47+
#if NETCOREAPP3_1_OR_GREATER
48+
(IEnumerable<Swatch>)Array.Empty<Swatch>();
49+
#else
50+
(IEnumerable<Swatch>)new Swatch[0];
51+
#endif
4752
}
4853

4954
/// <summary>

MaterialDesignThemes.Wpf.Tests/CalendarFormatInfoTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ public class CalendarFormatInfoTests
77
{
88
[StaTheory]
99
[InlineData("en-US", "MMMM yyyy", "yyyy", "ddd,", "MMM d")]
10+
#if NET5_0_OR_GREATER
11+
[InlineData("fr-CA", "MMMM yyyy", "yyyy", "ddd", "d MMM")]
12+
[InlineData("ja-JP", "yyyy年M月", "yyyy年", "M月d日", "dddd")]
13+
#else
1014
[InlineData("fr-CA", "MMMM, yyyy", "yyyy", "ddd", "d MMM")]
1115
[InlineData("ja-JP", "yyyy'年'M'月'", "yyyy年", "M月d日", "dddd")]
16+
#endif
1217
public void TestFromCultureInfo(string cultureName, string yearMonth, string componentThree, string componentTwo, string componentOne)
1318
{
1419
var result = CalendarFormatInfo.FromCultureInfo(CultureInfo.GetCultureInfo(cultureName));

MaterialDesignThemes.Wpf.Tests/ColorDefinitionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private static void AssertXamlColorsInTheme(string xaml, IBaseTheme baseTheme)
4242
Assert.False(themeProperty is null, $"{themePropertyName} from {xaml} not found in {theme.GetType()}");
4343
Assert.NotNull(themeProperty);
4444

45-
Assert.Equal(solidColorBrush.Color, themeProperty!.GetValue(theme));
45+
Assert.Equal(solidColorBrush!.Color, themeProperty!.GetValue(theme));
4646
}
4747
}
4848

MaterialDesignThemes.Wpf.Tests/ColorPickerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void SettingTheColorUpdatesTheControls(string colorName)
5050
{
5151
var converter = new ColorConverter();
5252
// ReSharper disable once PossibleNullReferenceException
53-
Color color = (Color)converter.ConvertFrom(colorName);
53+
Color color = (Color)converter.ConvertFrom(colorName)!;
5454
var hsb = color.ToHsb();
5555

5656
SetColor(color);

MaterialDesignThemes.Wpf.Tests/MaterialDesignThemes.Wpf.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net472;netcoreapp3.1;net5.0-windows</TargetFrameworks>
4+
<TargetFrameworks>net472;netcoreapp3.1;net6.0-windows</TargetFrameworks>
55
<AssemblyTitle>MaterialDesignThemes.Wpf.Tests</AssemblyTitle>
66
<Product>MaterialDesignThemes.Wpf.Tests</Product>
77
</PropertyGroup>

MaterialDesignThemes.Wpf.Tests/TimePickerUnitTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ public static IEnumerable<object[]> GetDisplaysExpectedTextData()
140140

141141
//Spain Spanish
142142
var spainSpanish = CultureInfo.GetCultureInfo("es-ES");
143+
#if NET5_0_OR_GREATER
144+
foreach (var data in GetDisplaysExpectedTextDataForCulture(spainSpanish, am,
145+
"3:05 a. m.", "3:05:09 a. m.", //12 hour short
146+
"03:05 a. m.", "03:05:09 a. m.", //12 hour long
147+
"3:05", "3:05:09", //24 hour short
148+
"03:05", "03:05:09")) //24 hour long
149+
{
150+
yield return data;
151+
}
152+
foreach (var data in GetDisplaysExpectedTextDataForCulture(spainSpanish, pm,
153+
"4:30 p. m.", "4:30:25 p. m.", //12 hour short
154+
"04:30 p. m.", "04:30:25 p. m.", //12 hour long
155+
"16:30", "16:30:25", //24 hour short
156+
"16:30", "16:30:25")) //24 hour long
157+
{
158+
yield return data;
159+
}
160+
#else
143161
foreach (var data in GetDisplaysExpectedTextDataForCulture(spainSpanish, am,
144162
"3:05", "3:05:09", //12 hour short
145163
"03:05", "03:05:09", //12 hour long
@@ -156,9 +174,28 @@ public static IEnumerable<object[]> GetDisplaysExpectedTextData()
156174
{
157175
yield return data;
158176
}
177+
#endif
159178

160179
//Iran Farsi fa-IR
161180
var iranFarsi = CultureInfo.GetCultureInfo("fa-IR");
181+
#if NET5_0_OR_GREATER
182+
foreach (var data in GetDisplaysExpectedTextDataForCulture(iranFarsi, am,
183+
"3:05 قبل‌ازظهر", "3:05:09 قبل‌ازظهر", //12 hour short
184+
"03:05 قبل‌ازظهر", "03:05:09 قبل‌ازظهر", //12 hour long
185+
"3:05", "3:05:09", //24 hour short
186+
"03:05", "03:05:09")) //24 hour long
187+
{
188+
yield return data;
189+
}
190+
foreach (var data in GetDisplaysExpectedTextDataForCulture(iranFarsi, pm,
191+
"4:30 بعدازظهر", "4:30:25 بعدازظهر", //12 hour short
192+
"04:30 بعدازظهر", "04:30:25 بعدازظهر", //12 hour long
193+
"16:30", "16:30:25", //24 hour short
194+
"16:30", "16:30:25")) //24 hour long
195+
{
196+
yield return data;
197+
}
198+
#else
162199
foreach (var data in GetDisplaysExpectedTextDataForCulture(iranFarsi, am,
163200
"3:05 ق.ظ", "3:05:09 ق.ظ", //12 hour short
164201
"03:05 ق.ظ", "03:05:09 ق.ظ", //12 hour long
@@ -175,6 +212,8 @@ public static IEnumerable<object[]> GetDisplaysExpectedTextData()
175212
{
176213
yield return data;
177214
}
215+
#endif
216+
178217
}
179218

180219
private static IEnumerable<object[]> GetDisplaysExpectedTextDataForCulture(CultureInfo culture,

MaterialDesignThemes.Wpf/Converters/SnackbarMessageTypeConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace MaterialDesignThemes.Wpf.Converters
66
{
77
public class SnackbarMessageTypeConverter : TypeConverter
88
{
9-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
9+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
1010
{
1111
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
1212
}
1313

14-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
14+
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
1515
{
1616
var s = value as string;
1717
if (s != null)

MaterialDesignThemes.Wpf/MaterialDateDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static string FormatDate(string format, DateTime displayDate, CultureInf
144144

145145
private void SetDisplayDateOfCalendar(DateTime displayDate)
146146
{
147-
Calendar calendarControl = this.GetVisualAncestry().OfType<Calendar>().FirstOrDefault();
147+
Calendar? calendarControl = this.GetVisualAncestry().OfType<Calendar>().FirstOrDefault();
148148

149149
if (calendarControl != null)
150150
{

0 commit comments

Comments
 (0)