From df7b5a4ac9d6be30d585dedfcbd8cd1bb38594af Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 29 Jan 2016 22:05:44 +0100 Subject: [PATCH] Test attached property validation. --- .../PerspexObjectTests_Validation.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Perspex.Base.UnitTests/PerspexObjectTests_Validation.cs b/tests/Perspex.Base.UnitTests/PerspexObjectTests_Validation.cs index cfbf31a764..8d0cf2794a 100644 --- a/tests/Perspex.Base.UnitTests/PerspexObjectTests_Validation.cs +++ b/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 QuxProperty = PerspexProperty.Register("Qux", validate: Validate); + public static readonly AttachedProperty AttachedProperty = + PerspexProperty.RegisterAttached("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