Skip to content

Commit 90a8076

Browse files
committed
Tests are now compiling
1 parent 8678187 commit 90a8076

File tree

12 files changed

+36
-106
lines changed

12 files changed

+36
-106
lines changed

tests/MaterialDesignThemes.Wpf.Tests/ClockTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task CanGenerateHoursButtonsWith24Hours()
2525
var buttonContents = hoursCanvas.GetVisualChildren<ClockItemButton>().Select(x => x.Content.ToString());
2626

2727
var expected = Enumerable.Range(13, 11).Select(x => $"{x:00}")
28-
.Concat(new[] { "00" })
28+
.Concat(["00"])
2929
.Concat(Enumerable.Range(1, 12).Select(x => $"{x:#}"));
3030
await Assert.That(buttonContents.OrderBy(x => x)).IsEqualTo(expected.OrderBy(x => x));
3131
}

tests/MaterialDesignThemes.Wpf.Tests/ColorPickerTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace MaterialDesignThemes.Wpf.Tests;
66
//TODO: Many of these tests could be moved over to MaterialDesignThemes.UITests
77
public class ColorPickerTests
88
{
9-
private readonly ColorPicker _colorPicker;
10-
private readonly Slider _hueSlider;
11-
private readonly Canvas _saturationBrightnessPicker;
12-
private readonly Thumb _saturationBrightnessPickerThumb;
9+
private readonly ColorPicker _colorPicker = new();
10+
private Slider _hueSlider = null!;
11+
private Canvas _saturationBrightnessPicker = null!;
12+
private Thumb _saturationBrightnessPickerThumb = null!;
1313

14-
public ColorPickerTests()
14+
[Before(Test)]
15+
public void Setup()
1516
{
16-
_colorPicker = new ColorPicker();
1717
_colorPicker.ApplyDefaultStyle();
1818
_colorPicker.Arrange(new Rect(0, 0, 400, 100));
1919

tests/MaterialDesignThemes.Wpf.Tests/Converters/MathConverterTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
using System.Globalization;
22
using System.Windows.Data;
33
using MaterialDesignThemes.Wpf.Converters;
4-
using TUnit.Core;
5-
using TUnit.Assertions;
6-
using TUnit.Assertions.Extensions;
7-
using System.Threading.Tasks;
84

95
namespace MaterialDesignThemes.Wpf.Tests.Converters;
106

117
public sealed class MathConverterTests
128
{
139
[Test]
14-
[EnumData]
15-
public async Task EnumValues_AreAllHandled(MathOperation operation)
10+
[MatrixDataSource]
11+
public async Task EnumValues_AreAllHandled(
12+
[EnumData<MathOperation>] MathOperation operation)
1613
{
1714
MathConverter converter = new()
1815
{

tests/MaterialDesignThemes.Wpf.Tests/Converters/MathMultipleConverterTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
using System.Globalization;
22
using MaterialDesignThemes.Wpf.Converters;
3-
using TUnit.Core;
4-
using TUnit.Assertions;
5-
using TUnit.Assertions.Extensions;
6-
using System.Threading.Tasks;
73

84
namespace MaterialDesignThemes.Wpf.Tests.Converters;
95

106
public sealed class MathMultipleConverterTests
117
{
128
[Test]
13-
[EnumData]
14-
public async Task EnumValues_AreAllHandled(MathOperation operation)
9+
[MatrixDataSource]
10+
public async Task EnumValues_AreAllHandled(
11+
[EnumData<MathOperation>]MathOperation operation)
1512
{
1613
MathMultipleConverter converter = new()
1714
{

tests/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44

55
namespace MaterialDesignThemes.Wpf.Tests;
66

7-
public class DialogHostTests : IDisposable
7+
public class DialogHostTests
88
{
9-
private readonly DialogHost _dialogHost;
9+
private readonly DialogHost _dialogHost = new();
1010

11-
public DialogHostTests()
11+
[Before(Test)]
12+
public void Setup()
1213
{
13-
_dialogHost = new DialogHost();
1414
_dialogHost.ApplyDefaultStyle();
1515
_dialogHost.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));
1616
}
1717

18-
public void Dispose()
18+
[After(Test)]
19+
public void Cleanup()
1920
{
2021
_dialogHost.RaiseEvent(new RoutedEventArgs(FrameworkElement.UnloadedEvent));
2122
}
@@ -403,7 +404,7 @@ public async Task WhenOnlySingleDialogHostIdentifierIsNullItShowsDialog()
403404
}
404405

405406
[Test, STAThreadExecutor]
406-
public async Task GetDialogSession_ShouldAllowAccessFromMultipleUIThreads()
407+
public void GetDialogSession_ShouldAllowAccessFromMultipleUIThreads()
407408
{
408409
DialogHost? dialogHost = null;
409410
DialogHost? dialogHostOnOtherUiThread = null;
Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
using System.Reflection;
1+
namespace MaterialDesignThemes.Wpf.Tests;
22

3-
namespace MaterialDesignThemes.Wpf.Tests;
4-
5-
public class EnumDataAttribute : DataAttribute
3+
public class EnumDataAttribute<TEnum> : MatrixAttribute<TEnum>
4+
where TEnum : struct, Enum
65
{
7-
public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData(MethodInfo testMethod, DisposalTracker disposalTracker)
6+
public EnumDataAttribute()
7+
#if NET6_0_OR_GREATER
8+
: base(Enum.GetValues<TEnum>())
9+
#else
10+
: base([.. Enum.GetValues(typeof(TEnum)).OfType<TEnum>()])
11+
#endif
812
{
9-
ParameterInfo[] parameters = testMethod.GetParameters();
10-
if (parameters.Length != 1 ||
11-
!parameters[0].ParameterType.IsEnum)
12-
{
13-
throw new Exception($"{testMethod.DeclaringType?.FullName}.{testMethod.Name} must have a single enum parameter");
14-
}
15-
16-
return new([..GetDataImplementation(parameters[0].ParameterType)]);
1713

18-
static IEnumerable<ITheoryDataRow> GetDataImplementation(Type parameterType)
19-
{
20-
foreach (object enumValue in Enum.GetValues(parameterType).OfType<object>())
21-
{
22-
yield return new TheoryDataRow(enumValue);
23-
}
24-
}
2514
}
26-
public override bool SupportsDiscoveryEnumeration() => true;
2715
}

tests/MaterialDesignThemes.Wpf.Tests/FlipperAssistTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public async Task CardStyle_StyleWithWrongTargetType_AttachedPropertyNotSet()
3030
}
3131

3232
[Test, STAThreadExecutor]
33-
public void CardStyle_StyleWithCorrectTargetType_AttachedPropertySet()
33+
public async Task CardStyle_StyleWithCorrectTargetType_AttachedPropertySet()
3434
{
3535
// Arrange
3636
var style = new Style(typeof(Card));
@@ -43,7 +43,7 @@ public void CardStyle_StyleWithCorrectTargetType_AttachedPropertySet()
4343
}
4444

4545
[Test, STAThreadExecutor]
46-
public void CardStyle_StyleWithDerivedCardTargetType_AttachedPropertySet()
46+
public async Task CardStyle_StyleWithDerivedCardTargetType_AttachedPropertySet()
4747
{
4848
// Arrange
4949
var style = new Style(typeof(DerivedCard));

tests/MaterialDesignThemes.Wpf.Tests/MdixHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ static MdixHelper()
1313

1414
private static ResourceDictionary GenericResourceDictionary => GetResourceDictionary("Generic.xaml");
1515

16-
public static async Task ApplyStyle<T>(this T control, object styleKey, bool applyTemplate = true) where T : FrameworkElement
16+
public static void ApplyStyle<T>(this T control, object styleKey, bool applyTemplate = true) where T : FrameworkElement
1717
{
18-
var style = GetStyle(styleKey);
19-
await Assert.That(style).IsNotNull().Because($"Could not find style with key '{styleKey}' for control type {typeof(T).FullName}");
18+
var style = GetStyle(styleKey) ?? throw new InvalidOperationException($"Could not find style with key '{styleKey}' for control type {typeof(T).FullName}");
19+
2020
control.Style = style;
2121
if (applyTemplate)
2222
{

tests/MaterialDesignThemes.Wpf.Tests/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@
88

99
// The following GUID is for the ID of the typelib if this project is exposed to COM
1010
[assembly: Guid("a361c80e-f6cd-4c57-a96c-002db159c1f4")]
11-
12-
[assembly: CollectionBehavior(DisableTestParallelization = true)]

tests/MaterialDesignThemes.Wpf.Tests/SnackbarMessageQueueItemTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public async Task IsDuplicate_ThrowsOnNullArgument()
77
{
88
SnackbarMessageQueueItem item = CreateItem();
99
var ex = await Assert.That(() => item.IsDuplicate(null!)).ThrowsExactly<ArgumentNullException>();
10-
await Assert.That(ex.ParamName).IsEqualTo("value");
10+
await Assert.That(ex?.ParamName).IsEqualTo("value");
1111
}
1212

1313
[Test]

0 commit comments

Comments
 (0)