BoundsTrackerTests.cs 1.8 KB

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