From 884423d879140fe30b36795c1cd3e91034184684 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 10 Oct 2017 21:43:01 +0300 Subject: [PATCH] Adapt threading tests to VerifyAccess on AvaloniaObject.ctor --- .../AvaloniaObjectTests_Threading.cs | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs index 229a34643d..215e872e8c 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Threading.cs @@ -14,13 +14,24 @@ namespace Avalonia.Base.UnitTests { public class AvaloniaObjectTests_Threading { + private ThreadingInterface _threading = new ThreadingInterface(true); + [Fact] - public void StyledProperty_GetValue_Should_Throw() + public void AvaloniaObject_Constructor_Should_Throw() { using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) { - var target = new Class1(); + Assert.Throws(() => new Class1()); + } + } + [Fact] + public void StyledProperty_GetValue_Should_Throw() + { + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) + { + var target = new Class1(); + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.GetValue(Class1.StyledProperty)); } } @@ -28,10 +39,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void StyledProperty_SetValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.SetValue(Class1.StyledProperty, "foo")); } } @@ -39,10 +50,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void Setting_StyledProperty_Binding_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.Bind( Class1.StyledProperty, @@ -53,10 +64,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void StyledProperty_ClearValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.ClearValue(Class1.StyledProperty)); } } @@ -64,10 +75,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void StyledProperty_IsSet_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.IsSet(Class1.StyledProperty)); } } @@ -75,10 +86,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_GetValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.GetValue(Class1.DirectProperty)); } } @@ -86,10 +97,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_SetValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.SetValue(Class1.DirectProperty, "foo")); } } @@ -97,10 +108,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void Setting_DirectProperty_Binding_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.Bind( Class1.DirectProperty, @@ -111,10 +122,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_ClearValue_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.ClearValue(Class1.DirectProperty)); } } @@ -122,10 +133,10 @@ namespace Avalonia.Base.UnitTests [Fact] public void DirectProperty_IsSet_Should_Throw() { - using (UnitTestApplication.Start(new TestServices(threadingInterface: new ThreadingInterface()))) + using (UnitTestApplication.Start(new TestServices(threadingInterface: _threading))) { var target = new Class1(); - + _threading.CurrentThreadIsLoopThread = false; Assert.Throws(() => target.IsSet(Class1.DirectProperty)); } } @@ -141,6 +152,7 @@ namespace Avalonia.Base.UnitTests private class ThreadingInterface : IPlatformThreadingInterface { + public ThreadingInterface(bool isLoopThread = false) { CurrentThreadIsLoopThread = isLoopThread;