Browse Source

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.
pull/9500/head
Steven Kirk 3 years ago
parent
commit
c29ed43e0e
  1. 2
      tests/Avalonia.Base.UnitTests/Animation/AnimatableTests.cs
  2. 2
      tests/Avalonia.Base.UnitTests/Styling/SetterTests.cs
  3. 16
      tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs
  4. 4
      tests/Avalonia.Benchmarks/Styling/Style_Activation.cs
  5. 3
      tests/Avalonia.Benchmarks/Styling/Style_Apply.cs
  6. 7
      tests/Avalonia.Benchmarks/Styling/Style_ClassSelector.cs
  7. 3
      tests/Avalonia.Benchmarks/Styling/Style_NonActive.cs
  8. 2
      tests/Avalonia.Markup.Xaml.UnitTests/StyleTests.cs
  9. 14
      tests/Avalonia.UnitTests/StyleHelpers.cs

2
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
// Transitions when the Opacity change notification gets raised here.

2
tests/Avalonia.Base.UnitTests/Styling/SetterTests.cs

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

16
tests/Avalonia.Base.UnitTests/Styling/StyleTests.cs

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

4
tests/Avalonia.Benchmarks/Styling/Style_Activation.cs

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

3
tests/Avalonia.Benchmarks/Styling/Style_Apply.cs

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

7
tests/Avalonia.Benchmarks/Styling/Style_ClassSelector.cs

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

3
tests/Avalonia.Benchmarks/Styling/Style_NonActive.cs

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

2
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);
control.Text = "bar";

14
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);
}
}
}
Loading…
Cancel
Save