Browse Source

Update to xunit.v3 (#20331)

* Update to xunit.v3

* Little more progress

* More fixes

* Keep VSTest supported

* Adjust Nuke

* Few fixes

* Fix for xunit 2

* Fix GetData override

* Adjust

* Use MTP for xunit 2

* Fix test

* Better fix

* --no-progress

* Few more fixes

* no progress

* Fix test

* Better fix

* TRX

* Move to Directory.Build.props

* Unify on MTP v2

* Update

* Update to stable

* 1.0.1

* 1.0.2

* Fix some warnings

* Fix more warnings

* Fix more warnings
pull/20249/merge
Youssef Victor 4 weeks ago
committed by GitHub
parent
commit
c9e210eb70
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      azure-pipelines-integrationtests.yml
  2. 14
      build/XUnit.props
  3. 3
      global.json
  4. 16
      nukebuild/Build.cs
  5. 10
      nukebuild/DotNetConfigHelper.cs
  6. 2
      tests/Avalonia.Base.UnitTests/Animation/AnimatableTests.cs
  7. 16
      tests/Avalonia.Base.UnitTests/Animation/AnimationIterationTests.cs
  8. 8
      tests/Avalonia.Base.UnitTests/Animation/KeySplineTests.cs
  9. 2
      tests/Avalonia.Base.UnitTests/Animation/SpringTests.cs
  10. 2
      tests/Avalonia.Base.UnitTests/Avalonia.Base.UnitTests.csproj
  11. 2
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs
  12. 1
      tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs
  13. 12
      tests/Avalonia.Base.UnitTests/Composition/CompositionAnimationTests.cs
  14. 2
      tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.Indexer.cs
  15. 2
      tests/Avalonia.Base.UnitTests/Data/Core/Plugins/IndeiValidationPluginTests.cs
  16. 24
      tests/Avalonia.Base.UnitTests/DispatcherTests.Exception.cs
  17. 14
      tests/Avalonia.Base.UnitTests/DispatcherTests.cs
  18. 2
      tests/Avalonia.Base.UnitTests/Input/KeyboardNavigationTests_Tab.cs
  19. 2
      tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs
  20. 1
      tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiAlgorithmTests.cs
  21. 1
      tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTests.cs
  22. 1
      tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakClassTrieGeneratorTests.cs
  23. 1
      tests/Avalonia.Base.UnitTests/Media/TextFormatting/LineBreakEnumeratorTests.cs
  24. 1
      tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj
  25. 2
      tests/Avalonia.Build.Tasks.UnitTest/Avalonia.Build.Tasks.UnitTest.csproj
  26. 2
      tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj
  27. 4
      tests/Avalonia.Controls.UnitTests/ButtonTests.cs
  28. 2
      tests/Avalonia.Controls.UnitTests/CalendarDatePickerTests.cs
  29. 12
      tests/Avalonia.Controls.UnitTests/DatePickerTests.cs
  30. 2
      tests/Avalonia.Controls.UnitTests/GridLengthTests.cs
  31. 1
      tests/Avalonia.Controls.UnitTests/GridTests.cs
  32. 10
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs
  33. 6
      tests/Avalonia.Controls.UnitTests/LoadedTests.cs
  34. 14
      tests/Avalonia.Controls.UnitTests/MenuItemTests.cs
  35. 16
      tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs
  36. 22
      tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs
  37. 10
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
  38. 4
      tests/Avalonia.Controls.UnitTests/TimePickerTests.cs
  39. 1
      tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs
  40. 8
      tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs
  41. 2
      tests/Avalonia.Controls.UnitTests/WindowTests.cs
  42. 2
      tests/Avalonia.DesignerSupport.Tests/Avalonia.DesignerSupport.Tests.csproj
  43. 9
      tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs
  44. 6
      tests/Avalonia.DesignerSupport.Tests/RemoteProtocolTests.cs
  45. 2
      tests/Avalonia.Generators.Tests/InitializeComponent/InitializeComponentTests.cs
  46. 2
      tests/Avalonia.Generators.Tests/OnlyProperties/OnlyPropertiesTests.cs
  47. 3
      tests/Avalonia.Headless.NUnit.PerAssembly.UnitTests/Avalonia.Headless.NUnit.PerAssembly.UnitTests.csproj
  48. 3
      tests/Avalonia.Headless.NUnit.PerTest.UnitTests/Avalonia.Headless.NUnit.PerTest.UnitTests.csproj
  49. 2
      tests/Avalonia.Headless.XUnit.PerAssembly.UnitTests/Avalonia.Headless.XUnit.PerAssembly.UnitTests.csproj
  50. 2
      tests/Avalonia.Headless.XUnit.PerTest.UnitTests/Avalonia.Headless.XUnit.PerTest.UnitTests.csproj
  51. 8
      tests/Avalonia.IntegrationTests.Appium/Avalonia.IntegrationTests.Appium.csproj
  52. 30
      tests/Avalonia.IntegrationTests.Appium/PlatformFactAttribute.cs
  53. 22
      tests/Avalonia.IntegrationTests.Appium/PlatformTheoryAttribute.cs
  54. 3
      tests/Avalonia.IntegrationTests.Win32/Avalonia.IntegrationTests.Win32.csproj
  55. 1
      tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj
  56. 8
      tests/Avalonia.LeakTests/ReleaseFact.cs
  57. 2
      tests/Avalonia.Markup.UnitTests/Avalonia.Markup.UnitTests.csproj
  58. 2
      tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs
  59. 8
      tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_Indexer.cs
  60. 12
      tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj
  61. 2
      tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Method.cs
  62. 2
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs
  63. 2
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs
  64. 3
      tests/Avalonia.RenderTests.WpfCompare/Avalonia.RenderTests.WpfCompare.csproj
  65. 13
      tests/Avalonia.RenderTests.WpfCompare/CrossFact.cs
  66. 4
      tests/Avalonia.RenderTests/Composition/DirectFbCompositionTests.cs
  67. 13
      tests/Avalonia.RenderTests/TestSkip.cs
  68. 1
      tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj
  69. 14
      tests/Avalonia.Skia.RenderTests/CrossTestBase.cs
  70. 1
      tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj
  71. 9
      tests/Avalonia.Skia.UnitTests/Win32Fact.cs
  72. 8
      tests/Avalonia.Skia.UnitTests/Win32Theory.cs
  73. 2
      tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj
  74. 10
      tests/Avalonia.UnitTests/InvariantCultureAttribute.cs
  75. 9
      tests/Avalonia.UnitTests/UnitTestApplication.cs
  76. 10
      tests/Avalonia.UnitTests/UseEmptyDesignatorCultureAttribute.cs
  77. 4
      tests/Avalonia.UnitTests/VerifyEmptyDispatcherAfterTestAttribute.cs
  78. 5
      tests/Directory.Build.props

3
azure-pipelines-integrationtests.yml

@ -43,7 +43,7 @@ jobs:
inputs:
command: 'test'
projects: 'tests/Avalonia.IntegrationTests.Appium/Avalonia.IntegrationTests.Appium.csproj'
arguments: '-l "console;verbosity=detailed"'
arguments: '--no-progress'
- script: |
pkill IntegrationTestApp
@ -94,6 +94,7 @@ jobs:
inputs:
command: 'run'
projects: 'tests/Avalonia.IntegrationTests.Win32/Avalonia.IntegrationTests.Win32.csproj'
arguments: '--no-progress'
- task: VSTest@2
displayName: 'Run Appium Integration Tests'

14
build/XUnit.props

@ -1,14 +1,10 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ItemGroup Condition="'$(IsXUnit2)'!='true'">
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.1" />
</ItemGroup>
<ItemGroup Condition="'$(IsXUnit2)'=='true'">
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.assert" Version="2.9.3" />
<PackageReference Include="xunit.core" Version="2.9.3" />
<PackageReference Include="xunit.extensibility.core" Version="2.9.3" />
<PackageReference Include="xunit.extensibility.execution" Version="2.9.3" />
<PackageReference Include="xunit.runner.console" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" Condition="'$(TargetFramework)' != 'netstandard2.0'" />
<PackageReference Include="Xunit.SkippableFact" Version="1.5.23" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="YTest.MTP.XUnit2" Version="1.0.2" />
</ItemGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\avalonia.snk</AssemblyOriginatorKeyFile>

3
global.json

@ -3,6 +3,9 @@
"version": "10.0.101",
"rollForward": "latestFeature"
},
"test": {
"runner": "Microsoft.Testing.Platform"
},
"msbuild-sdks": {
"Microsoft.Build.Traversal": "4.1.0"
}

