Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/build_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Test
timeout-minutes: 20
run: dotnet test ${{ env.solution }} --configuration ${{ inputs.build-configuration }} --no-build --blame-crash --logger GitHubActions
run: dotnet test ${{ env.solution }} --configuration ${{ inputs.build-configuration }} --no-build

- name: Upload Screenshots
if: ${{ always() }}
Expand Down
9 changes: 5 additions & 4 deletions Directory.packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
<!-- https://learn.microsoft.com/nuget/consume-packages/Central-Package-Management?WT.mc_id=DT-MVP-5003472#transitive-pinning -->
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="BluwolfIcons" Version="1.0.1" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageVersion Include="Dragablz" Version="0.0.3.234" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.1" />
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="MahApps.Metro" Version="2.4.11" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
Expand All @@ -21,7 +20,7 @@
<PackageVersion Include="Microsoft.Composition" Version="1.0.31" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="Microsoft.Toolkit.MVVM" Version="7.1.2" />
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
Expand All @@ -32,9 +31,11 @@
<PackageVersion Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.2" />
<PackageVersion Include="System.Memory" Version="4.6.3" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
<PackageVersion Include="TUnit" Version="0.25.21" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="TUnit" Version="1.9.45" />
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.8" />
<PackageVersion Include="XAMLTest" Version="1.3.1-ci662" />
</ItemGroup>
Expand Down
11 changes: 7 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"sdk": {
"version": "10.0.102",
"rollForward": "latestMinor"
}
"sdk": {
"version": "10.0.102",
"rollForward": "latestMinor"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
2 changes: 1 addition & 1 deletion tests/MaterialColorUtilities.Tests/HctTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public sealed class HctTests
{
[Test]
[Skip("Takes a long time to run")]
[Explicit] //Takes a long time to run
[DisplayName("HCT preserves original color for all opaque ARGB values")]
public async Task Hct_Preserves_Original_Color_For_All_Opaque_ARGB()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-windows;net10.0-windows</TargetFrameworks>
<AssemblyTitle>MaterialColorUtilities.Tests</AssemblyTitle>
<Product>MaterialColorUtilities.Tests</Product>
<OutputType>Exe</OutputType>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -18,16 +14,11 @@
<ProjectReference Include="..\..\src\MaterialDesign3.MaterialColorUtilities\MaterialColorUtilities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="TUnit" />
<PackageReference Include="Shouldly" />
</ItemGroup>
<ItemGroup>
<Using Include="TUnit.Assertions.AssertConditions.Throws" />
<Using Include="TUnit.Core.Executors" />
<Using Include="TUnit.Assertions" />
<Using Include="Shouldly" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net8.0-windows;net10.0-windows</TargetFrameworks>
<AssemblyTitle>MaterialDesignColors.Wpf.Tests</AssemblyTitle>
<Product>MaterialDesignColors.Wpf.Tests</Product>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net472'">
<Reference Include="PresentationCore" />
Expand All @@ -24,11 +20,7 @@
<ProjectReference Include="..\..\src\MaterialDesignColors.Wpf\MaterialDesignColors.Wpf.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Private.Uri" />
<PackageReference Include="TUnit" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if NET472
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Method, Inherited = false)]
internal sealed class ModuleInitializerAttribute : Attribute
{
}
#endif
4 changes: 0 additions & 4 deletions tests/MaterialDesignThemes.UITests/AllStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class AllStyles : TestBase
[Arguments("TreeView", "MaterialDesignTreeView")]
public async Task LoadStyleInIsolation_CanBeLoaded(string controlName, string styleName)
{
await using var recorder = new TestRecorder(App);

string applicationResourceXaml = $$"""
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Expand Down Expand Up @@ -78,7 +76,5 @@ await App.Initialize(applicationResourceXaml,
""");

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

recorder.Success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@
<UseWPF>true</UseWPF>
<NoWarn>$(NoWarn);CA1707</NoWarn>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<!--<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="GitHubActionsTestLogger">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="XAMLTest" />
<PackageReference Include="TUnit" />
Expand All @@ -32,4 +26,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\MaterialDesignThemes.Wpf\MaterialDesignThemes.Wpf.csproj" />
</ItemGroup>
</Project>
</Project>
83 changes: 52 additions & 31 deletions tests/MaterialDesignThemes.UITests/TUnit/IsCloseToExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,72 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using TUnit.Assertions.AssertConditions;
using TUnit.Assertions.AssertConditions.Interfaces;
using TUnit.Assertions.AssertionBuilders;
using TUnit.Assertions.Core;

namespace MaterialDesignThemes.Tests.TUnit;

