PerspexObjectTests_Metadata.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 GetRegisteredProperties_Returns_Registered_Properties()
  20. {
  21. string[] names = PerspexObject.GetRegisteredProperties(typeof(Class1)).Select(x => x.Name).ToArray();
  22. Assert.Equal(new[] { "Foo", "Baz", "Qux", "Attached" }, names);
  23. }
  24. [Fact]
  25. public void GetRegisteredProperties_Returns_Registered_Properties_For_Base_Types()
  26. {
  27. string[] names = PerspexObject.GetRegisteredProperties(typeof(Class2)).Select(x => x.Name).ToArray();
  28. Assert.Equal(new[] { "Bar", "Flob", "Fred", "Foo", "Baz", "Qux", "Attached" }, names);
  29. }
  30. private class Class1 : PerspexObject
  31. {
  32. public static readonly PerspexProperty<string> FooProperty =
  33. PerspexProperty.Register<Class1, string>("Foo");
  34. public static readonly PerspexProperty<string> BazProperty =
  35. PerspexProperty.Register<Class1, string>("Baz");
  36. public static readonly PerspexProperty<int> QuxProperty =
  37. PerspexProperty.Register<Class1, int>("Qux");
  38. }
  39. private class Class2 : Class1
  40. {
  41. public static readonly PerspexProperty<string> BarProperty =
  42. PerspexProperty.Register<Class2, string>("Bar");
  43. public static readonly PerspexProperty<double> FlobProperty =
  44. PerspexProperty.Register<Class2, double>("Flob");
  45. public static readonly PerspexProperty<double?> FredProperty =
  46. PerspexProperty.Register<Class2, double?>("Fred");
  47. }
  48. private class AttachedOwner
  49. {
  50. public static readonly PerspexProperty<string> AttachedProperty =
  51. PerspexProperty.RegisterAttached<AttachedOwner, Class1, string>("Attached");
  52. }
  53. }
  54. }