Browse Source

Added failing test for #11212.

pull/11341/head
Steven Kirk 3 years ago
parent
commit
e7c3e0c673
  1. 17
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Coercion.cs

17
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Coercion.cs

@ -31,6 +31,16 @@ namespace Avalonia.Base.UnitTests
Assert.Equal(100, target.GetValue(Class1.AttachedProperty)); Assert.Equal(100, target.GetValue(Class1.AttachedProperty));
} }
[Fact]
public void Coerces_Set_Value_Attached_On_Class_Not_Derived_From_Owner()
{
var target = new Class2();
target.SetValue(Class1.AttachedProperty, 150);
Assert.Equal(100, target.GetValue(Class1.AttachedProperty));
}
[Fact] [Fact]
public void Coerces_Bound_Value() public void Coerces_Bound_Value()
{ {
@ -301,7 +311,7 @@ namespace Avalonia.Base.UnitTests
coerce: CoerceFoo); coerce: CoerceFoo);
public static readonly AttachedProperty<int> AttachedProperty = public static readonly AttachedProperty<int> AttachedProperty =
AvaloniaProperty.RegisterAttached<Class1, Class1, int>( AvaloniaProperty.RegisterAttached<Class1, AvaloniaObject, int>(
"Attached", "Attached",
defaultValue: 11, defaultValue: 11,
coerce: CoerceFoo); coerce: CoerceFoo);
@ -332,8 +342,9 @@ namespace Avalonia.Base.UnitTests
public static int CoerceFoo(AvaloniaObject instance, int value) public static int CoerceFoo(AvaloniaObject instance, int value)
{ {
var o = (Class1)instance; return instance is Class1 o ?
return Math.Clamp(value, o.MinFoo, o.MaxFoo); Math.Clamp(value, o.MinFoo, o.MaxFoo) :
Math.Clamp(value, 0, 100);
} }
protected override void OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change) protected override void OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change)

Loading…
Cancel
Save