PerspexPropertyRegistryTests.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 PerspexPropertyRegistryTests
  9. {
  10. public PerspexPropertyRegistryTests()
  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 GetRegistered_Returns_Registered_Properties()
  20. {
  21. string[] names = PerspexPropertyRegistry.Instance.GetRegistered(typeof(Class1))
  22. .Select(x => x.Name)
  23. .ToArray();
  24. Assert.Equal(new[] { "Foo", "Baz", "Qux", "Attached" }, names);
  25. }
  26. [Fact]
  27. public void GetRegistered_Returns_Registered_Properties_For_Base_Types()
  28. {
  29. string[] names = PerspexPropertyRegistry.Instance.GetRegistered(typeof(Class2))
  30. .Select(x => x.Name)
  31. .ToArray();
  32. Assert.Equal(new[] { "Bar", "Flob", "Fred", "Foo", "Baz", "Qux", "Attached" }, names);
  33. }
  34. [Fact]
  35. public void GetAttached_Returns_Registered_Properties_For_Base_Types()
  36. {
  37. string[] names = PerspexPropertyRegistry.Instance.GetAttached(typeof(AttachedOwner)).Select(x => x.Name).ToArray();
  38. Assert.Equal(new[] { "Attached" }, names);
  39. }
  40. private class Class1 : PerspexObject
  41. {
  42. public static readonly PerspexProperty<string> FooProperty =
  43. PerspexProperty.Register<Class1, string>("Foo");
  44. public static readonly PerspexProperty<string> BazProperty =
  45. PerspexProperty.Register<Class1, string>("Baz");
  46. public static readonly PerspexProperty<int> QuxProperty =
  47. PerspexProperty.Register<Class1, int>("Qux");
  48. }
  49. private class Class2 : Class1
  50. {
  51. public static readonly PerspexProperty<string> BarProperty =
  52. PerspexProperty.Register<Class2, string>("Bar");
  53. public static readonly PerspexProperty<double> FlobProperty =
  54. PerspexProperty.Register<Class2, double>("Flob");
  55. public static readonly PerspexProperty<double?> FredProperty =
  56. PerspexProperty.Register<Class2, double?>("Fred");
  57. }
  58. private class AttachedOwner
  59. {
  60. public static readonly PerspexProperty<string> AttachedProperty =
  61. PerspexProperty.RegisterAttached<AttachedOwner, Class1, string>("Attached");
  62. }
  63. }
  64. }