Sfoglia il codice sorgente

Move attaching styles in tests to a helper.

The API is now internal, so this should prevent churn in the tests when the API changes.
Steven Kirk 2 anni fa
parent
commit
c29ed43e0e

+ 1 - 1
tests/Avalonia.Base.UnitTests/Animation/AnimatableTests.cs

@@ -436,7 +436,7 @@ namespace Avalonia.Base.UnitTests.Animation
                 }
                 }
             };
             };
 
 
-            style.TryAttach(control, control, FrameType.Style);
+            StyleHelpers.TryAttach(style, control);
 
 
             // Which means that the transition state hasn't been initialized with the new
             // Which means that the transition state hasn't been initialized with the new
             // Transitions when the Opacity change notification gets raised here.
             // Transitions when the Opacity change notification gets raised here.

+ 1 - 1
tests/Avalonia.Base.UnitTests/Styling/SetterTests.cs

@@ -504,7 +504,7 @@ namespace Avalonia.Base.UnitTests.Styling
 
 
         private void Apply(Style style, Control control)
         private void Apply(Style style, Control control)
         {
         {
-            style.TryAttach(control, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, control);
         }
         }
 
 
         private void Apply(Setter setter, Control control)
         private void Apply(Setter setter, Control control)

+ 8 - 8
tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs

@@ -28,7 +28,7 @@ namespace Avalonia.Base.UnitTests.Styling
 
 
             var target = new Class1();
             var target = new Class1();
 
 
-            style.TryAttach(target, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, target);
 
 
             Assert.Equal("Foo", target.Foo);
             Assert.Equal("Foo", target.Foo);
         }
         }
@@ -46,7 +46,7 @@ namespace Avalonia.Base.UnitTests.Styling
 
 
             var target = new Class1();
             var target = new Class1();
 
 
-            style.TryAttach(target, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, target);
             Assert.Equal("foodefault", target.Foo);
             Assert.Equal("foodefault", target.Foo);
             target.Classes.Add("foo");
             target.Classes.Add("foo");
             Assert.Equal("Foo", target.Foo);
             Assert.Equal("Foo", target.Foo);
@@ -67,7 +67,7 @@ namespace Avalonia.Base.UnitTests.Styling
 
 
             var target = new Class1();
             var target = new Class1();
 
 
-            style.TryAttach(target, target, FrameType.Style);
+            StyleHelpers.TryAttach(style, target);
 
 
             Assert.Equal("Foo", target.Foo);
             Assert.Equal("Foo", target.Foo);
         }
         }
@@ -93,7 +93,7 @@ namespace Avalonia.Base.UnitTests.Styling
             var target = new Class1();
             var target = new Class1();
             var other = new Class1();
             var other = new Class1();
 
 
-            style.TryAttach(target, other, FrameType.Style);
+            StyleHelpers.TryAttach(style, target, host: other);
 
 
             Assert.Equal("foodefault", target.Foo);
             Assert.Equal("foodefault", target.Foo);
         }
         }
@@ -114,7 +114,7 @@ namespace Avalonia.Base.UnitTests.Styling
                 Foo = "Original",
                 Foo = "Original",
             };
             };
 
 
-            style.TryAttach(target, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, target);
             Assert.Equal("Original", target.Foo);
             Assert.Equal("Original", target.Foo);
         }
         }
 
 
@@ -578,7 +578,7 @@ namespace Avalonia.Base.UnitTests.Styling
                 Child = border = new Border(),
                 Child = border = new Border(),
             };
             };
 
 
-            style.TryAttach(border, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, border);
 
 
             Assert.Equal(new Thickness(4), border.BorderThickness);
             Assert.Equal(new Thickness(4), border.BorderThickness);
             root.Child = null;
             root.Child = null;
@@ -762,7 +762,7 @@ namespace Avalonia.Base.UnitTests.Styling
 
 
             var target = new Class1();
             var target = new Class1();
 
 
-            style.TryAttach(target, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, target);
 
 
             Assert.Equal(1, target.Classes.ListenerCount);
             Assert.Equal(1, target.Classes.ListenerCount);
 
 
@@ -875,7 +875,7 @@ namespace Avalonia.Base.UnitTests.Styling
             var clock = new TestClock();
             var clock = new TestClock();
             var target = new Class1 { Clock = clock };
             var target = new Class1 { Clock = clock };
 
 
-            style.TryAttach(target, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, target);
 
 
             Assert.Equal(0.0, target.Double);
             Assert.Equal(0.0, target.Double);
 
 

+ 2 - 2
tests/Avalonia.Benchmarks/Styling/Style_Activation.cs

@@ -2,6 +2,7 @@
 using Avalonia.Controls;
 using Avalonia.Controls;
 using Avalonia.PropertyStore;
 using Avalonia.PropertyStore;
 using Avalonia.Styling;
 using Avalonia.Styling;
+using Avalonia.UnitTests;
 using BenchmarkDotNet.Attributes;
 using BenchmarkDotNet.Attributes;
 
 
 #nullable enable
 #nullable enable
@@ -27,8 +28,7 @@ namespace Avalonia.Benchmarks.Styling
             {
             {
                 Setters = { new Setter(TestClass.StringProperty, "foo") }
                 Setters = { new Setter(TestClass.StringProperty, "foo") }
             };
             };
-
-            style.TryAttach(_target, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, _target);
         }
         }
 
 
         [Benchmark]
         [Benchmark]

