Skip to content

Commit 7961d66

Browse files
committed
Starting conversion to TUnit
1 parent bc1819a commit 7961d66

39 files changed

+983
-1033
lines changed

Directory.packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
2727
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
2828
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
29+
<PackageVersion Include="TUnit" Version="0.16.28" />
2930
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.8" />
3031
<PackageVersion Include="XAMLTest" Version="1.2.2" />
3132
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
3233
<PackageVersion Include="Xunit.StaFact" Version="2.0.36-alpha" />
3334
<PackageVersion Include="xunit.v3" Version="1.1.0" />
3435
</ItemGroup>
35-
</Project>
36+
</Project>

src/MaterialDesignColors.Wpf/SwatchesProvider.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace MaterialDesignColors;
1212
/// </summary>
1313
public class SwatchesProvider
1414
{
15+
private static readonly object _syncLock = new();
1516
/// <summary>
1617
/// Generates an instance reading swatches from the provided assembly, allowing
1718
/// colours outside of the standard material palette to be loaded provided the are stored in the expected XAML format.
@@ -39,12 +40,7 @@ public SwatchesProvider(Assembly assembly)
3940
Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "primary")?.key),
4041
Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "secondary")?.key)
4142
))
42-
.ToList() ??
43-
#if NETCOREAPP3_1_OR_GREATER
44-
(IEnumerable<Swatch>)Array.Empty<Swatch>();
45-
#else
46-
(IEnumerable<Swatch>)new Swatch[0];
47-
#endif
43+
.ToList() ?? [];
4844
}
4945

5046
/// <summary>
@@ -98,8 +94,12 @@ static Hue GetHue(ResourceDictionary dictionary, DictionaryEntry entry)
9894
if (assemblyName is null || path is null)
9995
return null;
10096

101-
return (ResourceDictionary)Application.LoadComponent(new Uri(
102-
$"/{assemblyName};component/{path.Replace(".baml", ".xaml")}",
103-
UriKind.RelativeOrAbsolute));
97+
lock (_syncLock)
98+
{
99+
//NB: Application.LoadComponent is not thread safe
100+
return (ResourceDictionary)Application.LoadComponent(new Uri(
101+
$"/{assemblyName};component/{path.Replace(".baml", ".xaml")}",
102+
UriKind.RelativeOrAbsolute));
103+
}
104104
}
105105
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
using System.Windows.Media;
22
using MaterialDesignColors.ColorManipulation;
3-
using Xunit;
43

54
namespace MaterialDesignColors.Wpf.Tests;
65

