DockPanelTests.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Xunit;
  2. namespace Avalonia.Controls.UnitTests
  3. {
  4. public class DockPanelTests
  5. {
  6. [Fact]
  7. public void Should_Dock_Controls_Horizontal_First()
  8. {
  9. var target = new DockPanel
  10. {
  11. Children =
  12. {
  13. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Top },
  14. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Bottom },
  15. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Left },
  16. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Right },
  17. new Border { },
  18. }
  19. };
  20. target.Measure(Size.Infinity);
  21. target.Arrange(new Rect(target.DesiredSize));
  22. Assert.Equal(new Rect(0, 0, 500, 500), target.Bounds);
  23. Assert.Equal(new Rect(0, 0, 500, 50), target.Children[0].Bounds);
  24. Assert.Equal(new Rect(0, 450, 500, 50), target.Children[1].Bounds);
  25. Assert.Equal(new Rect(0, 50, 50, 400), target.Children[2].Bounds);
  26. Assert.Equal(new Rect(450, 50, 50, 400), target.Children[3].Bounds);
  27. Assert.Equal(new Rect(50, 50, 400, 400), target.Children[4].Bounds);
  28. }
  29. [Fact]
  30. public void Should_Dock_Controls_Vertical_First()
  31. {
  32. var target = new DockPanel
  33. {
  34. Children =
  35. {
  36. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Left },
  37. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Right },
  38. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Top },
  39. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Bottom },
  40. new Border { },
  41. }
  42. };
  43. target.Measure(Size.Infinity);
  44. target.Arrange(new Rect(target.DesiredSize));
  45. Assert.Equal(new Rect(0, 0, 600, 400), target.Bounds);
  46. Assert.Equal(new Rect(0, 0, 50, 400), target.Children[0].Bounds);
  47. Assert.Equal(new Rect(550, 0, 50, 400), target.Children[1].Bounds);
  48. Assert.Equal(new Rect(50, 0, 500, 50), target.Children[2].Bounds);
  49. Assert.Equal(new Rect(50, 350, 500, 50), target.Children[3].Bounds);
  50. Assert.Equal(new Rect(50, 50, 500, 300), target.Children[4].Bounds);
  51. }
  52. [Fact]
  53. public void Changing_Child_Dock_Invalidates_Measure()
  54. {
  55. Border child;
  56. var target = new DockPanel
  57. {
  58. Children =
  59. {
  60. (child = new Border
  61. {
  62. [DockPanel.DockProperty] = Dock.Left,
  63. }),
  64. }
  65. };
  66. target.Measure(Size.Infinity);
  67. target.Arrange(new Rect(target.DesiredSize));
  68. Assert.True(target.IsMeasureValid);
  69. DockPanel.SetDock(child, Dock.Right);
  70. Assert.False(target.IsMeasureValid);
  71. }
  72. }
  73. }