AncestorFinderTests.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Avalonia.Controls.Utils;
  7. using Avalonia.VisualTree;
  8. using Xunit;
  9. namespace Avalonia.Controls.UnitTests.Utils
  10. {
  11. public class AncestorFinderTests
  12. {
  13. [Fact]
  14. public void SanityCheck()
  15. {
  16. var child = new Control();
  17. var parent = new Decorator();
  18. var grandParent = new Border();
  19. var grandParent2 = new Border();
  20. IStyledElement currentParent = null;
  21. var subscription = AncestorFinder.Create(child, typeof (Border)).Subscribe(s => currentParent = s);
  22. Assert.Null(currentParent);
  23. parent.Child = child;
  24. Assert.Null(currentParent);
  25. grandParent.Child = parent;
  26. Assert.Equal(grandParent, currentParent);
  27. grandParent.Child = null;
  28. grandParent2.Child = parent;
  29. Assert.Equal(grandParent2, currentParent);
  30. subscription.Dispose();
  31. parent.Child = null;
  32. Assert.Equal(grandParent2, currentParent);
  33. }
  34. }
  35. }