16
nukebuild/Build.cs

@ -111,6 +111,9 @@ partial class Build : NukeBuild
DotNetTestSettings ApplySetting(DotNetTestSettings c, Configure<DotNetTestSettings> configurator = null) =>
ApplySettingCore(c).Test.Apply(configurator);
DotNetRunSettings ApplySetting(DotNetRunSettings c, Configure<DotNetRunSettings> configurator = null) =>
ApplySettingCore(c).Run.Apply(configurator);
Target Clean => _ => _.Executes(() =>
{
foreach (var buildDir in Parameters.BuildDirs)
@ -182,7 +185,10 @@ partial class Build : NukeBuild
{
RunCoreTest(projectName, (project, tfm) =>
{
DotNetTest(c => ApplySetting(c, project,tfm));
// NOTE: Nuke DotNetTest doesn't support Microsoft.Testing.Platform yet.
// Issue: https://github.com/nuke-build/nuke/issues/1584.
// However, we can easily use DotNetRun instead since MTP projects are executables.
DotNetRun(c => ApplySetting(c, project, tfm));
});
}
@ -236,15 +242,17 @@ partial class Build : NukeBuild
}
}
DotNetTestSettings ApplySetting(DotNetTestSettings settings, string project, string tfm) =>
DotNetRunSettings ApplySetting(DotNetRunSettings settings, string project, string tfm) =>
ApplySetting(settings)
.SetProjectFile(project)
.SetFramework(tfm)
.EnableNoBuild()
.EnableNoRestore()
// Disable progress output (works like terminal logger which isn't so nice in CI).
// See https://github.com/microsoft/testfx/issues/7056
.AddApplicationArguments("--no-progress")
.When(_ => Parameters.PublishTestResults, _ => _
.SetLoggers("trx")
.SetResultsDirectory(Parameters.TestResultsRoot));
.AddApplicationArguments("--report-trx", "--results-directory", Parameters.TestResultsRoot));
Target RunHtmlPreviewerTests => _ => _
.OnlyWhenStatic(() => !(Parameters.SkipTests))

10
nukebuild/DotNetConfigHelper.cs

@ -7,6 +7,7 @@ public class DotNetConfigHelper
public DotNetBuildSettings Build;
public DotNetPackSettings Pack;
public DotNetTestSettings Test;
public DotNetRunSettings Run;
public DotNetConfigHelper(DotNetBuildSettings s)
{
@ -23,6 +24,11 @@ public class DotNetConfigHelper
Test = s;
}
public DotNetConfigHelper(DotNetRunSettings s)
{
Run = s;
}
public DotNetConfigHelper AddProperty(string key, bool value) =>
AddProperty(key, value.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
public DotNetConfigHelper AddProperty(string key, string value)
@ -30,6 +36,7 @@ public class DotNetConfigHelper
Build = Build?.AddProperty(key, value);
Pack = Pack?.AddProperty(key, value);
Test = Test?.AddProperty(key, value);
Run = Run?.AddProperty(key, value);
return this;
}
@ -39,6 +46,7 @@ public class DotNetConfigHelper
Build = Build?.SetConfiguration(configuration);
Pack = Pack?.SetConfiguration(configuration);
Test = Test?.SetConfiguration(configuration);
Run = Run?.SetConfiguration(configuration);
return this;
}
@ -47,10 +55,12 @@ public class DotNetConfigHelper
Build = Build?.SetVerbosity(verbosity);
Pack = Pack?.SetVerbosity(verbosity);
Test = Test?.SetVerbosity(verbosity);
Run = Run?.SetVerbosity(verbosity);
return this;
}
public static implicit operator DotNetConfigHelper(DotNetBuildSettings s) => new DotNetConfigHelper(s);
public static implicit operator DotNetConfigHelper(DotNetPackSettings s) => new DotNetConfigHelper(s);
public static implicit operator DotNetConfigHelper(DotNetTestSettings s) => new DotNetConfigHelper(s);
public static implicit operator DotNetConfigHelper(DotNetRunSettings s) => new DotNetConfigHelper(s);
}

2
tests/Avalonia.Base.UnitTests/Animation/AnimatableTests.cs

@ -127,7 +127,7 @@ namespace Avalonia.Base.UnitTests.Animation
var rect = new Rectangle() { Width = 11, };
var clock = new TestClock();
animation.RunAsync(rect, clock);
animation.RunAsync(rect, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
Assert.Equal(1, rect.Width);

16
tests/Avalonia.Base.UnitTests/Animation/AnimationIterationTests.cs

@ -34,7 +34,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(border, clock);
animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
Assert.Equal(border.Width, 0d);
@ -69,7 +69,7 @@ namespace Avalonia.Base.UnitTests.Animation
var border = new Border() { Height = 100d, Width = 100d };
var clock = new TestClock();
var animationRun = animation.RunAsync(border, clock);
var animationRun = animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
border.Measure(Size.Infinity);
border.Arrange(new Rect(border.DesiredSize));
@ -118,7 +118,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(border, clock);
animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.FromSeconds(0d));
Assert.Equal(border.Width, 0d);
@ -167,7 +167,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(border, clock);
animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
@ -211,7 +211,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(border, clock);
animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.FromSeconds(0));
clock.Step(TimeSpan.FromSeconds(20));
@ -495,7 +495,7 @@ namespace Avalonia.Base.UnitTests.Animation
};
var clock = new TestClock();
var animationRun = animation.RunAsync(border, clock);
var animationRun = animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
Assert.Equal(1, animator.CallCount);
@ -556,7 +556,7 @@ namespace Avalonia.Base.UnitTests.Animation
};
var clock = new TestClock();
animation.RunAsync(border, clock);
animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
Assert.Equal(100.0, border.Width);
@ -597,7 +597,7 @@ namespace Avalonia.Base.UnitTests.Animation
};
var clock = new TestClock();
animation.RunAsync(border, clock);
animation.RunAsync(border, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
clock.Step(TimeSpan.FromSeconds(cue));

8
tests/Avalonia.Base.UnitTests/Animation/KeySplineTests.cs

@ -130,7 +130,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(rect, clock);
animation.RunAsync(rect, clock, TestContext.Current.CancellationToken);
// position is what you'd expect at end and beginning
clock.Step(TimeSpan.Zero);
@ -185,7 +185,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(rect, clock);
animation.RunAsync(rect, clock, TestContext.Current.CancellationToken);
// position is what you'd expect at end and beginning
clock.Step(TimeSpan.Zero);
@ -250,7 +250,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(rect, clock);
animation.RunAsync(rect, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
Assert.Equal(10.0, transform.Y, 0.0001);
@ -299,7 +299,7 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
animation.RunAsync(rect, clock);
animation.RunAsync(rect, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
Assert.Equal(50.0, transform.Y, 0.0001);

2
tests/Avalonia.Base.UnitTests/Animation/SpringTests.cs

@ -77,7 +77,7 @@ public class SpringTests
var rect = new Rectangle() { RenderTransform = rotateTransform };
var clock = new TestClock();
animation.RunAsync(rect, clock);
animation.RunAsync(rect, clock, TestContext.Current.CancellationToken);
clock.Step(TimeSpan.Zero);
Assert.Equal(-2.5, rotateTransform.Angle);

2
tests/Avalonia.Base.UnitTests/Avalonia.Base.UnitTests.csproj

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<IsTestProject>true</IsTestProject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

2
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs

@ -985,7 +985,7 @@ namespace Avalonia.Base.UnitTests
{
target.Bind(Class1.QuxProperty, source);
await Task.Run(() => source.OnNext(6.7));
await Task.Run(() => source.OnNext(6.7), TestContext.Current.CancellationToken);
}
}

1
tests/Avalonia.Base.UnitTests/AvaloniaPropertyRegistryTests.cs

@ -2,7 +2,6 @@ using System;
using System.Linq;
using System.Reactive.Linq;
using Xunit;
using Xunit.Abstractions;
namespace Avalonia.Base.UnitTests
{

12
tests/Avalonia.Base.UnitTests/Composition/CompositionAnimationTests.cs

@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Avalonia.Animation.Easings;
using Avalonia.Base.UnitTests.Rendering;
using Avalonia.Rendering;
@ -12,6 +13,7 @@ using Avalonia.Threading;
using Avalonia.UnitTests;
using Xunit;
using Xunit.Sdk;
using Xunit.v3;
namespace Avalonia.Base.UnitTests.Composition;
@ -54,13 +56,19 @@ public class CompositionAnimationTests : ScopedTestBase
}
};
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData(MethodInfo testMethod, DisposalTracker disposalTracker)
{
var list = new List<ITheoryDataRow>();
foreach (var ani in Generate())
{
yield return new Object[] { ani };
list.Add(new TheoryDataRow<AnimationData>(ani));
}
return ValueTask.FromResult<IReadOnlyCollection<ITheoryDataRow>>(list);
}
public override bool SupportsDiscoveryEnumeration()
=> true;
}
class DummyDispatcher : IDispatcher

