WrapPanelTests.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 Xunit;
  4. namespace Avalonia.Controls.UnitTests
  5. {
  6. public class WrapPanelTests
  7. {
  8. [Fact]
  9. public void Lays_Out_Horizontally_On_Separate_Lines()
  10. {
  11. var target = new WrapPanel()
  12. {
  13. Width = 100,
  14. Children = new Controls
  15. {
  16. new Border { Height = 50, Width = 100 },
  17. new Border { Height = 50, Width = 100 },
  18. }
  19. };
  20. target.Measure(Size.Infinity);
  21. target.Arrange(new Rect(target.DesiredSize));
  22. Assert.Equal(new Size(100, 100), target.Bounds.Size);
  23. Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds);
  24. Assert.Equal(new Rect(0, 50, 100, 50), target.Children[1].Bounds);
  25. }
  26. [Fact]
  27. public void Lays_Out_Horizontally_On_A_Single_Line()
  28. {
  29. var target = new WrapPanel()
  30. {
  31. Width = 200,
  32. Children = new Controls
  33. {
  34. new Border { Height = 50, Width = 100 },
  35. new Border { Height = 50, Width = 100 },
  36. }
  37. };
  38. target.Measure(Size.Infinity);
  39. target.Arrange(new Rect(target.DesiredSize));
  40. Assert.Equal(new Size(200, 50), target.Bounds.Size);
  41. Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds);
  42. Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].Bounds);
  43. }
  44. [Fact]
  45. public void Lays_Out_Vertically_Children_On_A_Single_Line()
  46. {
  47. var target = new WrapPanel()
  48. {
  49. Orientation = Orientation.Vertical,
  50. Height = 120,
  51. Children = new Controls
  52. {
  53. new Border { Height = 50, Width = 100 },
  54. new Border { Height = 50, Width = 100 },
  55. }
  56. };
  57. target.Measure(Size.Infinity);
  58. target.Arrange(new Rect(target.DesiredSize));
  59. Assert.Equal(new Size(100, 120), target.Bounds.Size);
  60. Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds);
  61. Assert.Equal(new Rect(0, 50, 100, 50), target.Children[1].Bounds);
  62. }
  63. [Fact]
  64. public void Lays_Out_Vertically_On_Separate_Lines()
  65. {
  66. var target = new WrapPanel()
  67. {
  68. Orientation = Orientation.Vertical,
  69. Height = 60,
  70. Children = new Controls
  71. {
  72. new Border { Height = 50, Width = 100 },
  73. new Border { Height = 50, Width = 100 },
  74. }
  75. };
  76. target.Measure(Size.Infinity);
  77. target.Arrange(new Rect(target.DesiredSize));
  78. Assert.Equal(new Size(200, 60), target.Bounds.Size);
  79. Assert.Equal(new Rect(0, 0, 100, 50), target.Children[0].Bounds);
  80. Assert.Equal(new Rect(100, 0, 100, 50), target.Children[1].Bounds);
  81. }
  82. }
  83. }