+ 2 - 1
tests/Avalonia.Benchmarks/Styling/Style_Apply.cs

@@ -4,6 +4,7 @@ using System.Runtime.CompilerServices;
 using Avalonia.Controls;
 using Avalonia.Controls;
 using Avalonia.PropertyStore;
 using Avalonia.PropertyStore;
 using Avalonia.Styling;
 using Avalonia.Styling;
+using Avalonia.UnitTests;
 using BenchmarkDotNet.Attributes;
 using BenchmarkDotNet.Attributes;
 
 
 #nullable enable
 #nullable enable
@@ -57,7 +58,7 @@ namespace Avalonia.Benchmarks.Styling
             target.GetValueStore().BeginStyling();
             target.GetValueStore().BeginStyling();
 
 
             foreach (var style in _styles)
             foreach (var style in _styles)
-                style.TryAttach(target, null, FrameType.Style);
+                StyleHelpers.TryAttach(style, target);
 
 
             target.GetValueStore().EndStyling();
             target.GetValueStore().EndStyling();
         }
         }

+ 4 - 3
tests/Avalonia.Benchmarks/Styling/Style_ClassSelector.cs

@@ -3,6 +3,7 @@ using System.Runtime.CompilerServices;
 using Avalonia.Controls;
 using Avalonia.Controls;
 using Avalonia.PropertyStore;
 using Avalonia.PropertyStore;
 using Avalonia.Styling;
 using Avalonia.Styling;
+using Avalonia.UnitTests;
 using BenchmarkDotNet.Attributes;
 using BenchmarkDotNet.Attributes;
 
 
 #nullable enable
 #nullable enable
@@ -36,7 +37,7 @@ namespace Avalonia.Benchmarks.Styling
             target.GetValueStore().BeginStyling();
             target.GetValueStore().BeginStyling();
 
 
             for (var i = 0; i < 50; ++i)
             for (var i = 0; i < 50; ++i)
-                _style.TryAttach(target, null, FrameType.Style);
+                StyleHelpers.TryAttach(_style, target);
 
 
             target.GetValueStore().EndStyling();
             target.GetValueStore().EndStyling();
         }
         }
@@ -49,7 +50,7 @@ namespace Avalonia.Benchmarks.Styling
             target.GetValueStore().BeginStyling();
             target.GetValueStore().BeginStyling();
 
 
             for (var i = 0; i < 50; ++i)
             for (var i = 0; i < 50; ++i)
-                _style.TryAttach(target, null, FrameType.Style);
+                StyleHelpers.TryAttach(_style, target);
 
 
             target.GetValueStore().EndStyling();
             target.GetValueStore().EndStyling();
 
 
@@ -65,7 +66,7 @@ namespace Avalonia.Benchmarks.Styling
             target.GetValueStore().BeginStyling();
             target.GetValueStore().BeginStyling();
 
 
             for (var i = 0; i < 50; ++i)
             for (var i = 0; i < 50; ++i)
-                _style.TryAttach(target, null, FrameType.Style);
+                StyleHelpers.TryAttach(_style, target);
 
 
             target.GetValueStore().EndStyling();
             target.GetValueStore().EndStyling();
 
 

+ 2 - 1
tests/Avalonia.Benchmarks/Styling/Style_NonActive.cs

@@ -2,6 +2,7 @@
 using Avalonia.Controls;
 using Avalonia.Controls;
 using Avalonia.PropertyStore;
 using Avalonia.PropertyStore;
 using Avalonia.Styling;
 using Avalonia.Styling;
+using Avalonia.UnitTests;
 using BenchmarkDotNet.Attributes;
 using BenchmarkDotNet.Attributes;
 
 
 #nullable enable
 #nullable enable
@@ -28,7 +29,7 @@ namespace Avalonia.Benchmarks.Styling
                 Setters = { new Setter(TestClass.StringProperty, "foo") }
                 Setters = { new Setter(TestClass.StringProperty, "foo") }
             };
             };
 
 
-            style.TryAttach(_target, null, FrameType.Style);
+            StyleHelpers.TryAttach(style, _target);
             _target.SetValue(TestClass.StringProperty, "foo");
             _target.SetValue(TestClass.StringProperty, "foo");
             _target.SetValue(TestClass.Struct1Property, new(1));
             _target.SetValue(TestClass.Struct1Property, new(1));
             _target.SetValue(TestClass.Struct2Property, new(1));
             _target.SetValue(TestClass.Struct2Property, new(1));

+ 1 - 1
tests/Avalonia.Markup.Xaml.UnitTests/StyleTests.cs

@@ -55,7 +55,7 @@ namespace Avalonia.Markup.Xaml.UnitTests
                     }
                     }
                 };
                 };
 
 
-                style.TryAttach(control, control, FrameType.Style);
+                StyleHelpers.TryAttach(style, control);
                 Assert.Equal("foo", control.Text);
                 Assert.Equal("foo", control.Text);
 
 
                 control.Text = "bar";
                 control.Text = "bar";

+ 14 - 0
tests/Avalonia.UnitTests/StyleHelpers.cs

@@ -0,0 +1,14 @@
+using Avalonia.Styling;
+
+#nullable enable
+
+namespace Avalonia.UnitTests
+{
+    public static class StyleHelpers
+    {
+        public static SelectorMatchResult TryAttach(Style style, StyledElement element, object? host = null)
+        {
+            return style.TryAttach(element, host ?? element, PropertyStore.FrameType.Style);
+        }
+    }
+}