public static class IsCloseToExtensions
{
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)
public static IsCloseToAssertion<double> IsCloseTo(
this IAssertionSource<double> source, double expected, double precision,
[CallerArgumentExpression(nameof(expected))] string? expectedExpression = null,
[CallerArgumentExpression(nameof(precision))] string? precisionExpression = null)
{
var assertionBuilder = valueSource.RegisterAssertion(new IsCloseToCondition<double>(expected, precision)
, [doNotPopulateThisValue1, doNotPopulateThisValue2]);

return new IsCloseToWrapper<double>(assertionBuilder);
source.Context.ExpressionBuilder.Append(".IsCloseTo(");
source.Context.ExpressionBuilder.Append(expectedExpression);
source.Context.ExpressionBuilder.Append(", ");
source.Context.ExpressionBuilder.Append(precisionExpression);
source.Context.ExpressionBuilder.Append(')');
return new IsCloseToAssertion<double>(source.Context, expected, precision);
}

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)
public static IsCloseToAssertion<float> IsCloseTo(
this IAssertionSource<float> source, float expected, float precision,
[CallerArgumentExpression(nameof(expected))] string? expectedExpression = null,
[CallerArgumentExpression(nameof(precision))] string? precisionExpression = null)
{
var assertionBuilder = valueSource.RegisterAssertion(new IsCloseToCondition<float>(expected, precision)
, [doNotPopulateThisValue1, doNotPopulateThisValue2]);

return new IsCloseToWrapper<float>(assertionBuilder);
source.Context.ExpressionBuilder.Append(".IsCloseTo(");
source.Context.ExpressionBuilder.Append(expectedExpression);
source.Context.ExpressionBuilder.Append(", ");
source.Context.ExpressionBuilder.Append(precisionExpression);
source.Context.ExpressionBuilder.Append(')');
return new IsCloseToAssertion<float>(source.Context, expected, precision);
}
}

public class IsCloseToWrapper<TActual>(InvokableAssertionBuilder<TActual> invokableAssertionBuilder)
: InvokableValueAssertionBuilder<TActual>(invokableAssertionBuilder);

file class IsCloseToCondition<TActual>(TActual expected, TActual tolerance) : BaseAssertCondition<TActual>
where TActual :
IFloatingPoint<TActual>,
INumberBase<TActual>
public class IsCloseToAssertion<TValue>(AssertionContext<TValue> context, TValue expected, TValue precision) : Assertion<TValue>(context)
where TValue : IFloatingPoint<TValue>, INumberBase<TValue>
{
protected override string GetExpectation() => $"to be within {tolerance} of {expected}";
protected override string GetExpectation()
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new(15, 1);
defaultInterpolatedStringHandler.AppendLiteral("to be within ");
defaultInterpolatedStringHandler.AppendFormatted($"\"{precision}\"");
defaultInterpolatedStringHandler.AppendLiteral(" of ");
defaultInterpolatedStringHandler.AppendFormatted($"\"{expected}\"");
return defaultInterpolatedStringHandler.ToStringAndClear();
}

protected override ValueTask<AssertionResult> GetResult(
TActual? actualValue, Exception? exception,
AssertionMetadata assertionMetadata
)
protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<TValue> metadata)
{
if(actualValue is null)
return AssertionResult.Fail("received null");
TValue? actualValue = metadata.Value;
Exception? exception = metadata.Exception;
if (exception != null)
{
return Task.FromResult(AssertionResult.Failed("threw " + exception.GetType().FullName));
}
if (actualValue is null)
{
return Task.FromResult(AssertionResult.Failed($"found <null>"));
}

TValue difference = actualValue - expected;
TValue absoluteDifference = TValue.Abs(difference);
bool isInRange = absoluteDifference <= precision;

TActual difference = actualValue - expected;
TActual absoluteDifference = TActual.Abs(difference);
bool isInRange = absoluteDifference <= tolerance;
return AssertionResult.FailIf(!isInRange, $"received {actualValue}");
if (isInRange)
{
return Task.FromResult(AssertionResult.Passed);
}
return Task.FromResult(AssertionResult.Failed($"found {actualValue}"));
}
}
22 changes: 13 additions & 9 deletions tests/MaterialDesignThemes.UITests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Windows.Media;
using MaterialDesignThemes.UITests;
using MaterialDesignThemes.Wpf.Internal;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using TUnit.Core;
using TUnit.Core.Interfaces;

[assembly: ParallelLimiter<SingleParallelLimit>]
Expand All @@ -26,13 +29,16 @@ public record SingleParallelLimit : IParallelLimit
public int Limit => 1;
}

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

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

[NotNull]
public TestRecorder? Recorder { get; set; }

protected async Task<Color> GetThemeColor(string name)
{
Expand All @@ -56,17 +62,15 @@ 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
public Task<IApp> StartApp()
{
return XamlTest.App.StartRemote(new AppOptions
{
#if !DEBUG
MinimizeOtherWindows = !System.Diagnostics.Debugger.IsAttached,
#endif
AllowVisualStudioDebuggerAttach = AttachedDebuggerToRemoteProcess,
LogMessage = Output.WriteLine
});

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