Skip to content

Commit 4cd3fbb

Browse files
committed
Tests all compile
1 parent 4a9b07f commit 4cd3fbb

File tree

29 files changed

+488
-499
lines changed

29 files changed

+488
-499
lines changed

src/MaterialDesignThemes.Wpf/ResourceDictionaryExtensions.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This code was generated by mdresgen.
3+
// This code was generated by MaterialDesignToolkit.ResourceGeneration.
44
// </auto-generated>
55
//------------------------------------------------------------------------------
66

src/MaterialDesignThemes.Wpf/Theme.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This code was generated by mdresgen.
3+
// This code was generated by MaterialDesignToolkit.ResourceGeneration.
44
// </auto-generated>
55
//------------------------------------------------------------------------------
66

src/MaterialDesignThemes.Wpf/ThemeExtensions.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This code was generated by mdresgen.
3+
// This code was generated by MaterialDesignToolkit.ResourceGeneration.
44
// </auto-generated>
55
//------------------------------------------------------------------------------
66

src/MaterialDesignToolkit.ResourceGeneration/Brushes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ void WriteBrush(Brush brush, string name)
482482
{{indent}}{{indent}}{
483483
{{indent}}{{indent}}{{indent}}IVisualElement<TextBlock> textBlock = await panel.GetElement<TextBlock>("[Text=\"{{name}}\"]");
484484
{{indent}}{{indent}}{{indent}}Color? textBlockBackground = await textBlock.GetBackgroundColor();
485-
{{indent}}{{indent}}{{indent}}Assert.Equal(await GetResourceColor("{{brush.Name}}"), textBlockBackground);
485+
{{indent}}{{indent}}{{indent}}await Assert.That(textBlockBackground).IsEqualTo(await GetResourceColor("{{brush.Name}}"));
486486
{{indent}}{{indent}}}
487487
""");
488488
}

tests/MaterialDesignThemes.UITests/MaterialDesignSpec.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ public static class MaterialDesignSpec
1717
/// </summary>
1818
public const double MinimumContrastLargeText = 3.0;
1919

20-
public static void AssertContrastRatio(Color foreground, Color background, double minimumContrastRatio)
20+
public static async Task AssertContrastRatio(Color foreground, Color background, double minimumContrastRatio)
2121
{
2222
const double tolerance = 0.1;
2323

24-
var ratio = ColorAssist.ContrastRatio(foreground, background);
25-
await Assert.True(ratio >= minimumContrastRatio - tolerance, $"Contrast ratio '{ratio}' is less than {minimumContrastRatio} with a tolerance of 0.1");
24+
double ratio = ColorAssist.ContrastRatio(foreground, background);
25+
await Assert.That(ratio).IsGreaterThanOrEqualTo(minimumContrastRatio - tolerance)
26+
.Because($"Contrast ratio '{ratio}' is less than {minimumContrastRatio} with a tolerance of 0.1");
2627
}
2728
}

tests/MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<ItemGroup>
3333
<Using Include="MaterialDesignThemes.Wpf" />
34+
<Using Include="MaterialDesignThemes.UITests.TUnit"/>
3435
<Using Include="XamlTest" />
3536
</ItemGroup>
3637

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Numerics;
2+
using System.Runtime.CompilerServices;
3+
using TUnit.Assertions.AssertConditions;
4+
using TUnit.Assertions.AssertConditions.Interfaces;
5+
using TUnit.Assertions.AssertionBuilders;
6+
7+
namespace MaterialDesignThemes.UITests.TUnit;
8+
9+
public static class IsCloseToExtensions
10+
{
11+
public static IsCloseToWrapper<double> IsCloseTo(this IValueSource<double> valueSource, double expected, double precision, [CallerArgumentExpression(nameof(expected))] string? doNotPopulateThisValue1 = null, [CallerArgumentExpression(nameof(precision))] string? doNotPopulateThisValue2 = null)
12+
{
13+
var assertionBuilder = valueSource.RegisterAssertion(new IsCloseToCondition<double>(expected, precision)
14+
, [doNotPopulateThisValue1, doNotPopulateThisValue2]);
15+
16+
return new IsCloseToWrapper<double>(assertionBuilder);
17+
}
18+
19+
public static IsCloseToWrapper<float> IsCloseTo(this IValueSource<float> valueSource, float expected, float precision, [CallerArgumentExpression(nameof(expected))] string? doNotPopulateThisValue1 = null, [CallerArgumentExpression(nameof(precision))] string? doNotPopulateThisValue2 = null)
20+
{
21+
var assertionBuilder = valueSource.RegisterAssertion(new IsCloseToCondition<float>(expected, precision)
22+
, [doNotPopulateThisValue1, doNotPopulateThisValue2]);
23+
24+
return new IsCloseToWrapper<float>(assertionBuilder);
25+
}
26+
}
27+
28+
public class IsCloseToWrapper<TActual>(InvokableAssertionBuilder<TActual> invokableAssertionBuilder)
29+
: InvokableValueAssertionBuilder<TActual>(invokableAssertionBuilder);
30+
31+
file class IsCloseToCondition<TActual>(TActual expected, TActual tolerance) : BaseAssertCondition<TActual>
32+
where TActual :
33+
IFloatingPoint<TActual>,
34+
INumberBase<TActual>
35+
{
36+
protected override string GetExpectation() => $"to be within {tolerance} of {expected}";
37+
38+
protected override ValueTask<AssertionResult> GetResult(
39+
TActual? actualValue, Exception? exception,
40+
AssertionMetadata assertionMetadata
41+
)
42+
{
43+
if(actualValue is null)
44+
return AssertionResult.Fail("received null");
45+
46+
TActual difference = actualValue - expected;
47+
TActual absoluteDifference = TActual.Abs(difference);
48+
bool isInRange = absoluteDifference <= tolerance;
49+
return AssertionResult.FailIf(!isInRange, $"received {actualValue}");
50+
}
51+
}

tests/MaterialDesignThemes.UITests/TestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
namespace MaterialDesignThemes.UITests;
2020

21-
file record SingleParallelLimit : IParallelLimit
21+
public record SingleParallelLimit : IParallelLimit
2222
{
2323
public int Limit => 1;
2424
}
2525

2626
public abstract class TestBase()
2727
{
2828
protected bool AttachedDebuggerToRemoteProcess { get; set; } = true;
29-
protected TextWriter Output => TestContext.Current?.OutputWriter ?? throw new InvalidOperationException("Could not find output writer");
29+
protected static TextWriter Output => TestContext.Current?.OutputWriter ?? throw new InvalidOperationException("Could not find output writer");
3030

3131
[NotNull]
3232
protected IApp? App { get; set; }

tests/MaterialDesignThemes.UITests/WPF/Cards/OutlinedCardTests.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
using System.Windows.Media;
22

3-
43
namespace MaterialDesignThemes.UITests.WPF.Cards;
54

65
public class OutlinedCardTests : TestBase
76
{
8-
public OutlinedCardTests(ITestOutputHelper output)
9-
: base(output)
10-
{ }
11-
127
[Test]
138
public async Task OutlinedCard_UsesThemeColorForBorder()
149
{
@@ -24,7 +19,7 @@ public async Task OutlinedCard_UsesThemeColorForBorder()
2419
Color? internalBorderColor = await internalBorder.GetBorderBrushColor();
2520

2621
//Assert
27-
await Assert.Equal(dividerColor, internalBorderColor);
22+
await Assert.That(internalBorderColor).IsEqualTo(dividerColor);
2823

2924
recorder.Success();
3025
}
@@ -43,10 +38,10 @@ public async Task OutlinedCard_UniformCornerRadiusApplied_AppliesCornerRadiusOnB
4338
CornerRadius? internalBorderCornerRadius = await internalBorder.GetCornerRadius();
4439

4540
//Assert
46-
await Assert.Equal(5, internalBorderCornerRadius.Value.TopLeft);
47-
await Assert.Equal(5, internalBorderCornerRadius.Value.TopRight);
48-
await Assert.Equal(5, internalBorderCornerRadius.Value.BottomRight);
49-
await Assert.Equal(5, internalBorderCornerRadius.Value.BottomLeft);
41+
await Assert.That(internalBorderCornerRadius.Value.TopLeft).IsEqualTo(5);
42+
await Assert.That(internalBorderCornerRadius.Value.TopRight).IsEqualTo(5);
43+
await Assert.That(internalBorderCornerRadius.Value.BottomRight).IsEqualTo(5);
44+
await Assert.That(internalBorderCornerRadius.Value.BottomLeft).IsEqualTo(5);
5045

5146
recorder.Success();
5247
}

tests/MaterialDesignThemes.UITests/WPF/ColorPickerTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
using System.Windows.Media;
22
using MaterialDesignColors.ColorManipulation;
33

4-
54
namespace MaterialDesignThemes.UITests.WPF;
65

76
public class ColorPickerTests : TestBase
87
{
9-
public ColorPickerTests(ITestOutputHelper output)
10-
: base(output)
11-
{
12-
}
13-
148
[Test]
159
public async Task OnLostFocusIfSelectedTimeIsNull_DatePartWillBeToday()
1610
{
@@ -35,7 +29,7 @@ public async Task OnLostFocusIfSelectedTimeIsNull_DatePartWillBeToday()
3529

3630

3731
double currentBrightness = (await colorPicker.GetColor()).ToHsb().Brightness;
38-
await Assert.True(currentBrightness < lastBrightness, $"Brightness {currentBrightness} is not less than {lastBrightness}");
32+
await Assert.That(currentBrightness).IsLessThan(lastBrightness);
3933

4034
recorder.Success();
4135
}

0 commit comments

Comments
 (0)