2
tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.Indexer.cs

@ -182,7 +182,7 @@ public partial class BindingExpressionTests
data.Foo["foo"] = "bar2";
// Forces WeakEvent compact
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal("bar2", target.String);

2
tests/Avalonia.Base.UnitTests/Data/Core/Plugins/IndeiValidationPluginTests.cs

@ -61,7 +61,7 @@ namespace Avalonia.Base.UnitTests.Data.Core.Plugins
Assert.Equal(1, data.ErrorsChangedSubscriptionCount);
validator.Unsubscribe();
// Forces WeakEvent compact
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
}

24
tests/Avalonia.Base.UnitTests/DispatcherTests.Exception.cs

@ -37,7 +37,7 @@ public partial class DispatcherTests
disp.Post(() => ThrowAnException());
disp.Post(() => executed = true);
disp.RunJobs();
disp.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(handled);
Assert.True(executed);
@ -62,7 +62,7 @@ public partial class DispatcherTests
syncContext.Post(_ => ThrowAnException(), null);
syncContext.Post(_ => executed = true, null);
disp.RunJobs();
disp.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(handled);
Assert.True(executed);
@ -88,7 +88,7 @@ public partial class DispatcherTests
try
{
dispatcher.Post(ThrowAnException, DispatcherPriority.Normal);
dispatcher.RunJobs();
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception e)
{
@ -115,7 +115,7 @@ public partial class DispatcherTests
try
{
dispatcher.Post(ThrowAnException, DispatcherPriority.Normal);
dispatcher.RunJobs();
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception)
{
@ -143,8 +143,8 @@ public partial class DispatcherTests
try
{
// Since both Invoke and InvokeAsync can throw exception, there is no need to pass them to the UnhandledException.
dispatcher.Invoke(ThrowAnException, DispatcherPriority.Normal);
dispatcher.RunJobs();
dispatcher.Invoke(ThrowAnException, DispatcherPriority.Normal, TestContext.Current.CancellationToken);
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception e)
{
@ -172,9 +172,9 @@ public partial class DispatcherTests
try
{
// Since both Invoke and InvokeAsync can throw exception, there is no need to pass them to the UnhandledException.
var op = dispatcher.InvokeAsync(ThrowAnException, DispatcherPriority.Normal);
var op = dispatcher.InvokeAsync(ThrowAnException, DispatcherPriority.Normal, TestContext.Current.CancellationToken);
op.Wait();
dispatcher.RunJobs();
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception e)
{
@ -202,7 +202,7 @@ public partial class DispatcherTests
try
{
dispatcher.Post(ThrowAnException, DispatcherPriority.Normal);
dispatcher.RunJobs();
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception e)
{
@ -233,7 +233,7 @@ public partial class DispatcherTests
try
{
dispatcher.Post(ThrowAnException, DispatcherPriority.Normal);
dispatcher.RunJobs();
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception e)
{
@ -263,7 +263,7 @@ public partial class DispatcherTests
try
{
dispatcher.Post(ThrowAnException, DispatcherPriority.Normal);
dispatcher.RunJobs();
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception)
{
@ -291,7 +291,7 @@ public partial class DispatcherTests
try
{
dispatcher.Post(ThrowAnException, DispatcherPriority.Normal);
dispatcher.RunJobs();
dispatcher.RunJobs(null, TestContext.Current.CancellationToken);
}
catch (Exception e)
{

14
tests/Avalonia.Base.UnitTests/DispatcherTests.cs

@ -137,8 +137,8 @@ public partial class DispatcherTests
var impl = new SimpleDispatcherImpl();
var disp = new Dispatcher(impl);
var actions = new List<string>();
var toPromote = disp.InvokeAsync(()=>actions.Add("PromotedRender"), DispatcherPriority.Background);
var toPromote2 = disp.InvokeAsync(()=>actions.Add("PromotedRender2"), DispatcherPriority.Input);
var toPromote = disp.InvokeAsync(()=>actions.Add("PromotedRender"), DispatcherPriority.Background, TestContext.Current.CancellationToken);
var toPromote2 = disp.InvokeAsync(()=>actions.Add("PromotedRender2"), DispatcherPriority.Input, TestContext.Current.CancellationToken);
disp.Post(() => actions.Add("Render"), DispatcherPriority.Render);
toPromote.Priority = DispatcherPriority.Render;
@ -444,7 +444,7 @@ public partial class DispatcherTests
}, DispatcherPriority.Background);
disp.MainLoop(CancellationToken.None);
disp.Invoke(DumpCurrentPriority, DispatcherPriority.Send);
disp.Invoke(DumpCurrentPriority, DispatcherPriority.Send, TestContext.Current.CancellationToken);
disp.Invoke(() =>
{
DumpCurrentPriority();
@ -500,7 +500,7 @@ public partial class DispatcherTests
{
var t = Test();
var cts = new CancellationTokenSource();
Task.Delay(3000).ContinueWith(_ => cts.Cancel());
Task.Delay(3000, TestContext.Current.CancellationToken).ContinueWith(_ => cts.Cancel(), TestContext.Current.CancellationToken);
Dispatcher.UIThread.MainLoop(cts.Token);
Assert.True(t.IsCompletedSuccessfully);
t.GetAwaiter().GetResult();
@ -657,7 +657,7 @@ public partial class DispatcherTests
tokenSource.Cancel();
});
});
}, TestContext.Current.CancellationToken);
Dispatcher.UIThread.MainLoop(tokenSource.Token);
await Task.WhenAll(task);
@ -699,7 +699,7 @@ public partial class DispatcherTests
{
tokenSource.Cancel();
});
});
}, TestContext.Current.CancellationToken);
Dispatcher.UIThread.MainLoop(tokenSource.Token);
await Task.WhenAll(task);
@ -753,7 +753,7 @@ public partial class DispatcherTests
await Task.WhenAll(task1);
tokenSource.Cancel();
});
});
}, TestContext.Current.CancellationToken);
try
{

2
tests/Avalonia.Base.UnitTests/Input/KeyboardNavigationTests_Tab.cs

@ -1311,7 +1311,7 @@ namespace Avalonia.Base.UnitTests.Input
top.ApplyTemplate();
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next) as Button;

