Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f9123cf
Updating to xUnit v3 1.x
Keboo Mar 7, 2025
86ee7ba
Adding MTP
Keboo Mar 7, 2025
35dd15d
Starting conversion to TUnit
Keboo Mar 7, 2025
0896401
Tests all compile
Keboo Mar 14, 2025
b025312
Adds cancellation tokens to async delays
Keboo Apr 25, 2025
857fcf0
WIP
Keboo Apr 25, 2025
d90b472
Refactors test suite and updates dependencies
Keboo May 9, 2025
6090704
Updates test framework and fixes assertions
Keboo May 30, 2025
5feeb41
Reverting stupid
Keboo May 30, 2025
a9cfce8
Save point
Keboo May 30, 2025
5fb172e
Assert.True
Keboo May 30, 2025
a89d951
Updates tests to be async
Keboo May 30, 2025
93c173e
Removes TUnit dependencies from tests
Keboo May 30, 2025
e92ae66
Tests are now compiling
Keboo May 30, 2025
dbf6a5b
Updates test framework for DecimalUpDown
Keboo Jun 13, 2025
b8fd9a7
Fixing member data sources
Keboo Jun 13, 2025
8eca7b3
Refactors code for brevity and adds tests
Keboo Jun 13, 2025
5b65a58
Updates screenshot artifact path
Keboo Jun 13, 2025
bd166d4
Fixes artifact upload path
Keboo Jun 20, 2025
66e3264
Updates coordinate assertion method
Keboo Jun 20, 2025
69cd173
Updates NuGet package versions
Keboo Jun 20, 2025
407f626
Fixes UI test failures
Keboo Jun 23, 2025
7b3b253
Fixes combo box test assertion
Keboo Jun 23, 2025
af69b3a
Updates artifact path for .NET 9
Keboo Jun 23, 2025
110e8bc
Adds success recorder in auto suggest box tests
Keboo Jun 23, 2025
dc9a112
Skips flaky GetDialogSession test
Keboo Jun 23, 2025
7a321dd
Skips failing saturation drag test
Keboo Jun 27, 2025
4dafa6b
Ensures DialogHost is properly unloaded
Keboo Jun 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Starting conversion to TUnit
  • Loading branch information
Keboo committed Jun 27, 2025
commit 35dd15d528ed95542f8e73e020cc98f4d7b2d325
3 changes: 2 additions & 1 deletion Directory.packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="TUnit" Version="0.16.28" />
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.8" />
<PackageVersion Include="XAMLTest" Version="1.3.0-ci602" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
<PackageVersion Include="Xunit.StaFact" Version="2.0.36-alpha" />
<PackageVersion Include="xunit.v3" Version="1.1.0" />
</ItemGroup>
</Project>
</Project>
18 changes: 9 additions & 9 deletions src/MaterialDesignColors.Wpf/SwatchesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace MaterialDesignColors;
/// </summary>
public class SwatchesProvider
{
private static readonly object _syncLock = new();
/// <summary>
/// Generates an instance reading swatches from the provided assembly, allowing
/// colours outside of the standard material palette to be loaded provided the are stored in the expected XAML format.
Expand Down Expand Up @@ -39,12 +40,7 @@ public SwatchesProvider(Assembly assembly)
Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "primary")?.key),
Read(assemblyName, x.SingleOrDefault(y => y.match.Groups["type"].Value == "secondary")?.key)
))
.ToList() ??
#if NETCOREAPP3_1_OR_GREATER
(IEnumerable<Swatch>)Array.Empty<Swatch>();
#else
(IEnumerable<Swatch>)new Swatch[0];
#endif
.ToList() ?? [];
}

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

return (ResourceDictionary)Application.LoadComponent(new Uri(
$"/{assemblyName};component/{path.Replace(".baml", ".xaml")}",
UriKind.RelativeOrAbsolute));
lock (_syncLock)
{
//NB: Application.LoadComponent is not thread safe
return (ResourceDictionary)Application.LoadComponent(new Uri(
$"/{assemblyName};component/{path.Replace(".baml", ".xaml")}",
UriKind.RelativeOrAbsolute));
}
}
}
9 changes: 4 additions & 5 deletions tests/MaterialDesignColors.Wpf.Tests/ColorAssistTests.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System.Windows.Media;
using MaterialDesignColors.ColorManipulation;
using Xunit;

namespace MaterialDesignColors.Wpf.Tests;

