PerspexObjectTests_Metadata.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System.Linq;
  4. using System.Reactive.Linq;
  5. using Xunit;
  6. namespace Perspex.Base.UnitTests
  7. {
  8. public class PerspexObjectTests_Metadata
  9. {
  10. public PerspexObjectTests_Metadata()
  11. {
  12. // Ensure properties are registered.
  13. PerspexProperty p;
  14. p = Class1.FooProperty;
  15. p = Class2.BarProperty;
  16. p = AttachedOwner.AttachedProperty;
  17. }
  18. [Fact]
  19. public void IsSet_Returns_False_For_Unset_Property()
  20. {
  21. var target = new Class1();
  22. Assert.False(target.IsSet(Class1.FooProperty));
  23. }
  24. [Fact]
  25. public void IsSet_Returns_False_For_Set_Property()
  26. {
  27. var target = new Class1();
  28. target.SetValue(Class1.FooProperty, "foo");
  29. Assert.True(target.IsSet(Class1.FooProperty));
  30. }
  31. [Fact]
  32. public void IsSet_Returns_False_For_Cleared_Property()
  33. {
  34. var target = new Class1();
  35. target.SetValue(Class1.FooProperty, "foo");
  36. target.SetValue(Class1.FooProperty, PerspexProperty.UnsetValue);
  37. Assert.False(target.IsSet(Class1.FooProperty));
  38. }
  39. private class Class1 : PerspexObject
  40. {
  41. public static readonly PerspexProperty<string> FooProperty =
  42. PerspexProperty.Register<Class1, string>("Foo");
  43. public static readonly PerspexProperty<string> BazProperty =
  44. PerspexProperty.Register<Class1, string>("Baz");
  45. public static readonly PerspexProperty<int> QuxProperty =
  46. PerspexProperty.Register<Class1, int>("Qux");
  47. }
  48. private class Class2 : Class1
  49. {
  50. public static readonly PerspexProperty<string> BarProperty =
  51. PerspexProperty.Register<Class2, string>("Bar");
  52. public static readonly PerspexProperty<double> FlobProperty =
  53. PerspexProperty.Register<Class2, double>("Flob");
  54. public static readonly PerspexProperty<double?> FredProperty =
  55. PerspexProperty.Register<Class2, double?>("Fred");
  56. }
  57. private class AttachedOwner
  58. {
  59. public static readonly PerspexProperty<string> AttachedProperty =
  60. PerspexProperty.RegisterAttached<AttachedOwner, Class1, string>("Attached");
  61. }
  62. }
  63. }