2
tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs

@ -474,7 +474,7 @@ namespace Avalonia.Base.UnitTests.Layout
root.LayoutManager.InvalidateArrange(control);
root.LayoutManager.ExecuteInitialLayoutPass();
Dispatcher.UIThread.RunJobs(DispatcherPriority.Render);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Render, TestContext.Current.CancellationToken);
Assert.Equal(1, layoutCount);
}

1
tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiAlgorithmTests.cs

@ -1,7 +1,6 @@
using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Utilities;
using Xunit;
using Xunit.Abstractions;
namespace Avalonia.Visuals.UnitTests.Media.TextFormatting
{

1
tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTests.cs

@ -4,7 +4,6 @@ using System.Runtime.InteropServices;
using System.Text;
using Avalonia.Media.TextFormatting.Unicode;
using Xunit;
using Xunit.Abstractions;
namespace Avalonia.Visuals.UnitTests.Media.TextFormatting
{

1
tests/Avalonia.Base.UnitTests/Media/TextFormatting/GraphemeBreakClassTrieGeneratorTests.cs

@ -2,7 +2,6 @@
using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Visuals.UnitTests.Media.TextFormatting;
using Xunit;
using Xunit.Abstractions;
namespace Avalonia.Base.UnitTests.Media.TextFormatting
{

1
tests/Avalonia.Base.UnitTests/Media/TextFormatting/LineBreakEnumeratorTests.cs

@ -6,7 +6,6 @@ using System.Linq;
using System.Net.Http;
using Avalonia.Media.TextFormatting.Unicode;
using Xunit;
using Xunit.Abstractions;
using static Avalonia.Media.TextFormatting.Unicode.LineBreakEnumerator;
namespace Avalonia.Base.UnitTests.Media.TextFormatting

1
tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj

@ -3,6 +3,7 @@
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<XunitAutoGeneratedEntryPoint>false</XunitAutoGeneratedEntryPoint>
</PropertyGroup>
<Import Project="..\..\build\SharedVersion.props" />
<ItemGroup>

2
tests/Avalonia.Build.Tasks.UnitTest/Avalonia.Build.Tasks.UnitTest.csproj

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>$(AvsCurrentTargetFramework);net481</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>

2
tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />

4
tests/Avalonia.Controls.UnitTests/ButtonTests.cs

@ -103,7 +103,7 @@ namespace Avalonia.Controls.UnitTests
};
var root = new TestRoot { Child = target };
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.True(target.IsEnabled);
Assert.False(target.IsEffectivelyEnabled);
@ -341,7 +341,7 @@ namespace Avalonia.Controls.UnitTests
target.Presenter!.UpdateChild();
kd.SetFocusedElement(target, NavigationMethod.Unspecified, KeyModifiers.None);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
var accessKey = Key.A;
target.CommandParameter = true;

2
tests/Avalonia.Controls.UnitTests/CalendarDatePickerTests.cs

@ -33,7 +33,7 @@ namespace Avalonia.Controls.UnitTests
};
DateTime value = new DateTime(2000, 10, 10);
datePicker.SelectedDate = value;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(handled);
}
}

12
tests/Avalonia.Controls.UnitTests/DatePickerTests.cs

@ -30,7 +30,7 @@ namespace Avalonia.Controls.UnitTests
};
DateTimeOffset value = new DateTimeOffset(2000, 10, 10, 0, 0, 0, TimeSpan.Zero);
datePicker.SelectedDate = value;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(handled);
}
}
@ -46,7 +46,7 @@ namespace Avalonia.Controls.UnitTests
DayVisible = false
};
datePicker.ApplyTemplate();
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var desc = datePicker.GetVisualDescendants();
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
@ -81,7 +81,7 @@ namespace Avalonia.Controls.UnitTests
MonthVisible = false
};
datePicker.ApplyTemplate();
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var desc = datePicker.GetVisualDescendants();
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
@ -116,7 +116,7 @@ namespace Avalonia.Controls.UnitTests
YearVisible = false
};
datePicker.ApplyTemplate();
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var desc = datePicker.GetVisualDescendants();
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
@ -151,7 +151,7 @@ namespace Avalonia.Controls.UnitTests
YearVisible = false
};
datePicker.ApplyTemplate();
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var desc = datePicker.GetVisualDescendants();
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
@ -232,7 +232,7 @@ namespace Avalonia.Controls.UnitTests
Assert.True(DataValidationErrors.GetHasErrors(datePicker));
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
datePicker.SelectedDate = new DateTimeOffset(2005, 5, 10, 11, 12, 13, TimeSpan.Zero);
Assert.True(handled);
}

2
tests/Avalonia.Controls.UnitTests/GridLengthTests.cs

@ -118,7 +118,7 @@ namespace Avalonia.Controls.UnitTests
{
CultureInfo.CurrentCulture = culture;
Assert.Equal(result, length.ToString());
});
}, TestContext.Current.CancellationToken);
}
}
}

1
tests/Avalonia.Controls.UnitTests/GridTests.cs

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using Avalonia.UnitTests;
using Xunit;
using Xunit.Abstractions;
namespace Avalonia.Controls.UnitTests
{

10
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -435,7 +435,7 @@ namespace Avalonia.Controls.UnitTests
items.Remove("1");
lm.ExecuteLayoutPass();
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal("30", target.ContainerFromIndex(items.Count - 1)!.DataContext);
Assert.Equal("29", target.ContainerFromIndex(items.Count - 2)!.DataContext);
@ -462,12 +462,12 @@ namespace Avalonia.Controls.UnitTests
Prepare(target);
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
// First an item that is not index 0 must be selected.
_mouse.Click(target.Presenter!.Panel!.Children[1]);
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(1, target.Selection.AnchorIndex);
@ -489,7 +489,7 @@ namespace Avalonia.Controls.UnitTests
// Click item 9.
_mouse.Click(item);
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(1, raised);
}
@ -732,7 +732,7 @@ namespace Avalonia.Controls.UnitTests
items.Reverse();
Layout(target);
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
realized = target.GetRealizedContainers()
.Cast<ListBoxItem>()

6
tests/Avalonia.Controls.UnitTests/LoadedTests.cs

@ -25,7 +25,7 @@ public class LoadedTests : ScopedTestBase
Assert.Equal(0, unloadedCount);
target.Show();
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.True(target.IsLoaded);
Assert.Equal(1, loadedCount);
@ -59,7 +59,7 @@ public class LoadedTests : ScopedTestBase
Assert.Equal(0, unloadedCount);
window.Content = target;
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.True(target.IsLoaded);
Assert.Equal(1, loadedCount);
@ -98,7 +98,7 @@ public class LoadedTests : ScopedTestBase
// Attach to another logical parent (this can actually happen outside tests with overlay popups)
((ISetLogicalParent) target).SetParent(new Window());
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
// At this point, the control shouldn't have been loaded at all.
Assert.Null(target.VisualParent);

14
tests/Avalonia.Controls.UnitTests/MenuItemTests.cs