public class ColorAssistTests
{
[Fact]
public void EnsureContrastRatio_AdjustsColor()
[Test]
public async Task EnsureContrastRatio_AdjustsColor()
{
var background = Color.FromRgb(0xFA, 0xFA, 0xFA);
var foreground = Color.FromRgb(0xFF, 0xC1, 0x07);

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

double contrastRatio = adjusted.ContrastRatio(background);
Assert.True(contrastRatio >= 2.9);
Assert.True(contrastRatio <= 3.1);
await Assert.That(contrastRatio).IsGreaterThanOrEqualTo(2.9);
await Assert.That(contrastRatio).IsLessThanOrEqualTo(3.1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
<PackageReference Include="System.Net.Http" />
<PackageReference Include="System.Private.Uri" />
<PackageReference Include="System.Text.RegularExpressions" />
<PackageReference Include="Shouldly" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" />
<PackageReference Include="TUnit" />
</ItemGroup>
</Project>
41 changes: 19 additions & 22 deletions tests/MaterialDesignColors.Wpf.Tests/ResourceProviderFixture.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
using Shouldly;
using Xunit;

namespace MaterialDesignColors.Wpf.Tests;
namespace MaterialDesignColors.Wpf.Tests;

public class ResourceProviderFixture
{
[Fact]
public void ExcludesBlack()
[Test]
public async Task ExcludesBlack()
{
SwatchesProvider swatchesProvider = new ();

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

containsBlack.ShouldBe(false);
await Assert.That(containsBlack).IsFalse();
}

[Fact]
public void IncludesGrey()
[Test]
public async Task IncludesGrey()
{
SwatchesProvider swatchesProvider = new ();

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

containsBlack.ShouldBe(true);
await Assert.That(containsBlack).IsTrue();
}

[Fact]
public void BrownHasNoSecondary()
[Test]
public async Task BrownHasNoSecondary()
{
SwatchesProvider swatchesProvider = new ();

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

brownSwatch.SecondaryHues.ShouldNotBeNull();
brownSwatch.SecondaryHues.Count.ShouldBe(0);
await Assert.That(brownSwatch.SecondaryHues).IsNotNull();
await Assert.That(brownSwatch.SecondaryHues.Count).IsEqualTo(0);
}

[Fact]
public void BrownHasPrimaries()
[Test]
public async Task BrownHasPrimaries()
{
SwatchesProvider swatchesProvider = new ();

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

brownSwatch.PrimaryHues.ShouldNotBeNull();
brownSwatch.PrimaryHues.Count.ShouldBe(10);
await Assert.That(brownSwatch.PrimaryHues).IsNotNull();
await Assert.That(brownSwatch.PrimaryHues.Count).IsEqualTo(10);
}

[Fact]
public void IndigoHasSecondaries()
[Test]
public async Task IndigoHasSecondaries()
{
SwatchesProvider swatchesProvider = new ();

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

brownSwatch.SecondaryHues.ShouldNotBeNull();
brownSwatch.SecondaryHues.Count.ShouldBe(4);
await Assert.That(brownSwatch.SecondaryHues).IsNotNull();
await Assert.That(brownSwatch.SecondaryHues.Count).IsEqualTo(4);
}
}
63 changes: 29 additions & 34 deletions tests/MaterialDesignThemes.UITests/AllStyles.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
using System.Reflection;
using MaterialDesignColors;
using MaterialDesignColors;

namespace MaterialDesignThemes.UITests;

public class AllStyles : TestBase
{
public AllStyles(ITestOutputHelper output)
: base(output)
{ }

[Theory]
[InlineData("Button", "MaterialDesignRaisedButton")]
[InlineData("Calendar", "MaterialDesignCalendarPortrait")]
[InlineData("CheckBox", "MaterialDesignCheckBox")]
[InlineData("ComboBox", "MaterialDesignComboBox")]
[InlineData("DataGrid", "MaterialDesignDataGrid")]
[InlineData("DatePicker", "MaterialDesignDatePicker")]
[InlineData("Expander", "MaterialDesignExpander")]
[InlineData("GridSplitter", "MaterialDesignGridSplitter")]
[InlineData("GroupBox", "MaterialDesignGroupBox")]
[InlineData("Label", "MaterialDesignLabel")]
[InlineData("ListBox", "MaterialDesignListBox")]
[InlineData("ListView", "MaterialDesignListView")]
[InlineData("Menu", "MaterialDesignMenu")]
[InlineData("PasswordBox", "MaterialDesignPasswordBox")]
[InlineData("ProgressBar", "MaterialDesignLinearProgressBar")]
[InlineData("RadioButton", "MaterialDesignRadioButton")]
[InlineData("RichTextBox", "MaterialDesignRichTextBox")]
[InlineData("ScrollBar", "MaterialDesignScrollBar")]
[InlineData("ScrollViewer", "MaterialDesignScrollViewer")]
[InlineData("Slider", "MaterialDesignSlider")]
[InlineData("TabControl", "MaterialDesignTabControl")]
[InlineData("TextBox", "MaterialDesignTextBox")]
[InlineData("ToggleButton", "MaterialDesignSwitchToggleButton")]
[InlineData("ToolBar", "MaterialDesignToolBar")]
[InlineData("TreeView", "MaterialDesignTreeView")]
[Test]
[Arguments("Button", "MaterialDesignRaisedButton")]
[Arguments("Calendar", "MaterialDesignCalendarPortrait")]
[Arguments("CheckBox", "MaterialDesignCheckBox")]
[Arguments("ComboBox", "MaterialDesignComboBox")]
[Arguments("DataGrid", "MaterialDesignDataGrid")]
[Arguments("DatePicker", "MaterialDesignDatePicker")]
[Arguments("Expander", "MaterialDesignExpander")]
[Arguments("GridSplitter", "MaterialDesignGridSplitter")]
[Arguments("GroupBox", "MaterialDesignGroupBox")]
[Arguments("Label", "MaterialDesignLabel")]
[Arguments("ListBox", "MaterialDesignListBox")]
[Arguments("ListView", "MaterialDesignListView")]
[Arguments("Menu", "MaterialDesignMenu")]
[Arguments("PasswordBox", "MaterialDesignPasswordBox")]
[Arguments("ProgressBar", "MaterialDesignLinearProgressBar")]
[Arguments("RadioButton", "MaterialDesignRadioButton")]
[Arguments("RichTextBox", "MaterialDesignRichTextBox")]
[Arguments("ScrollBar", "MaterialDesignScrollBar")]
[Arguments("ScrollViewer", "MaterialDesignScrollViewer")]
[Arguments("Slider", "MaterialDesignSlider")]
[Arguments("TabControl", "MaterialDesignTabControl")]
[Arguments("TextBox", "MaterialDesignTextBox")]
[Arguments("ToggleButton", "MaterialDesignSwitchToggleButton")]
[Arguments("ToolBar", "MaterialDesignToolBar")]
[Arguments("TreeView", "MaterialDesignTreeView")]
public async Task LoadStyleInIsolation_CanBeLoaded(string controlName, string styleName)
{
await using var recorder = new TestRecorder(App);
Expand All @@ -57,7 +52,7 @@ public async Task LoadStyleInIsolation_CanBeLoaded(string controlName, string st
await App.Initialize(applicationResourceXaml,
Path.GetFullPath("MaterialDesignColors.dll"),
Path.GetFullPath("MaterialDesignThemes.Wpf.dll"),
Assembly.GetExecutingAssembly().Location);
System.Reflection.Assembly.GetExecutingAssembly().Location);

IWindow window = await App.CreateWindow($$"""
<Window
Expand All @@ -82,7 +77,7 @@ await App.Initialize(applicationResourceXaml,
</Window>
""");

Assert.True(await window.GetIsVisible());
await Assert.That(await window.GetIsVisible()).IsTrue();

recorder.Success();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MaterialDesignThemes.UITests/MaterialDesignSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public static void AssertContrastRatio(Color foreground, Color background, doubl
const double tolerance = 0.1;

var ratio = ColorAssist.ContrastRatio(foreground, background);
Assert.True(ratio >= minimumContrastRatio - tolerance, $"Contrast ratio '{ratio}' is less than {minimumContrastRatio} with a tolerance of 0.1");
await Assert.True(ratio >= minimumContrastRatio - tolerance, $"Contrast ratio '{ratio}' is less than {minimumContrastRatio} with a tolerance of 0.1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" />
<PackageReference Include="TUnit" />
</ItemGroup>

<ItemGroup>
<Using Include="MaterialDesignThemes.Wpf" />
<Using Include="XamlTest" />
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 12 additions & 3 deletions tests/MaterialDesignThemes.UITests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.Windows.Media;
using MaterialDesignThemes.UITests;
using TUnit.Core.Interfaces;

[assembly: CollectionBehavior(DisableTestParallelization = true)]
[assembly: ParallelLimiter<SingleParallelLimit>]
[assembly: GenerateHelpers(typeof(AutoSuggestBox))]
[assembly: GenerateHelpers(typeof(ColorPicker))]
[assembly: GenerateHelpers(typeof(DecimalUpDown))]
Expand All @@ -16,10 +18,15 @@

namespace MaterialDesignThemes.UITests;

public abstract class TestBase(ITestOutputHelper output) : IAsyncLifetime
file record SingleParallelLimit : IParallelLimit
{
public int Limit => 1;
}

public abstract class TestBase()
{
protected bool AttachedDebuggerToRemoteProcess { get; set; } = true;
protected ITestOutputHelper Output { get; } = output ?? throw new ArgumentNullException(nameof(output));
protected TextWriter Output => TestContext.Current?.OutputWriter ?? throw new InvalidOperationException("Could not find output writer");

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

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

[After(Test)]
public async ValueTask DisposeAsync() => await App.DisposeAsync();
}
Loading