BoundsTrackerTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // -----------------------------------------------------------------------
  2. // <copyright file="BoundsTrackerTests.cs" company="Steven Kirk">
  3. // Copyright 2015 MIT Licence. See licence.md for more information.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace Perspex.SceneGraph.UnitTests.VisualTree
  7. {
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Reactive.Linq;
  12. using Perspex.Controls;
  13. using Perspex.Controls.Shapes;
  14. using Perspex.VisualTree;
  15. using Xunit;
  16. public class BoundsTrackerTests
  17. {
  18. [Fact]
  19. public void Should_Track_Bounds()
  20. {
  21. var target = new BoundsTracker();
  22. var control = default(Rectangle);
  23. var tree = new Decorator
  24. {
  25. Padding = new Thickness(10),
  26. Child = new Decorator
  27. {
  28. Padding = new Thickness(5),
  29. Child = control = new Rectangle
  30. {
  31. Width = 15,
  32. Height = 15,
  33. },
  34. }
  35. };
  36. tree.Measure(Size.Infinity);
  37. tree.Arrange(new Rect(0, 0, 100, 100));
  38. var track = target.Track(control, tree);
  39. var results = new List<TransformedBounds>();
  40. track.Subscribe(results.Add);
  41. Assert.Equal(new Rect(15, 15, 15, 15), results.Last().Bounds);
  42. tree.Padding = new Thickness(15);
  43. tree.Measure(Size.Infinity);
  44. tree.Arrange(new Rect(0, 0, 100, 100), true);
  45. Assert.Equal(new Rect(20, 20, 15, 15), results.Last().Bounds);
  46. }
  47. }
  48. }