@ -139,7 +139,7 @@ namespace Avalonia.Controls.UnitTests
};
var root = new TestRoot { Child = target };
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.True(target.IsEnabled);
Assert.False(target.IsEffectivelyEnabled);
@ -213,7 +213,7 @@ namespace Avalonia.Controls.UnitTests
var target = new MenuItem { Command = command };
var root = new TestRoot { Child = target };
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
target.CommandParameter = true;
Assert.True(target.IsEffectivelyEnabled);
@ -239,7 +239,7 @@ namespace Avalonia.Controls.UnitTests
window.ApplyStyling();
window.ApplyTemplate();
window.Presenter!.ApplyTemplate();
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.True(target.IsEffectivelyEnabled);
target.Command = command;
@ -252,7 +252,7 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(0, canExecuteCallCount);
contextMenu.Open();
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.Equal(3, canExecuteCallCount);// 3 because popup is changing logical child and moreover we need to invalidate again after the item is attached to the visual tree
command.RaiseCanExecuteChanged();
@ -281,7 +281,7 @@ namespace Avalonia.Controls.UnitTests
window.ApplyStyling();
window.ApplyTemplate();
window.Presenter!.ApplyTemplate();
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.True(target.IsEffectivelyEnabled);
target.Command = command;
Assert.Equal(0, canExecuteCallCount);
@ -293,7 +293,7 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(0, canExecuteCallCount);
flyout.ShowAt(button);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.Equal(2, canExecuteCallCount); // 2 because we need to invalidate after the item is attached to the visual tree
command.RaiseCanExecuteChanged();
@ -324,7 +324,7 @@ namespace Avalonia.Controls.UnitTests
window.Presenter!.ApplyTemplate();
contextMenu.Open();
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded, TestContext.Current.CancellationToken);
Assert.True(target.IsEffectivelyEnabled);
target.Command = command;

16
tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs

@ -25,7 +25,7 @@ public class ScreensTests : ScopedTestBase
// Push 2 screens.
screens.PushNewScreens([1, 2]);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(2, screens.ScreenCount);
totalScreens.Add(Assert.IsType<TestScreen>(screens.GetScreen(1)));
@ -33,7 +33,7 @@ public class ScreensTests : ScopedTestBase
// Push 3 screens, while removing one old.
screens.PushNewScreens([2, 3, 4]);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(3, screens.ScreenCount);
Assert.Null(screens.GetScreen(1));
@ -64,7 +64,7 @@ public class ScreensTests : ScopedTestBase
Assert.Empty(screens.AllScreens);
screens.PushNewScreens([1]);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var screen = screens.GetScreen(1);
@ -73,7 +73,7 @@ public class ScreensTests : ScopedTestBase
Assert.Equal(new IntPtr(1), screen.TryGetPlatformHandle()!.Handle);
screens.PushNewScreens([1]);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(2, screen.Generation);
Assert.Equal(new IntPtr(1), screen.TryGetPlatformHandle()!.Handle);
@ -94,7 +94,7 @@ public class ScreensTests : ScopedTestBase
screens.PushNewScreens([1, 2]);
screens.PushNewScreens([1, 2]); // OnChanged can be triggered multiple times by different events
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(2, screens.ScreenCount);
Assert.NotEmpty(screens.AllScreens);
@ -118,7 +118,7 @@ public class ScreensTests : ScopedTestBase
};
ThreadRunHelper.RunOnDedicatedThread(() => screens.PushNewScreens([1, 2])).GetAwaiter().GetResult();
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(1, hasChangedTimes);
}
@ -131,7 +131,7 @@ public class ScreensTests : ScopedTestBase
var screens = new TestScreens();
screens.PushNewScreens([1, 2]);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var hasChangedTimes = 0;
var screen = screens.GetScreen(2);
@ -144,7 +144,7 @@ public class ScreensTests : ScopedTestBase
};
screens.PushNewScreens([1]);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(1, hasChangedTimes);
}

22
tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs

@ -814,7 +814,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var window = PreparedWindow(popup);
window.Show();
popup.Open();
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender, TestContext.Current.CancellationToken);
var raised = false;
if (popup.Host is PopupRoot popupRoot)
@ -837,7 +837,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
};
}
window.Position = new PixelPoint(10, 10);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender, TestContext.Current.CancellationToken);
Assert.False(raised);
}
}
@ -867,7 +867,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var window = PreparedWindow(placementTarget);
window.Show();
popup.Open();
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender, TestContext.Current.CancellationToken);
// The target's initial placement is (395,295) which is a 10x10 panel centered in a 800x600 window
Assert.Equal(placementTarget.Bounds, new Rect(395D, 295D, 10, 10));
@ -898,7 +898,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
};
}
window.PlatformImpl?.Resize(new Size(700D, 500D), WindowResizeReason.Unspecified);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender, TestContext.Current.CancellationToken);
Assert.True(raised);
}
}
@ -928,7 +928,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var window = PreparedWindow(placementTarget);
window.Show();
popup.Open();
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender, TestContext.Current.CancellationToken);
// The target's initial placement is (395,295) which is a 10x10 panel centered in a 800x600 window
Assert.Equal(placementTarget.Bounds, new Rect(395D, 295D, 10, 10));
@ -954,7 +954,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
};
}
window.PlatformImpl?.Resize(new Size(700D, 500D), WindowResizeReason.Unspecified);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender, TestContext.Current.CancellationToken);
Assert.False(raised);
}
}
@ -983,7 +983,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var window = PreparedWindow(placementTarget);
window.Show();
popup.Open();
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
// The target's initial placement is (395,295) which is a 10x10 panel centered in a 800x600 window
Assert.Equal(placementTarget.Bounds, new Rect(395D, 295D, 10, 10));
@ -1013,7 +1013,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
};
}
placementTarget.Margin = new Thickness(10, 0, 0, 0);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(raised);
}
}
@ -1043,7 +1043,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var window = PreparedWindow(placementTarget);
window.Show();
popup.Open();
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
// The target's initial placement is (395,295) which is a 10x10 panel centered in a 800x600 window
Assert.Equal(placementTarget.Bounds, new Rect(395D, 295D, 10, 10));
@ -1069,7 +1069,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
};
}
placementTarget.Margin = new Thickness(10, 0, 0, 0);
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.False(raised);
}
}
@ -1240,7 +1240,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
root.LayoutManager.ExecuteInitialLayoutPass();
popup.Open();
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender);
Dispatcher.UIThread.RunJobs(DispatcherPriority.AfterRender, TestContext.Current.CancellationToken);
// X: Adorned Canvas.Left + Adorner Margin Left + Adorner Width
// Y: Adorned Canvas.Top + Adorner Margin Top + Adorner Height

10
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -1649,7 +1649,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Prepare(target);
target.AddHandler(Control.RequestBringIntoViewEvent, (s, e) => raised = true);
target.SelectedIndex = 2;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(raised);
}
@ -1676,7 +1676,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
target.AddHandler(Control.RequestBringIntoViewEvent, (s, e) => raised = true);
target.SelectedIndex = 2;
Prepare(target);
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(raised);
}
@ -1750,7 +1750,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
root.Child = null;
target.SelectedIndex = 1;
root.Child = target;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(raised);
}
@ -1811,11 +1811,11 @@ namespace Avalonia.Controls.UnitTests.Primitives
var raised = false;
target.AddHandler(Control.RequestBringIntoViewEvent, (s, e) => raised = true);
target.SelectedIndex = 2;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.False(raised);
target.AutoScrollToSelectedItem = true;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(raised);
}

4
tests/Avalonia.Controls.UnitTests/TimePickerTests.cs

