AncestorFinderTests.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.UnitTests;
  8. using Avalonia.VisualTree;
  9. using Xunit;
  10. namespace Avalonia.Controls.UnitTests.Utils
  11. {
  12. public class AncestorFinderTests : ScopedTestBase
  13. {
  14. [Fact]
  15. public void SanityCheck()
  16. {
  17. var child = new Control();
  18. var parent = new Decorator();
  19. var grandParent = new Border();
  20. var grandParent2 = new Border();
  21. StyledElement currentParent = null;
  22. var subscription = AncestorFinder.Create(child, typeof (Border)).Subscribe(s => currentParent = s);
  23. Assert.Null(currentParent);
  24. parent.Child = child;
  25. Assert.Null(currentParent);
  26. grandParent.Child = parent;
  27. Assert.Equal(grandParent, currentParent);
  28. grandParent.Child = null;
  29. grandParent2.Child = parent;
  30. Assert.Equal(grandParent2, currentParent);
  31. subscription.Dispose();
  32. parent.Child = null;
  33. Assert.Equal(grandParent2, currentParent);
  34. }
  35. }
  36. }