DockPanelTests.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Xunit;
  4. namespace Perspex.Controls.UnitTests
  5. {
  6. public class DockPanelTests
  7. {
  8. [Fact]
  9. public void Should_Dock_Controls_Horizontal_First()
  10. {
  11. var target = new DockPanel
  12. {
  13. Children = new Controls
  14. {
  15. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Top },
  16. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Bottom },
  17. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Left },
  18. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Right },
  19. new Border { },
  20. }
  21. };
  22. target.Measure(Size.Infinity);
  23. target.Arrange(new Rect(target.DesiredSize));
  24. Assert.Equal(new Rect(0, 0, 500, 500), target.Bounds);
  25. Assert.Equal(new Rect(0, 0, 500, 50), target.Children[0].Bounds);
  26. Assert.Equal(new Rect(0, 450, 500, 50), target.Children[1].Bounds);
  27. Assert.Equal(new Rect(0, 50, 50, 400), target.Children[2].Bounds);
  28. Assert.Equal(new Rect(450, 50, 50, 400), target.Children[3].Bounds);
  29. Assert.Equal(new Rect(50, 50, 400, 400), target.Children[4].Bounds);
  30. }
  31. [Fact]
  32. public void Should_Dock_Controls_Vertical_First()
  33. {
  34. var target = new DockPanel
  35. {
  36. Children = new Controls
  37. {
  38. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Left },
  39. new Border { Width = 50, Height = 400, [DockPanel.DockProperty] = Dock.Right },
  40. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Top },
  41. new Border { Width = 500, Height = 50, [DockPanel.DockProperty] = Dock.Bottom },
  42. new Border { },
  43. }
  44. };
  45. target.Measure(Size.Infinity);
  46. target.Arrange(new Rect(target.DesiredSize));
  47. Assert.Equal(new Rect(0, 0, 600, 400), target.Bounds);
  48. Assert.Equal(new Rect(0, 0, 50, 400), target.Children[0].Bounds);
  49. Assert.Equal(new Rect(550, 0, 50, 400), target.Children[1].Bounds);
  50. Assert.Equal(new Rect(50, 0, 500, 50), target.Children[2].Bounds);
  51. Assert.Equal(new Rect(50, 350, 500, 50), target.Children[3].Bounds);
  52. Assert.Equal(new Rect(50, 50, 500, 300), target.Children[4].Bounds);
  53. }
  54. }
  55. }