@ -30,7 +30,7 @@ namespace Avalonia.Controls.UnitTests
};
TimeSpan value = TimeSpan.FromHours(10);
timePicker.SelectedTime = value;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.True(handled);
}
}
@ -249,7 +249,7 @@ namespace Avalonia.Controls.UnitTests
Assert.True(DataValidationErrors.GetHasErrors(timePicker));
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
timePicker.SelectedTime = new TimeSpan(11, 12, 13);
Assert.True(handled);
}

1
tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs

@ -9,6 +9,7 @@ using Avalonia.Controls.Templates;
using Avalonia.Headless;
using Avalonia.Layout;
using Avalonia.Platform;
using Avalonia.Threading;
using Avalonia.UnitTests;
using Avalonia.VisualTree;
using Xunit;

8
tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs

@ -53,7 +53,7 @@ namespace Avalonia.Controls.UnitTests.Utils
}
[Theory]
[MemberData(nameof(ElementsFactory), parameters: true)]
[MemberData(nameof(ElementsFactory), arguments: true)]
public void HotKeyManager_Should_Use_CommandParameter(string factoryName, Factory factory)
{
using (AvaloniaLocator.EnterScope())
@ -98,7 +98,7 @@ namespace Avalonia.Controls.UnitTests.Utils
[Theory]
[MemberData(nameof(ElementsFactory), parameters: true)]
[MemberData(nameof(ElementsFactory), arguments: true)]
public void HotKeyManager_Should_Do_Not_Executed_When_IsEnabled_False(string factoryName, Factory factory)
{
using (AvaloniaLocator.EnterScope())
@ -141,7 +141,7 @@ namespace Avalonia.Controls.UnitTests.Utils
}
[Theory]
[MemberData(nameof(ElementsFactory), parameters:false)]
[MemberData(nameof(ElementsFactory), arguments:false)]
public void HotKeyManager_Should_Invoke_Event_Click_When_Command_Is_Null(string factoryName, Factory factory)
{
using (AvaloniaLocator.EnterScope())
@ -197,7 +197,7 @@ namespace Avalonia.Controls.UnitTests.Utils
}
[Theory]
[MemberData(nameof(ElementsFactory), parameters: true)]
[MemberData(nameof(ElementsFactory), arguments: true)]
public void HotKeyManager_Should_Not_Invoke_Event_Click_When_Command_Is_Not_Null(string factoryName, Factory factory)
{
using (AvaloniaLocator.EnterScope())

2
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -718,7 +718,7 @@ namespace Avalonia.Controls.UnitTests
target.Width = 120;
target.Height = 70;
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(1, child.MeasureSizes.Count);
Assert.Equal(new Size(120, 70), child.MeasureSizes[0]);

2
tests/Avalonia.DesignerSupport.Tests/Avalonia.DesignerSupport.Tests.csproj

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<WebAppDir>$(MSBuildThisFileDirectory)Remote/HtmlTransport/webapp</WebAppDir>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />

9
tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs

@ -13,21 +13,20 @@ using Avalonia.Remote.Protocol;
using Avalonia.Remote.Protocol.Designer;
using Avalonia.Remote.Protocol.Viewport;
using Xunit;
using Xunit.Extensions;
namespace Avalonia.DesignerSupport.Tests
{
public class DesignerSupportTests
{
private const string DesignerAppPath = "../../../../../src/tools/Avalonia.Designer.HostApp/bin/$BUILD/$TFM/Avalonia.Designer.HostApp.dll";
private readonly Xunit.Abstractions.ITestOutputHelper outputHelper;
private readonly ITestOutputHelper outputHelper;
public DesignerSupportTests(Xunit.Abstractions.ITestOutputHelper outputHelper)
public DesignerSupportTests(ITestOutputHelper outputHelper)
{
this.outputHelper = outputHelper;
}
[SkippableTheory,
[Theory,
InlineData(
@"..\..\..\..\..\tests/Avalonia.DesignerSupport.TestApp/bin/$BUILD/$TFM/",
"Avalonia.DesignerSupport.TestApp",
@ -63,7 +62,7 @@ namespace Avalonia.DesignerSupport.Tests
xamlFile = Path.GetFullPath(xamlFile.Replace('\\', Path.DirectorySeparatorChar));
if (method == "win32")
Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows-only");
var xaml = File.ReadAllText(xamlFile);
string buildType;

6
tests/Avalonia.DesignerSupport.Tests/RemoteProtocolTests.cs

@ -139,7 +139,7 @@ namespace Avalonia.DesignerSupport.Tests
foreach (var p in t.GetProperties())
p.SetValue(o, GetRandomValue(p.PropertyType, $"{t.FullName}.{p.Name}"));
_client.Send(o).Wait(TimeoutInMs);
_client.Send(o).Wait(TimeoutInMs, TestContext.Current.CancellationToken);
var received = TakeServer();
Helpers.StructDiff(received, o);
@ -199,11 +199,11 @@ namespace Avalonia.DesignerSupport.Tests
{
exceptions.Add(ex);
}
});
}, TestContext.Current.CancellationToken);
tasks.Add(task);
}
Task.WaitAll(tasks.ToArray(), TimeoutInMs * messages.Length * 10);
Task.WaitAll(tasks.ToArray(), TimeoutInMs * messages.Length * 10, TestContext.Current.CancellationToken);
// Verify no exceptions occurred
Assert.Empty(exceptions);

2
tests/Avalonia.Generators.Tests/InitializeComponent/InitializeComponentTests.cs

@ -61,7 +61,7 @@ public class InitializeComponentTests
.Replace("\r", string.Empty)
.Replace("$GeneratorVersion", generatorVersion);
CSharpSyntaxTree.ParseText(code);
CSharpSyntaxTree.ParseText(code, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(expected, code);
}
}

2
tests/Avalonia.Generators.Tests/OnlyProperties/OnlyPropertiesTests.cs

@ -55,7 +55,7 @@ public class OnlyPropertiesTests
.Replace("\r", string.Empty)
.Replace("$GeneratorVersion", generatorVersion);
CSharpSyntaxTree.ParseText(code);
CSharpSyntaxTree.ParseText(code, cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(expected, code);
}
}

3
tests/Avalonia.Headless.NUnit.PerAssembly.UnitTests/Avalonia.Headless.NUnit.PerAssembly.UnitTests.csproj

@ -3,6 +3,8 @@
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<IsTestProject>true</IsTestProject>
<DefineConstants>$(DefineConstants);NUNIT</DefineConstants>
<EnableNUnitRunner>true</EnableNUnitRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />
@ -14,7 +16,6 @@
<ItemGroup>
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
</ItemGroup>
<ItemGroup>

3
tests/Avalonia.Headless.NUnit.PerTest.UnitTests/Avalonia.Headless.NUnit.PerTest.UnitTests.csproj

@ -3,6 +3,8 @@
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<IsTestProject>true</IsTestProject>
<DefineConstants>$(DefineConstants);NUNIT</DefineConstants>
<EnableNUnitRunner>true</EnableNUnitRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />
@ -14,7 +16,6 @@
<ItemGroup>
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
</ItemGroup>
<ItemGroup>

2
tests/Avalonia.Headless.XUnit.PerAssembly.UnitTests/Avalonia.Headless.XUnit.PerAssembly.UnitTests.csproj

@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<IsTestProject>true</IsTestProject>
<DefineConstants>$(DefineConstants);XUNIT</DefineConstants>
<IsXUnit2>true</IsXUnit2>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />

2
tests/Avalonia.Headless.XUnit.PerTest.UnitTests/Avalonia.Headless.XUnit.PerTest.UnitTests.csproj

@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<IsTestProject>true</IsTestProject>
<DefineConstants>$(DefineConstants);XUNIT</DefineConstants>
<IsXUnit2>true</IsXUnit2>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />

