BoundsTrackerTests.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) The Avalonia 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;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reactive.Linq;
  7. using Avalonia.Controls;
  8. using Avalonia.Controls.Shapes;
  9. using Avalonia.VisualTree;
  10. using Avalonia.Rendering;
  11. using Xunit;
  12. using Avalonia.Media;
  13. using Moq;
  14. using Avalonia.UnitTests;
  15. using Avalonia.Platform;
  16. namespace Avalonia.Visuals.UnitTests.VisualTree
  17. {
  18. public class BoundsTrackerTests
  19. {
  20. [Fact]
  21. public void Should_Track_Bounds()
  22. {
  23. using (UnitTestApplication.Start(TestServices.StyledWindow))
  24. {
  25. var target = new BoundsTracker();
  26. var control = default(Rectangle);
  27. var tree = new Decorator
  28. {
  29. Padding = new Thickness(10),
  30. Child = new Decorator
  31. {
  32. Padding = new Thickness(5),
  33. Child = control = new Rectangle
  34. {
  35. Width = 15,
  36. Height = 15,
  37. },
  38. }
  39. };
  40. var context = new DrawingContext(Mock.Of<IDrawingContextImpl>());
  41. tree.Measure(Size.Infinity);
  42. tree.Arrange(new Rect(0, 0, 100, 100));
  43. ImmediateRenderer.Render(tree, context);
  44. var track = target.Track(control);
  45. var results = new List<TransformedBounds?>();
  46. track.Subscribe(results.Add);
  47. Assert.Equal(new Rect(0, 0, 15, 15), results[0].Value.Bounds);
  48. Assert.Equal(Matrix.CreateTranslation(42, 42), results[0].Value.Transform);
  49. }
  50. }
  51. }
  52. }