From 0f4ed2a4b9fb82f9eff66fce66ef6ae9758fe594 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Mon, 20 Mar 2023 15:15:53 +0600 Subject: [PATCH] Updated tests to use IDispatcherImpl --- .../AvaloniaObjectTests_Binding.cs | 20 ++++----- .../AvaloniaObjectTests_Direct.cs | 6 +-- .../AvaloniaObjectTests_Threading.cs | 43 +++++++++---------- .../Input/MouseDeviceTests.cs | 7 +-- .../Input/TouchDeviceTests.cs | 3 +- .../Layout/ControlsBenchmark.cs | 2 +- .../NullThreadingPlatform.cs | 14 +++--- .../Styling/ControlTheme_Change.cs | 2 +- .../Styling/ResourceBenchmarks.cs | 2 +- .../Styling/Style_Apply_Detach_Complex.cs | 2 +- .../Text/HugeTextLayout.cs | 2 +- .../Themes/FluentBenchmark.cs | 2 +- .../DesktopStyleApplicationLifetimeTests.cs | 8 +++- .../Primitives/SelectingItemsControlTests.cs | 10 ++--- tests/Avalonia.RenderTests/TestBase.cs | 33 +++++--------- tests/Avalonia.UnitTests/TestServices.cs | 15 ++++--- .../Avalonia.UnitTests/UnitTestApplication.cs | 2 +- 17 files changed, 81 insertions(+), 92 deletions(-) diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs index 9f74d2fc08..e4080dd0a9 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs @@ -962,12 +962,12 @@ namespace Avalonia.Base.UnitTests var currentThreadId = Thread.CurrentThread.ManagedThreadId; var raised = 0; - var threadingInterfaceMock = new Mock(); - threadingInterfaceMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) + var dispatcherMock = new Mock(); + dispatcherMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) .Returns(() => Thread.CurrentThread.ManagedThreadId == currentThreadId); var services = new TestServices( - threadingInterface: threadingInterfaceMock.Object); + dispatcherImpl: dispatcherMock.Object); target.PropertyChanged += (s, e) => { @@ -1000,12 +1000,12 @@ namespace Avalonia.Base.UnitTests var currentThreadId = Thread.CurrentThread.ManagedThreadId; var raised = 0; - var threadingInterfaceMock = new Mock(); - threadingInterfaceMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) + var dispatcherMock = new Mock(); + dispatcherMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) .Returns(() => Thread.CurrentThread.ManagedThreadId == currentThreadId); var services = new TestServices( - threadingInterface: threadingInterfaceMock.Object); + dispatcherImpl: dispatcherMock.Object); target.PropertyChanged += (s, e) => { @@ -1038,12 +1038,12 @@ namespace Avalonia.Base.UnitTests var currentThreadId = Thread.CurrentThread.ManagedThreadId; var raised = 0; - var threadingInterfaceMock = new Mock(); + var threadingInterfaceMock = new Mock(); threadingInterfaceMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) .Returns(() => Thread.CurrentThread.ManagedThreadId == currentThreadId); var services = new TestServices( - threadingInterface: threadingInterfaceMock.Object); + dispatcherImpl: threadingInterfaceMock.Object); target.PropertyChanged += (s, e) => { @@ -1071,12 +1071,12 @@ namespace Avalonia.Base.UnitTests var source = new Subject(); var currentThreadId = Thread.CurrentThread.ManagedThreadId; - var threadingInterfaceMock = new Mock(); + var threadingInterfaceMock = new Mock(); threadingInterfaceMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) .Returns(() => Thread.CurrentThread.ManagedThreadId == currentThreadId); var services = new TestServices( - threadingInterface: threadingInterfaceMock.Object); + dispatcherImpl: threadingInterfaceMock.Object); using (UnitTestApplication.Start(services)) { diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs index 973090ee92..ad8c2751cd 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs @@ -530,12 +530,12 @@ namespace Avalonia.Base.UnitTests var currentThreadId = Thread.CurrentThread.ManagedThreadId; var raised = 0; - var threadingInterfaceMock = new Mock(); - threadingInterfaceMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) + var dispatcherMock = new Mock(); + dispatcherMock.SetupGet(mock => mock.CurrentThreadIsLoopThread) .Returns(() => Thread.CurrentThread.ManagedThreadId == currentThreadId); var services = new TestServices( - threadingInterface: threadingInterfaceMock.Object); + dispatcherImpl: dispatcherMock.Object); target.PropertyChanged += (s, e) => { diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs index 16d6b9166b..7f1251f73e 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs @@ -11,12 +11,12 @@ namespace Avalonia.Base.UnitTests { public class AvaloniaObjectTests_Threading { - private ThreadingInterface _threading = new ThreadingInterface(true); + private TestDipatcherImpl _threading = new(true); [Fact] public void AvaloniaObject_Constructor_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: new TestDipatcherImpl()))) { Assert.Throws(() => new Class1()); } @@ -25,7 +25,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void StyledProperty_GetValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -36,7 +36,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void StyledProperty_SetValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -47,7 +47,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void Setting_StyledProperty_Binding_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -61,7 +61,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void StyledProperty_ClearValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -72,7 +72,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void StyledProperty_IsSet_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -83,7 +83,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_GetValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -94,7 +94,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_SetValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -105,7 +105,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void Setting_DirectProperty_Binding_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -119,7 +119,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_ClearValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -130,7 +130,7 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_IsSet_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: _threading))) { var target = new Class1(); _threading.CurrentThreadIsLoopThread = false; @@ -147,10 +147,10 @@ namespace Avalonia.Base.UnitTests AvaloniaProperty.RegisterDirect("Qux", _ => null, (o, v) => { }); } - private class ThreadingInterface : IPlatformThreadingInterface + private class TestDipatcherImpl : IDispatcherImpl { - public ThreadingInterface(bool isLoopThread = false) + public TestDipatcherImpl(bool isLoopThread = false) { CurrentThreadIsLoopThread = isLoopThread; } @@ -158,18 +158,17 @@ namespace Avalonia.Base.UnitTests public bool CurrentThreadIsLoopThread { get; set; } #pragma warning disable 67 - public event Action Signaled; -#pragma warning restore 67 - - public void Signal(DispatcherPriority prio) + public event Action Signaled; + public event Action Timer; + public long Now => 0; + public void UpdateTimer(long? dueTimeInMs) { throw new NotImplementedException(); } + public void Signal() => throw new NotImplementedException(); +#pragma warning restore 67 - public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick) - { - throw new NotImplementedException(); - } + } } } diff --git a/tests/Avalonia.Base.UnitTests/Input/MouseDeviceTests.cs b/tests/Avalonia.Base.UnitTests/Input/MouseDeviceTests.cs index 1bb1b4af73..642e762c1b 100644 --- a/tests/Avalonia.Base.UnitTests/Input/MouseDeviceTests.cs +++ b/tests/Avalonia.Base.UnitTests/Input/MouseDeviceTests.cs @@ -3,6 +3,7 @@ using Avalonia.Input; using Avalonia.Input.Raw; using Avalonia.Media; using Avalonia.Platform; +using Avalonia.Threading; using Avalonia.UnitTests; using Moq; using Xunit; @@ -16,9 +17,9 @@ namespace Avalonia.Base.UnitTests.Input { using var scope = AvaloniaLocator.EnterScope(); var settingsMock = new Mock(); - var threadingMock = new Mock(); + var dispatcherMock = new Mock(); - threadingMock.Setup(x => x.CurrentThreadIsLoopThread).Returns(true); + dispatcherMock.Setup(x => x.CurrentThreadIsLoopThread).Returns(true); AvaloniaLocator.CurrentMutable.BindToSelf(this) .Bind().ToConstant(settingsMock.Object); @@ -26,7 +27,7 @@ namespace Avalonia.Base.UnitTests.Input using var app = UnitTestApplication.Start( new TestServices( inputManager: new InputManager(), - threadingInterface: threadingMock.Object)); + dispatcherImpl: dispatcherMock.Object)); var renderer = RendererMocks.CreateRenderer(); var device = new MouseDevice(); diff --git a/tests/Avalonia.Base.UnitTests/Input/TouchDeviceTests.cs b/tests/Avalonia.Base.UnitTests/Input/TouchDeviceTests.cs index 36587ea222..0653d49191 100644 --- a/tests/Avalonia.Base.UnitTests/Input/TouchDeviceTests.cs +++ b/tests/Avalonia.Base.UnitTests/Input/TouchDeviceTests.cs @@ -1,6 +1,7 @@ using System; using Avalonia.Input.Raw; using Avalonia.Platform; +using Avalonia.Threading; using Avalonia.UnitTests; using Moq; using Xunit; @@ -207,7 +208,7 @@ namespace Avalonia.Input.UnitTests private IDisposable UnitTestApp(TimeSpan doubleClickTime = new TimeSpan()) { var unitTestApp = UnitTestApplication.Start( - new TestServices(inputManager: new InputManager(), threadingInterface: Mock.Of(x => x.CurrentThreadIsLoopThread == true))); + new TestServices(inputManager: new InputManager(), dispatcherImpl: Mock.Of(x => x.CurrentThreadIsLoopThread == true))); var iSettingsMock = new Mock(); iSettingsMock.Setup(x => x.GetDoubleTapTime(It.IsAny())).Returns(doubleClickTime); iSettingsMock.Setup(x => x.GetDoubleTapSize(It.IsAny())).Returns(new Size(16, 16)); diff --git a/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs b/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs index eacf73ac94..5df1dd1679 100644 --- a/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs +++ b/tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs @@ -18,7 +18,7 @@ namespace Avalonia.Benchmarks.Layout _app = UnitTestApplication.Start( TestServices.StyledWindow.With( renderInterface: new NullRenderingPlatform(), - threadingInterface: new NullThreadingPlatform(), + dispatcherImpl: new NullThreadingPlatform(), standardCursorFactory: new NullCursorFactory())); _root = new TestRoot(true, null) diff --git a/tests/Avalonia.Benchmarks/NullThreadingPlatform.cs b/tests/Avalonia.Benchmarks/NullThreadingPlatform.cs index 6acc9e3483..1b5b60031c 100644 --- a/tests/Avalonia.Benchmarks/NullThreadingPlatform.cs +++ b/tests/Avalonia.Benchmarks/NullThreadingPlatform.cs @@ -6,22 +6,22 @@ using Avalonia.Threading; namespace Avalonia.Benchmarks { - internal class NullThreadingPlatform : IPlatformThreadingInterface + internal class NullThreadingPlatform : IDispatcherImpl { - public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick) + public void Signal() { - return Disposable.Empty; } - - public void Signal(DispatcherPriority priority) + + public void UpdateTimer(long? dueTimeInMs) { } public bool CurrentThreadIsLoopThread => true; #pragma warning disable CS0067 - public event Action Signaled; + public event Action Signaled; + public event Action Timer; + public long Now => 0; #pragma warning restore CS0067 - } } diff --git a/tests/Avalonia.Benchmarks/Styling/ControlTheme_Change.cs b/tests/Avalonia.Benchmarks/Styling/ControlTheme_Change.cs index 627edfdeb6..00080e3b82 100644 --- a/tests/Avalonia.Benchmarks/Styling/ControlTheme_Change.cs +++ b/tests/Avalonia.Benchmarks/Styling/ControlTheme_Change.cs @@ -23,7 +23,7 @@ namespace Avalonia.Benchmarks.Styling _app = UnitTestApplication.Start( TestServices.StyledWindow.With( renderInterface: new NullRenderingPlatform(), - threadingInterface: new NullThreadingPlatform())); + dispatcherImpl: new NullThreadingPlatform())); // Simulate an application with a lot of styles by creating a tree of nested panels, // each with a bunch of styles applied. diff --git a/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs b/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs index bc47e68bc1..b044bcde59 100644 --- a/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs +++ b/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs @@ -23,7 +23,7 @@ namespace Avalonia.Benchmarks.Styling renderInterface: new MockPlatformRenderInterface(), standardCursorFactory: Mock.Of(), theme: () => CreateTheme(), - threadingInterface: new NullThreadingPlatform(), + dispatcherImpl: new NullThreadingPlatform(), fontManagerImpl: new MockFontManagerImpl(), textShaperImpl: new MockTextShaperImpl(), windowingPlatform: new MockWindowingPlatform()); diff --git a/tests/Avalonia.Benchmarks/Styling/Style_Apply_Detach_Complex.cs b/tests/Avalonia.Benchmarks/Styling/Style_Apply_Detach_Complex.cs index a6be6c0c18..307f15a6c0 100644 --- a/tests/Avalonia.Benchmarks/Styling/Style_Apply_Detach_Complex.cs +++ b/tests/Avalonia.Benchmarks/Styling/Style_Apply_Detach_Complex.cs @@ -20,7 +20,7 @@ namespace Avalonia.Benchmarks.Styling _app = UnitTestApplication.Start( TestServices.StyledWindow.With( renderInterface: new NullRenderingPlatform(), - threadingInterface: new NullThreadingPlatform())); + dispatcherImpl: new NullThreadingPlatform())); // Simulate an application with a lot of styles by creating a tree of nested panels, // each with a bunch of styles applied. diff --git a/tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs b/tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs index 03b85840a7..22ca9d8c6d 100644 --- a/tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs +++ b/tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs @@ -32,7 +32,7 @@ public class HugeTextLayout : IDisposable var testServices = TestServices.StyledWindow.With( renderInterface: new NullRenderingPlatform(), - threadingInterface: new NullThreadingPlatform(), + dispatcherImpl: new NullThreadingPlatform(), standardCursorFactory: new NullCursorFactory()); if (s_useSkia) diff --git a/tests/Avalonia.Benchmarks/Themes/FluentBenchmark.cs b/tests/Avalonia.Benchmarks/Themes/FluentBenchmark.cs index 1115bc9760..e9b82d5381 100644 --- a/tests/Avalonia.Benchmarks/Themes/FluentBenchmark.cs +++ b/tests/Avalonia.Benchmarks/Themes/FluentBenchmark.cs @@ -47,7 +47,7 @@ namespace Avalonia.Benchmarks.Themes renderInterface: new MockPlatformRenderInterface(), standardCursorFactory: Mock.Of(), theme: () => LoadFluentTheme(), - threadingInterface: new NullThreadingPlatform(), + dispatcherImpl: new NullThreadingPlatform(), fontManagerImpl: new MockFontManagerImpl(), textShaperImpl: new MockTextShaperImpl(), windowingPlatform: new MockWindowingPlatform()); diff --git a/tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs b/tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs index 8cd5816984..90a0db691c 100644 --- a/tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs +++ b/tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Platform; using Avalonia.Rendering; +using Avalonia.Threading; using Avalonia.UnitTests; using Moq; using Xunit; @@ -12,10 +13,13 @@ namespace Avalonia.Controls.UnitTests public class DesktopStyleApplicationLifetimeTests { + IDispatcherImpl CreateDispatcherWithInstantMainLoop() => Mock.Of(x => x.CurrentThreadIsLoopThread == true); + + [Fact] public void Should_Set_ExitCode_After_Shutdown() { - using (UnitTestApplication.Start(TestServices.MockThreadingInterface)) + using (UnitTestApplication.Start(new TestServices(dispatcherImpl: CreateDispatcherWithInstantMainLoop()))) using(var lifetime = new ClassicDesktopStyleApplicationLifetime()) { lifetime.Shutdown(1337); @@ -215,7 +219,7 @@ namespace Avalonia.Controls.UnitTests [Fact] public void Should_Allow_Canceling_Shutdown_Via_ShutdownRequested_Event() { - using (UnitTestApplication.Start(TestServices.StyledWindow)) + using (UnitTestApplication.Start(TestServices.StyledWindow.With(dispatcherImpl: CreateDispatcherWithInstantMainLoop()))) using (var lifetime = new ClassicDesktopStyleApplicationLifetime()) { var lifetimeEvents = new Mock(); diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs index 3fa2bb515d..9574598038 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs @@ -2084,13 +2084,9 @@ namespace Avalonia.Controls.UnitTests.Primitives [Fact] public void Setting_IsTextSearchEnabled_Enables_Or_Disables_Text_Search() { - var pti = Mock.Of(x => x.CurrentThreadIsLoopThread == true); - - Mock.Get(pti) - .Setup(v => v.StartTimer(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(Disposable.Empty); - - using (UnitTestApplication.Start(TestServices.StyledWindow.With(threadingInterface: pti))) + var pti = Mock.Of(x => x.CurrentThreadIsLoopThread == true); + + using (UnitTestApplication.Start(TestServices.StyledWindow.With(dispatcherImpl: pti))) { var items = new[] { diff --git a/tests/Avalonia.RenderTests/TestBase.cs b/tests/Avalonia.RenderTests/TestBase.cs index b6aba5e04c..a0d8f8bcc3 100644 --- a/tests/Avalonia.RenderTests/TestBase.cs +++ b/tests/Avalonia.RenderTests/TestBase.cs @@ -41,8 +41,8 @@ namespace Avalonia.Direct2D1.RenderTests #endif public static FontFamily TestFontFamily = new FontFamily(s_fontUri); - private static readonly TestThreadingInterface threadingInterface = - new TestThreadingInterface(); + private static readonly TestDispatcherImpl threadingInterface = + new TestDispatcherImpl(); private static readonly IAssetLoader assetLoader = new AssetLoader(); @@ -54,7 +54,7 @@ namespace Avalonia.Direct2D1.RenderTests Direct2D1Platform.Initialize(); #endif AvaloniaLocator.CurrentMutable - .Bind() + .Bind() .ToConstant(threadingInterface); AvaloniaLocator.CurrentMutable @@ -243,40 +243,27 @@ namespace Avalonia.Direct2D1.RenderTests return path; } - private class TestThreadingInterface : IPlatformThreadingInterface + private class TestDispatcherImpl : IDispatcherImpl { public bool CurrentThreadIsLoopThread => MainThread.ManagedThreadId == Thread.CurrentThread.ManagedThreadId; public Thread MainThread { get; set; } #pragma warning disable 67 - public event Action Signaled; + public event Action Signaled; + public event Action Timer; #pragma warning restore 67 - public void Signal(DispatcherPriority prio) + public void Signal() { // No-op } - private static List s_timers = new(); - - public static void RunTimers() - { - lock (s_timers) - { - foreach(var t in s_timers.ToList()) - t.Invoke(); - } - } + public long Now => 0; - public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick) + public void UpdateTimer(long? dueTimeInMs) { - var act = () => tick(); - lock (s_timers) s_timers.Add(act); - return Disposable.Create(() => - { - lock (s_timers) s_timers.Remove(act); - }); + // No-op } } diff --git a/tests/Avalonia.UnitTests/TestServices.cs b/tests/Avalonia.UnitTests/TestServices.cs index 339cb1462c..800abbc2c7 100644 --- a/tests/Avalonia.UnitTests/TestServices.cs +++ b/tests/Avalonia.UnitTests/TestServices.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using Avalonia.Controls; using System.Reflection; using Avalonia.Animation; +using Avalonia.Threading; namespace Avalonia.UnitTests { @@ -24,7 +25,7 @@ namespace Avalonia.UnitTests renderInterface: new MockPlatformRenderInterface(), standardCursorFactory: Mock.Of(), theme: () => CreateSimpleTheme(), - threadingInterface: Mock.Of(x => x.CurrentThreadIsLoopThread == true), + dispatcherImpl: Mock.Of(x => x.CurrentThreadIsLoopThread == true), fontManagerImpl: new MockFontManagerImpl(), textShaperImpl: new MockTextShaperImpl(), windowingPlatform: new MockWindowingPlatform()); @@ -39,7 +40,7 @@ namespace Avalonia.UnitTests platform: Mock.Of()); public static readonly TestServices MockThreadingInterface = new TestServices( - threadingInterface: Mock.Of(x => x.CurrentThreadIsLoopThread == true)); + dispatcherImpl: Mock.Of(x => x.CurrentThreadIsLoopThread == true)); public static readonly TestServices MockWindowingPlatform = new TestServices( windowingPlatform: new MockWindowingPlatform()); @@ -73,7 +74,7 @@ namespace Avalonia.UnitTests IRenderTimer renderLoop = null, ICursorFactory standardCursorFactory = null, Func theme = null, - IPlatformThreadingInterface threadingInterface = null, + IDispatcherImpl dispatcherImpl = null, IFontManagerImpl fontManagerImpl = null, ITextShaperImpl textShaperImpl = null, IWindowImpl windowImpl = null, @@ -92,7 +93,7 @@ namespace Avalonia.UnitTests TextShaperImpl = textShaperImpl; StandardCursorFactory = standardCursorFactory; Theme = theme; - ThreadingInterface = threadingInterface; + DispatcherImpl = dispatcherImpl; WindowImpl = windowImpl; WindowingPlatform = windowingPlatform; } @@ -110,7 +111,7 @@ namespace Avalonia.UnitTests public ITextShaperImpl TextShaperImpl { get; } public ICursorFactory StandardCursorFactory { get; } public Func Theme { get; } - public IPlatformThreadingInterface ThreadingInterface { get; } + public IDispatcherImpl DispatcherImpl { get; } public IWindowImpl WindowImpl { get; } public IWindowingPlatform WindowingPlatform { get; } @@ -128,7 +129,7 @@ namespace Avalonia.UnitTests IScheduler scheduler = null, ICursorFactory standardCursorFactory = null, Func theme = null, - IPlatformThreadingInterface threadingInterface = null, + IDispatcherImpl dispatcherImpl = null, IFontManagerImpl fontManagerImpl = null, ITextShaperImpl textShaperImpl = null, IWindowImpl windowImpl = null, @@ -148,7 +149,7 @@ namespace Avalonia.UnitTests textShaperImpl: textShaperImpl ?? TextShaperImpl, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, theme: theme ?? Theme, - threadingInterface: threadingInterface ?? ThreadingInterface, + dispatcherImpl: dispatcherImpl ?? DispatcherImpl, windowingPlatform: windowingPlatform ?? WindowingPlatform, windowImpl: windowImpl ?? WindowImpl); } diff --git a/tests/Avalonia.UnitTests/UnitTestApplication.cs b/tests/Avalonia.UnitTests/UnitTestApplication.cs index 3108e09315..8d9f08caa1 100644 --- a/tests/Avalonia.UnitTests/UnitTestApplication.cs +++ b/tests/Avalonia.UnitTests/UnitTestApplication.cs @@ -71,7 +71,7 @@ namespace Avalonia.UnitTests .Bind().ToConstant(Services.RenderInterface) .Bind().ToConstant(Services.FontManagerImpl) .Bind().ToConstant(Services.TextShaperImpl) - .Bind().ToConstant(Services.ThreadingInterface) + .Bind().ToConstant(Services.DispatcherImpl) .Bind().ToConstant(Services.StandardCursorFactory) .Bind().ToConstant(Services.WindowingPlatform) .Bind().ToSingleton();