8
tests/Avalonia.IntegrationTests.Appium/Avalonia.IntegrationTests.Appium.csproj

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<IsRunningAppium2 Condition="'$(IsRunningAppium2)' == ''">false</IsRunningAppium2>
@ -29,6 +30,13 @@
<PackageReference Include="Appium.WebDriver" Version="5.2.0"/>
</ItemGroup>
<ItemGroup>
<!-- This test project is run in CI via VSTest Azure Task, to have video recorder support -->
<!-- Video recorder isn't yet supported by Microsoft.Testing.Platform, we keep this project compatible with both VSTest and Microsoft.Testing.Platform. -->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>
<Import Project="..\..\build\XUnit.props" />
<Import Project="..\..\build\Rx.props" />
<Import Project="..\..\build\ImageSharp.props" />

30
tests/Avalonia.IntegrationTests.Appium/PlatformFactAttribute.cs

@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
@ -16,31 +17,22 @@ namespace Avalonia
internal class PlatformFactAttribute : FactAttribute
{
private readonly string? _reason;
private string? _skip;
public PlatformFactAttribute(TestPlatforms platforms, string? reason = null)
public PlatformFactAttribute(
TestPlatforms platforms,
string? reason = null,
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1)
: base(sourceFilePath, sourceLineNumber)
{
_reason = reason;
Platforms = platforms;
if (!IsSupported())
Skip = $"Ignored on {RuntimeInformation.OSDescription}" +
(reason is not null ? $" reason: '{reason}'" : "");
}
public TestPlatforms Platforms { get; }
public override string? Skip
{
get
{
if (_skip is not null)
return _skip;
if (!IsSupported())
return $"Ignored on {RuntimeInformation.OSDescription}" +
(_reason is not null ? $" reason: '{_reason}'" : "");
return null;
}
set => _skip = value;
}
private bool IsSupported()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

22
tests/Avalonia.IntegrationTests.Appium/PlatformTheoryAttribute.cs

@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
@ -7,23 +8,20 @@ namespace Avalonia.IntegrationTests.Appium
{
internal class PlatformTheoryAttribute : TheoryAttribute
{
private string? _skip;
public PlatformTheoryAttribute(TestPlatforms platforms = TestPlatforms.All) => Platforms = platforms;
public TestPlatforms Platforms { get; }
public override string? Skip
public PlatformTheoryAttribute(
TestPlatforms platforms = TestPlatforms.All,
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
{
get
Platforms = platforms;
if (!IsSupported())
{
if (_skip is not null)
return _skip;
return !IsSupported() ? $"Ignored on {RuntimeInformation.OSDescription}" : null;
Skip = $"Ignored on {RuntimeInformation.OSDescription}";
}
set => _skip = value;
}
public TestPlatforms Platforms { get; }
private bool IsSupported()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

3
tests/Avalonia.IntegrationTests.Win32/Avalonia.IntegrationTests.Win32.csproj

@ -14,8 +14,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="xunit.v3" Version="3.2.1" />
<PackageReference Include="xunit.v3.extensibility.core" Version="3.2.1" />
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.1" />
</ItemGroup>
<Import Project="../../build/SharedVersion.props" />

1
tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<Import Project="..\..\build\Moq.props" />
<Import Project="..\..\build\XUnit.props" />

8
tests/Avalonia.LeakTests/ReleaseFact.cs

@ -1,4 +1,5 @@
using Xunit;
using System.Runtime.CompilerServices;
using Xunit;
namespace Avalonia.LeakTests;
@ -7,7 +8,10 @@ namespace Avalonia.LeakTests;
/// </summary>
internal sealed class ReleaseFactAttribute : FactAttribute
{
public ReleaseFactAttribute()
public ReleaseFactAttribute(
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1
) : base(sourceFilePath, sourceLineNumber)
{
#if DEBUG
Skip = "Only runs in Release mode";

2
tests/Avalonia.Markup.UnitTests/Avalonia.Markup.UnitTests.csproj

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />

2
tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs

@ -551,7 +551,7 @@ namespace Avalonia.Markup.UnitTests.Data
}
// Forces WeakEvent compact
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(0, source.SubscriberCount);
}

8
tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_Indexer.cs

@ -167,7 +167,7 @@ namespace Avalonia.Markup.UnitTests.Parsers
}
// Forces WeakEvent compact
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(new[] { AvaloniaProperty.UnsetValue, "baz" }, result);
Assert.Null(((INotifyCollectionChangedDebug)data.Foo).GetCollectionChangedSubscribers());
@ -188,7 +188,7 @@ namespace Avalonia.Markup.UnitTests.Parsers
}
// Forces WeakEvent compact
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(new[] { "foo", "bar" }, result);
Assert.Null(((INotifyCollectionChangedDebug)data.Foo).GetCollectionChangedSubscribers());
@ -209,7 +209,7 @@ namespace Avalonia.Markup.UnitTests.Parsers
}
// Forces WeakEvent compact
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(new[] { "bar", "baz" }, result);
Assert.Null(((INotifyCollectionChangedDebug)data.Foo).GetCollectionChangedSubscribers());
@ -268,7 +268,7 @@ namespace Avalonia.Markup.UnitTests.Parsers
}
// Forces WeakEvent compact
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var expected = new[] { "bar", "bar2" };
Assert.Equal(expected, result);

12
tests/Avalonia.Markup.Xaml.UnitTests/Avalonia.Markup.Xaml.UnitTests.csproj

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>$(AvsCurrentTargetFramework)</TargetFrameworks>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />
@ -38,15 +38,5 @@
</Compile>
<Compile Include="../Shared/ScopedSanityCheck.cs"/>
</ItemGroup>
<ItemGroup>
<PackageReference Update="xunit.runner.console" Version="2.9.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<Import Project="..\..\build\BuildTargets.targets" />
</Project>

2
tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Method.cs

@ -135,7 +135,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Data
Assert.Equal(button.IsEffectivelyEnabled, false);
vm.Parameter = true;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(button.IsEffectivelyEnabled, true);
}

2
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs

@ -2012,7 +2012,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
Assert.Equal(button.IsEffectivelyEnabled, false);
vm.Parameter = true;
Threading.Dispatcher.UIThread.RunJobs();
Threading.Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
Assert.Equal(button.IsEffectivelyEnabled, true);
}

2
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs

@ -121,7 +121,7 @@ namespace Avalonia.Markup.Xaml.UnitTests
w.ApplyTemplate();
w.Show();
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
var itemsPresenter = ((ItemsControl)w.Content!).GetVisualChildren().FirstOrDefault();
Assert.NotNull(itemsPresenter);

