Browse Source

Test attached property validation.

pull/387/merge
Steven Kirk 10 years ago
parent
commit
df7b5a4ac9
  1. 17
      tests/Perspex.Base.UnitTests/PerspexObjectTests_Validation.cs

17
tests/Perspex.Base.UnitTests/PerspexObjectTests_Validation.cs

@ -69,11 +69,23 @@ namespace Perspex.Base.UnitTests
source.OnNext(PerspexProperty.UnsetValue);
}
[Fact]
public void Attached_Property_Should_Be_Validated()
{
var target = new Class2();
target.SetValue(Class1.AttachedProperty, 15);
Assert.Equal(10, target.GetValue(Class1.AttachedProperty));
}
private class Class1 : PerspexObject
{
public static readonly StyledProperty<int> QuxProperty =
PerspexProperty.Register<Class1, int>("Qux", validate: Validate);
public static readonly AttachedProperty<int> AttachedProperty =
PerspexProperty.RegisterAttached<Class1, Class2, int>("Attached", validate: Validate);
public Class1()
{
MaxQux = 10;
@ -93,6 +105,11 @@ namespace Perspex.Base.UnitTests
return Math.Min(Math.Max(value, 0), ((Class1)instance).MaxQux);
}
private static int Validate(Class2 instance, int value)
{
return Math.Min(value, 10);
}
}
private class Class2 : PerspexObject

Loading…
Cancel
Save