76
public class ColorAssistTests
87
{
9-
[Fact]
10-
public void EnsureContrastRatio_AdjustsColor()
8+
[Test]
9+
public async Task EnsureContrastRatio_AdjustsColor()
1110
{
1211
var background = Color.FromRgb(0xFA, 0xFA, 0xFA);
1312
var foreground = Color.FromRgb(0xFF, 0xC1, 0x07);
1413

1514
var adjusted = foreground.EnsureContrastRatio(background, 3.0f);
1615

1716
double contrastRatio = adjusted.ContrastRatio(background);
18-
Assert.True(contrastRatio >= 2.9);
19-
Assert.True(contrastRatio <= 3.1);
17+
await Assert.That(contrastRatio).IsGreaterThanOrEqualTo(2.9);
18+
await Assert.That(contrastRatio).IsLessThanOrEqualTo(3.1);
2019
}
2120
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
<PackageReference Include="System.Net.Http" />
3232
<PackageReference Include="System.Private.Uri" />
3333
<PackageReference Include="System.Text.RegularExpressions" />
34-
<PackageReference Include="Shouldly" />
35-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
36-
<PackageReference Include="xunit.runner.visualstudio">
37-
<PrivateAssets>all</PrivateAssets>
38-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
39-
</PackageReference>
40-
<PackageReference Include="xunit.v3" />
34+
<PackageReference Include="TUnit" />
4135
</ItemGroup>
4236
</Project>
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,62 @@
1-
using Shouldly;
2-
using Xunit;
3-
4-
namespace MaterialDesignColors.Wpf.Tests;
1+
namespace MaterialDesignColors.Wpf.Tests;
52

63
public class ResourceProviderFixture
74
{
8-
[Fact]
9-
public void ExcludesBlack()
5+
[Test]
6+
public async Task ExcludesBlack()
107
{
118
SwatchesProvider swatchesProvider = new ();
129

1310
bool containsBlack = swatchesProvider.Swatches.Any(
1411
swatch => string.Compare(swatch.Name, "Black", StringComparison.InvariantCultureIgnoreCase) == 0);
1512

16-
containsBlack.ShouldBe(false);
13+
await Assert.That(containsBlack).IsFalse();
1714
}
1815

19-
[Fact]
20-
public void IncludesGrey()
16+
[Test]
17+
public async Task IncludesGrey()
2118
{
2219
SwatchesProvider swatchesProvider = new ();
2320

2421
bool containsBlack = swatchesProvider.Swatches.Any(
2522
swatch => string.Compare(swatch.Name, "Grey", StringComparison.InvariantCultureIgnoreCase) == 0);
2623

27-
containsBlack.ShouldBe(true);
24+
await Assert.That(containsBlack).IsTrue();
2825
}
2926

30-
[Fact]
31-
public void BrownHasNoSecondary()
27+
[Test]
28+
public async Task BrownHasNoSecondary()
3229
{
3330
SwatchesProvider swatchesProvider = new ();
3431

3532
var brownSwatch = swatchesProvider.Swatches.Single(
3633
swatch => swatch.Name == "brown");
3734

38-
brownSwatch.SecondaryHues.ShouldNotBeNull();
39-
brownSwatch.SecondaryHues.Count.ShouldBe(0);
35+
await Assert.That(brownSwatch.SecondaryHues).IsNotNull();
36+
await Assert.That(brownSwatch.SecondaryHues.Count).IsEqualTo(0);
4037
}
4138

42-
[Fact]
43-
public void BrownHasPrimaries()
39+
[Test]
40+
public async Task BrownHasPrimaries()
4441
{
4542
SwatchesProvider swatchesProvider = new ();
4643

4744
var brownSwatch = swatchesProvider.Swatches.Single(
4845
swatch => swatch.Name == "brown");
4946

50-
brownSwatch.PrimaryHues.ShouldNotBeNull();
51-
brownSwatch.PrimaryHues.Count.ShouldBe(10);
47+
await Assert.That(brownSwatch.PrimaryHues).IsNotNull();
48+
await Assert.That(brownSwatch.PrimaryHues.Count).IsEqualTo(10);
5249
}
5350

54-
[Fact]
55-
public void IndigoHasSecondaries()
51+
[Test]
52+
public async Task IndigoHasSecondaries()
5653
{
5754
SwatchesProvider swatchesProvider = new ();
5855

5956
var brownSwatch = swatchesProvider.Swatches.Single(
6057
swatch => swatch.Name == "indigo");
6158

62-
brownSwatch.SecondaryHues.ShouldNotBeNull();
63-
brownSwatch.SecondaryHues.Count.ShouldBe(4);
59+
await Assert.That(brownSwatch.SecondaryHues).IsNotNull();
60+
await Assert.That(brownSwatch.SecondaryHues.Count).IsEqualTo(4);
6461
}
6562
}

tests/MaterialDesignThemes.UITests/AllStyles.cs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
1-
using System.Reflection;
2-
using MaterialDesignColors;
1+
using MaterialDesignColors;
32

43
namespace MaterialDesignThemes.UITests;
54

65
public class AllStyles : TestBase
76
{
8-
public AllStyles(ITestOutputHelper output)
9-
: base(output)
10-
{ }
11-
12-
[Theory]
13-
[InlineData("Button", "MaterialDesignRaisedButton")]
14-
[InlineData("Calendar", "MaterialDesignCalendarPortrait")]
15-
[InlineData("CheckBox", "MaterialDesignCheckBox")]
16-
[InlineData("ComboBox", "MaterialDesignComboBox")]
17-
[InlineData("DataGrid", "MaterialDesignDataGrid")]
18-
[InlineData("DatePicker", "MaterialDesignDatePicker")]
19-
[InlineData("Expander", "MaterialDesignExpander")]
20-
[InlineData("GridSplitter", "MaterialDesignGridSplitter")]
21-
[InlineData("GroupBox", "MaterialDesignGroupBox")]
22-
[InlineData("Label", "MaterialDesignLabel")]
23-
[InlineData("ListBox", "MaterialDesignListBox")]
24-
[InlineData("ListView", "MaterialDesignListView")]
25-
[InlineData("Menu", "MaterialDesignMenu")]
26-
[InlineData("PasswordBox", "MaterialDesignPasswordBox")]
27-
[InlineData("ProgressBar", "MaterialDesignLinearProgressBar")]
28-
[InlineData("RadioButton", "MaterialDesignRadioButton")]
29-
[InlineData("RichTextBox", "MaterialDesignRichTextBox")]
30-
[InlineData("ScrollBar", "MaterialDesignScrollBar")]
31-
[InlineData("ScrollViewer", "MaterialDesignScrollViewer")]
32-
[InlineData("Slider", "MaterialDesignSlider")]
33-
[InlineData("TabControl", "MaterialDesignTabControl")]
34-
[InlineData("TextBox", "MaterialDesignTextBox")]
35-
[InlineData("ToggleButton", "MaterialDesignSwitchToggleButton")]
36-
[InlineData("ToolBar", "MaterialDesignToolBar")]
37-
[InlineData("TreeView", "MaterialDesignTreeView")]
7+
[Test]
8+
[Arguments("Button", "MaterialDesignRaisedButton")]
9+
[Arguments("Calendar", "MaterialDesignCalendarPortrait")]
10+
[Arguments("CheckBox", "MaterialDesignCheckBox")]
11+
[Arguments("ComboBox", "MaterialDesignComboBox")]
12+
[Arguments("DataGrid", "MaterialDesignDataGrid")]
13+
[Arguments("DatePicker", "MaterialDesignDatePicker")]
14+
[Arguments("Expander", "MaterialDesignExpander")]
15+
[Arguments("GridSplitter", "MaterialDesignGridSplitter")]
16+
[Arguments("GroupBox", "MaterialDesignGroupBox")]
17+
[Arguments("Label", "MaterialDesignLabel")]
18+
[Arguments("ListBox", "MaterialDesignListBox")]
19+
[Arguments("ListView", "MaterialDesignListView")]
20+
[Arguments("Menu", "MaterialDesignMenu")]
21+
[Arguments("PasswordBox", "MaterialDesignPasswordBox")]
22+
[Arguments("ProgressBar", "MaterialDesignLinearProgressBar")]
23+
[Arguments("RadioButton", "MaterialDesignRadioButton")]
24+
[Arguments("RichTextBox", "MaterialDesignRichTextBox")]
25+
[Arguments("ScrollBar", "MaterialDesignScrollBar")]
26+
[Arguments("ScrollViewer", "MaterialDesignScrollViewer")]
27+
[Arguments("Slider", "MaterialDesignSlider")]
28+
[Arguments("TabControl", "MaterialDesignTabControl")]
29+
[Arguments("TextBox", "MaterialDesignTextBox")]
30+
[Arguments("ToggleButton", "MaterialDesignSwitchToggleButton")]
31+
[Arguments("ToolBar", "MaterialDesignToolBar")]
32+
[Arguments("TreeView", "MaterialDesignTreeView")]
3833
public async Task LoadStyleInIsolation_CanBeLoaded(string controlName, string styleName)
3934
{
4035
await using var recorder = new TestRecorder(App);
@@ -57,7 +52,7 @@ public async Task LoadStyleInIsolation_CanBeLoaded(string controlName, string st
5752
await App.Initialize(applicationResourceXaml,
5853
Path.GetFullPath("MaterialDesignColors.dll"),
5954
Path.GetFullPath("MaterialDesignThemes.Wpf.dll"),
60-
Assembly.GetExecutingAssembly().Location);
55+
System.Reflection.Assembly.GetExecutingAssembly().Location);
6156

6257
IWindow window = await App.CreateWindow($$"""
6358
<Window
@@ -82,7 +77,7 @@ await App.Initialize(applicationResourceXaml,
8277
</Window>
8378
""");
8479

85-
Assert.True(await window.GetIsVisible());
80+
await Assert.That(await window.GetIsVisible()).IsTrue();
8681

8782
recorder.Success();
8883
}

tests/MaterialDesignThemes.UITests/MaterialDesignSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public static void AssertContrastRatio(Color foreground, Color background, doubl
2222
const double tolerance = 0.1;
2323

2424
var ratio = ColorAssist.ContrastRatio(foreground, background);
25-
Assert.True(ratio >= minimumContrastRatio - tolerance, $"Contrast ratio '{ratio}' is less than {minimumContrastRatio} with a tolerance of 0.1");
25+
await Assert.True(ratio >= minimumContrastRatio - tolerance, $"Contrast ratio '{ratio}' is less than {minimumContrastRatio} with a tolerance of 0.1");
2626
}
2727
}

tests/MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2828
</PackageReference>
29-
<PackageReference Include="xunit.v3" />
29+
<PackageReference Include="TUnit" />
3030
</ItemGroup>
3131

3232
<ItemGroup>
3333
<Using Include="MaterialDesignThemes.Wpf" />
3434
<Using Include="XamlTest" />
35-
<Using Include="Xunit" />
3635
</ItemGroup>
3736

3837
<ItemGroup>

tests/MaterialDesignThemes.UITests/TestBase.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Diagnostics.CodeAnalysis;
22
using System.Windows.Media;
3+
using MaterialDesignThemes.UITests;
4+
using TUnit.Core.Interfaces;
35

4-
[assembly: CollectionBehavior(DisableTestParallelization = true)]
6+
[assembly: ParallelLimiter<SingleParallelLimit>]
57
[assembly: GenerateHelpers(typeof(AutoSuggestBox))]
68
[assembly: GenerateHelpers(typeof(ColorPicker))]
79
[assembly: GenerateHelpers(typeof(DecimalUpDown))]
@@ -16,10 +18,15 @@
1618

1719
namespace MaterialDesignThemes.UITests;
1820

19-
public abstract class TestBase(ITestOutputHelper output) : IAsyncLifetime
21+
file record SingleParallelLimit : IParallelLimit
22+
{
23+
public int Limit => 1;
24+
}
25+
26+
public abstract class TestBase()
2027
{
2128
protected bool AttachedDebuggerToRemoteProcess { get; set; } = true;
22-
protected ITestOutputHelper Output { get; } = output ?? throw new ArgumentNullException(nameof(output));
29+
protected TextWriter Output => TestContext.Current?.OutputWriter ?? throw new InvalidOperationException("Could not find output writer");
2330

2431
[NotNull]
2532
protected IApp? App { get; set; }
@@ -46,6 +53,7 @@ protected async Task<IVisualElement> LoadUserControl(Type userControlType)
4653
return await App.CreateWindowWithUserControl(userControlType);
4754
}
4855

56+
[Before(Test)]
4957
public async ValueTask InitializeAsync() =>
5058
App = await XamlTest.App.StartRemote(new AppOptions
5159
{
@@ -56,5 +64,6 @@ public async ValueTask InitializeAsync() =>
5664
LogMessage = Output.WriteLine
5765
});
5866

67+
[After(Test)]
5968
public async ValueTask DisposeAsync() => await App.DisposeAsync();
6069
}

0 commit comments

Comments
 (0)