3
tests/Avalonia.RenderTests.WpfCompare/Avalonia.RenderTests.WpfCompare.csproj

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(AvsCurrentWindowsTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<Nullable>enable</Nullable>
<UseWpf>true</UseWpf>
@ -15,7 +16,7 @@
<Content Include="../Avalonia.RenderTests/**/*.png" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xunit.StaFact" Version="1.2.69" />
<PackageReference Include="Xunit.StaFact" Version="3.0.13" />
</ItemGroup>
<Import Project="..\..\build\Moq.props" />
<Import Project="..\..\build\Rx.props" />

13
tests/Avalonia.RenderTests.WpfCompare/CrossFact.cs

@ -1,13 +1,20 @@
using Xunit;
using System.Runtime.CompilerServices;
using Xunit;
namespace Avalonia.RenderTests.WpfCompare;
public class CrossFactAttribute : StaFactAttribute
{
public CrossFactAttribute([CallerFilePath] string? sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = -1)
: base(sourceFilePath, sourceLineNumber)
{
}
}
public class CrossTheoryAttribute : StaTheoryAttribute
{
public CrossTheoryAttribute([CallerFilePath] string? sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = -1)
: base(sourceFilePath, sourceLineNumber)
{
}
}

4
tests/Avalonia.RenderTests/Composition/DirectFbCompositionTests.cs

@ -100,7 +100,7 @@ public class DirectFbCompositionTests : TestBase
control.Measure(new Size(control.Width, control.Height));
control.Arrange(new Rect(control.DesiredSize));
renderer.Start();
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
timer.TriggerTick();
var image1 =
$"{nameof(Should_Only_Update_Clipped_Rects_When_Retained_Fb_Is_Advertised)}_advertized-{advertised}_initial";
@ -112,7 +112,7 @@ public class DirectFbCompositionTests : TestBase
r1.Fill = Brushes.Red;
r2.Fill = Brushes.Green;
Dispatcher.UIThread.RunJobs();
Dispatcher.UIThread.RunJobs(null, TestContext.Current.CancellationToken);
timer.TriggerTick();
var image2 =
$"{nameof(Should_Only_Update_Clipped_Rects_When_Retained_Fb_Is_Advertised)}_advertized-{advertised}_updated";

13
tests/Avalonia.RenderTests/TestSkip.cs

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
@ -7,7 +8,11 @@ namespace Avalonia.Skia.RenderTests
{
public class Win32Fact : FactAttribute
{
public Win32Fact(string message)
public Win32Fact(
string message,
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1)
: base(sourceFilePath, sourceLineNumber)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Skip = message;
@ -16,7 +21,11 @@ namespace Avalonia.Skia.RenderTests
public class Win32Theory : TheoryAttribute
{
public Win32Theory(string message)
public Win32Theory(
string message,
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1)
: base(sourceFilePath, sourceLineNumber)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Skip = message;

1
tests/Avalonia.Skia.RenderTests/Avalonia.Skia.RenderTests.csproj

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<DefineConstants>$(DefineConstants);AVALONIA_SKIA</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeLinuxSkia>true</IncludeLinuxSkia>

14
tests/Avalonia.Skia.RenderTests/CrossTestBase.cs

@ -14,12 +14,22 @@ namespace Avalonia.Skia.RenderTests;
class CrossFactAttribute : FactAttribute
{
public CrossFactAttribute(
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1
) : base(sourceFilePath, sourceLineNumber)
{
}
}
class CrossTheoryAttribute : TheoryAttribute
{
public CrossTheoryAttribute(
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1
) : base(sourceFilePath, sourceLineNumber)
{
}
}
public class CrossTestBase : IDisposable

1
tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<Import Project="..\..\build\UnitTests.NetCore.targets" />
<Import Project="..\..\build\Moq.props" />

9
tests/Avalonia.Skia.UnitTests/Win32Fact.cs

@ -1,11 +1,16 @@
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
namespace Avalonia.Skia.UnitTests
{
internal class Win32Fact : FactAttribute
{
public Win32Fact(string message)
public Win32Fact(
string message,
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1)
: base(sourceFilePath, sourceLineNumber)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Skip = message;

8
tests/Avalonia.Skia.UnitTests/Win32Theory.cs

@ -1,11 +1,15 @@
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
namespace Avalonia.Skia.UnitTests
{
internal class Win32Theory: TheoryAttribute
{
public Win32Theory(string message)
public Win32Theory(
string message,
[CallerFilePath] string? sourceFilePath = null,
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Skip = message;

2
tests/Avalonia.UnitTests/Avalonia.UnitTests.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

10
tests/Avalonia.UnitTests/InvariantCultureAttribute.cs

@ -3,7 +3,7 @@
using System;
using System.Globalization;
using System.Reflection;
using Xunit.Sdk;
using Xunit.v3;
namespace Avalonia.UnitTests;
@ -21,9 +21,9 @@ public sealed class InvariantCultureAttribute : BeforeAfterTestAttribute
private CultureInfo? _previousCulture;
private CultureInfo? _previousUICulture;
public override void Before(MethodInfo methodUnderTest)
public override void Before(MethodInfo methodUnderTest, IXunitTest test)
{
base.Before(methodUnderTest);
base.Before(methodUnderTest, test);
_previousCulture = CultureInfo.CurrentCulture;
_previousUICulture = CultureInfo.CurrentUICulture;
@ -32,11 +32,11 @@ public sealed class InvariantCultureAttribute : BeforeAfterTestAttribute
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
}
public override void After(MethodInfo methodUnderTest)
public override void After(MethodInfo methodUnderTest, IXunitTest test)
{
CultureInfo.CurrentCulture = _previousCulture!;
CultureInfo.CurrentUICulture = _previousUICulture!;
base.After(methodUnderTest);
base.After(methodUnderTest, test);
}
}

9
tests/Avalonia.UnitTests/UnitTestApplication.cs

@ -62,6 +62,15 @@ namespace Avalonia.UnitTests
public override void RegisterServices()
{
// Arrange (as part of layouting) calls TaskScheduler.FromCurrentSynchronizationContext, which needs a non-null context.
// If it's null, it will fail. So we need to ensure it's not null.
// Historically, this line wasn't needed because xunit itself used to always install its own SynchronizationContext.
// This was changed in xunit.v3.
if (SynchronizationContext.Current is null)
{
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
}
AvaloniaLocator.CurrentMutable
.Bind<IAssetLoader?>().ToConstant(Services.AssetLoader)
.Bind<IGlobalClock?>().ToConstant(Services.GlobalClock)

10
tests/Avalonia.UnitTests/UseEmptyDesignatorCultureAttribute.cs

@ -3,7 +3,7 @@
using System;
using System.Globalization;
using System.Reflection;
using Xunit.Sdk;
using Xunit.v3;
namespace Avalonia.UnitTests;
@ -16,9 +16,9 @@ public sealed class UseEmptyDesignatorCultureAttribute : BeforeAfterTestAttribut
private CultureInfo CultureInfo { get; } =
new(string.Empty, false) { DateTimeFormat = { AMDesignator = string.Empty, PMDesignator = string.Empty } };
public override void Before(MethodInfo methodUnderTest)
public override void Before(MethodInfo methodUnderTest, IXunitTest test)
{
base.Before(methodUnderTest);
base.Before(methodUnderTest, test);
_previousCulture = CultureInfo.CurrentCulture;
_previousUICulture = CultureInfo.CurrentUICulture;
@ -27,11 +27,11 @@ public sealed class UseEmptyDesignatorCultureAttribute : BeforeAfterTestAttribut
CultureInfo.CurrentUICulture = CultureInfo;
}
public override void After(MethodInfo methodUnderTest)
public override void After(MethodInfo methodUnderTest, IXunitTest test)
{
CultureInfo.CurrentCulture = _previousCulture!;
CultureInfo.CurrentUICulture = _previousUICulture!;
base.After(methodUnderTest);
base.After(methodUnderTest, test);
}
}

4
tests/Avalonia.UnitTests/VerifyEmptyDispatcherAfterTestAttribute.cs

@ -4,13 +4,13 @@ using System.Reflection;
using Avalonia.Controls;
using Avalonia.Threading;
using Xunit;
using Xunit.Sdk;
using Xunit.v3;
namespace Avalonia.UnitTests;
public sealed class VerifyEmptyDispatcherAfterTestAttribute : BeforeAfterTestAttribute
{
public override void After(MethodInfo methodUnderTest)
public override void After(MethodInfo methodUnderTest, IXunitTest test)
{
if (typeof(ScopedTestBase).IsAssignableFrom(methodUnderTest.DeclaringType))
return;

5
tests/Directory.Build.props

@ -3,5 +3,10 @@
<PropertyGroup>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="2.0.2" />
</ItemGroup>
</Project>

Loading…
Cancel
Save