From 24f11bba18d963757a1e8d7bb71ffb55de59ac70 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 16 Nov 2019 11:33:01 +0100 Subject: [PATCH] Simplify test controls in styling unit tests. Making a change to interfaces was becoming a pain because of this. --- .../SelectorTests_Child.cs | 85 +------------------ .../SelectorTests_Class.cs | 2 +- .../SelectorTests_Descendent.cs | 85 +------------------ .../SelectorTests_Name.cs | 3 +- .../SelectorTests_Not.cs | 4 +- .../SelectorTests_OfType.cs | 5 +- .../SelectorTests_Or.cs | 9 +- .../TestControlBase.cs | 83 ------------------ .../TestTemplatedControl.cs | 81 ------------------ 9 files changed, 21 insertions(+), 336 deletions(-) delete mode 100644 tests/Avalonia.Styling.UnitTests/TestControlBase.cs delete mode 100644 tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs index c6eeb1ec0e3..320dbfeec39 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs @@ -81,89 +81,12 @@ public void Child_Selector_Should_Have_Correct_String_Representation() Assert.Equal("TestLogical1 > TestLogical3", selector.ToString()); } - public abstract class TestLogical : ILogical, IStyleable + public abstract class TestLogical : Control { - public TestLogical() + public ILogical LogicalParent { - Classes = new Classes(); - } - - public event EventHandler PropertyChanged; - public event EventHandler InheritablePropertyChanged; - public event EventHandler AttachedToLogicalTree; - public event EventHandler DetachedFromLogicalTree; - - public Classes Classes { get; } - - public string Name { get; set; } - - public bool IsAttachedToLogicalTree { get; } - - public IAvaloniaReadOnlyList LogicalChildren { get; set; } - - public ILogical LogicalParent { get; set; } - - public Type StyleKey { get; } - - public ITemplatedControl TemplatedParent { get; } - - IObservable IStyleable.StyleDetach { get; } - - IAvaloniaReadOnlyList IStyleable.Classes => Classes; - - public object GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public T GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, object value, BindingPriority priority) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority) - { - throw new NotImplementedException(); - } - - public bool IsAnimating(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public bool IsSet(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public void NotifyAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) - { - throw new NotImplementedException(); - } - - public void NotifyDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) - { - throw new NotImplementedException(); - } - - public void NotifyResourcesChanged(ResourcesChangedEventArgs e) - { - throw new NotImplementedException(); + get => Parent; + set => ((ISetLogicalParent)this).SetParent(value); } } diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs index 496998ecd96..fd25b17ba46 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs @@ -144,7 +144,7 @@ public void Only_Notifies_When_Result_Changes() Assert.Equal(new[] { true, false }, result); } - public class Control1 : TestControlBase + public class Control1 : Control { } } diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs index aef539becd1..940b2b18ef5 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs @@ -111,89 +111,12 @@ public void Descendant_Selector_Should_Have_Correct_String_Representation() Assert.Equal("TestLogical1.foo TestLogical3", selector.ToString()); } - public abstract class TestLogical : ILogical, IStyleable + public abstract class TestLogical : Control { - public TestLogical() + public ILogical LogicalParent { - Classes = new Classes(); - } - - public event EventHandler PropertyChanged; - public event EventHandler InheritablePropertyChanged; - public event EventHandler AttachedToLogicalTree; - public event EventHandler DetachedFromLogicalTree; - - public Classes Classes { get; } - - public string Name { get; set; } - - public bool IsAttachedToLogicalTree { get; } - - public IAvaloniaReadOnlyList LogicalChildren { get; set; } - - public ILogical LogicalParent { get; set; } - - public Type StyleKey { get; } - - public ITemplatedControl TemplatedParent { get; } - - IAvaloniaReadOnlyList IStyleable.Classes => Classes; - - IObservable IStyleable.StyleDetach { get; } - - public object GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public T GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, object value, BindingPriority priority) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public bool IsAnimating(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public bool IsSet(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public void NotifyAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) - { - throw new NotImplementedException(); - } - - public void NotifyDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) - { - throw new NotImplementedException(); - } - - public void NotifyResourcesChanged(ResourcesChangedEventArgs e) - { - throw new NotImplementedException(); + get => Parent; + set => ((ISetLogicalParent)this).SetParent(value); } } diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs index 1c8a3a406e3..26734a494b8 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs @@ -1,6 +1,7 @@ // Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. +using Avalonia.Controls; using Moq; using Xunit; @@ -52,7 +53,7 @@ public void Type_And_Name_Has_Correct_String_Representation() Assert.Equal("Control1#foo", target.ToString()); } - public class Control1 : TestControlBase + public class Control1 : Control { } } diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs index 2f3e2b8f344..7c23cb4d2ce 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs @@ -103,11 +103,11 @@ public void Returns_Correct_TargetType() Assert.Equal(typeof(Control1), target.TargetType); } - public class Control1 : TestControlBase + public class Control1 : Control { } - public class Control2 : TestControlBase + public class Control2 : Control { } } diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs index 05f3544366e..a254c73c032 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs @@ -1,6 +1,7 @@ // Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. +using Avalonia.Controls; using Moq; using Xunit; @@ -44,11 +45,11 @@ public void OfType_Matches_Control_With_TemplatedParent() Assert.Equal(SelectorMatchResult.AlwaysThisType, target.Match(control).Result); } - public class Control1 : TestControlBase + public class Control1 : Control { } - public class Control2 : TestControlBase + public class Control2 : Control { } } diff --git a/tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs b/tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs index 521c73ce27b..e9bc93c957d 100644 --- a/tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs +++ b/tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs @@ -1,6 +1,7 @@ // Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. +using Avalonia.Controls; using Xunit; namespace Avalonia.Styling.UnitTests @@ -78,7 +79,7 @@ public void Returns_Common_TargetType() default(Selector).OfType().Class("foo"), default(Selector).OfType().Class("bar")); - Assert.Equal(typeof(TestControlBase), target.TargetType); + Assert.Equal(typeof(Control), target.TargetType); } [Fact] @@ -91,15 +92,15 @@ public void Returns_Null_TargetType_When_A_Selector_Has_No_TargetType() Assert.Equal(null, target.TargetType); } - public class Control1 : TestControlBase + public class Control1 : Control { } - public class Control2 : TestControlBase + public class Control2 : Control { } - public class Control3 : TestControlBase + public class Control3 : Control { } } diff --git a/tests/Avalonia.Styling.UnitTests/TestControlBase.cs b/tests/Avalonia.Styling.UnitTests/TestControlBase.cs deleted file mode 100644 index d9fabf6f5d1..00000000000 --- a/tests/Avalonia.Styling.UnitTests/TestControlBase.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) The Avalonia Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -using System; -using System.Reactive; -using Avalonia.Collections; -using Avalonia.Controls; -using Avalonia.Data; - -namespace Avalonia.Styling.UnitTests -{ - public class TestControlBase : IStyleable - { - public TestControlBase() - { - Classes = new Classes(); - SubscribeCheckObservable = new TestObservable(); - } - -#pragma warning disable CS0067 // Event not used - public event EventHandler PropertyChanged; - public event EventHandler InheritablePropertyChanged; -#pragma warning restore CS0067 - - public string Name { get; set; } - - public virtual Classes Classes { get; set; } - - public Type StyleKey => GetType(); - - public TestObservable SubscribeCheckObservable { get; private set; } - - public ITemplatedControl TemplatedParent - { - get; - set; - } - - IAvaloniaReadOnlyList IStyleable.Classes => Classes; - - IObservable IStyleable.StyleDetach { get; } - - public object GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public T GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, object value, BindingPriority priority) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public bool IsAnimating(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public bool IsSet(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - } -} diff --git a/tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs b/tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs deleted file mode 100644 index e92ac36e8f9..00000000000 --- a/tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) The Avalonia Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -using System; -using System.Reactive; -using Avalonia.Collections; -using Avalonia.Controls; -using Avalonia.Data; - -namespace Avalonia.Styling.UnitTests -{ - public abstract class TestTemplatedControl : ITemplatedControl, IStyleable - { - public event EventHandler PropertyChanged; - public event EventHandler InheritablePropertyChanged; - - public abstract Classes Classes - { - get; - } - - public abstract string Name - { - get; - } - - public abstract Type StyleKey - { - get; - } - - public abstract ITemplatedControl TemplatedParent - { - get; - } - - IAvaloniaReadOnlyList IStyleable.Classes => Classes; - - IObservable IStyleable.StyleDetach { get; } - - public object GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public T GetValue(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, object value, BindingPriority priority) - { - throw new NotImplementedException(); - } - - public void SetValue(AvaloniaProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public IDisposable Bind(AvaloniaProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) - { - throw new NotImplementedException(); - } - - public bool IsAnimating(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - - public bool IsSet(AvaloniaProperty property) - { - throw new NotImplementedException(); - } - } -}