CanvasTests.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using Avalonia.Controls.Shapes;
  3. using Avalonia.UnitTests;
  4. using Xunit;
  5. namespace Avalonia.Controls.UnitTests
  6. {
  7. public class CanvasTests : ScopedTestBase
  8. {
  9. [Fact]
  10. public void Left_Property_Should_Work()
  11. {
  12. using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);
  13. Rectangle rect;
  14. var target = new Canvas
  15. {
  16. Width = 400,
  17. Height = 400,
  18. Children =
  19. {
  20. (rect = new Rectangle
  21. {
  22. MinWidth = 20,
  23. MinHeight = 25,
  24. [Canvas.LeftProperty] = 30,
  25. })
  26. }
  27. };
  28. target.Measure(new Size(400, 400));
  29. target.Arrange(new Rect(target.DesiredSize));
  30. Assert.Equal(new Rect(30, 0, 20, 25), rect.Bounds);
  31. }
  32. [Fact]
  33. public void Top_Property_Should_Work()
  34. {
  35. using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);
  36. Rectangle rect;
  37. var target = new Canvas
  38. {
  39. Width = 400,
  40. Height = 400,
  41. Children =
  42. {
  43. (rect = new Rectangle
  44. {
  45. MinWidth = 20,
  46. MinHeight = 25,
  47. [Canvas.TopProperty] = 30,
  48. })
  49. }
  50. };
  51. target.Measure(new Size(400, 400));
  52. target.Arrange(new Rect(target.DesiredSize));
  53. Assert.Equal(new Rect(0, 30, 20, 25), rect.Bounds);
  54. }
  55. [Fact]
  56. public void Right_Property_Should_Work()
  57. {
  58. using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);
  59. Rectangle rect;
  60. var target = new Canvas
  61. {
  62. Width = 400,
  63. Height = 400,
  64. Children =
  65. {
  66. (rect = new Rectangle
  67. {
  68. MinWidth = 20,
  69. MinHeight = 25,
  70. [Canvas.RightProperty] = 30,
  71. })
  72. }
  73. };
  74. target.Measure(new Size(400, 400));
  75. target.Arrange(new Rect(target.DesiredSize));
  76. Assert.Equal(new Rect(350, 0, 20, 25), rect.Bounds);
  77. }
  78. [Fact]
  79. public void Bottom_Property_Should_Work()
  80. {
  81. using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);
  82. Rectangle rect;
  83. var target = new Canvas
  84. {
  85. Width = 400,
  86. Height = 400,
  87. Children =
  88. {
  89. (rect = new Rectangle
  90. {
  91. MinWidth = 20,
  92. MinHeight = 25,
  93. [Canvas.BottomProperty] = 30,
  94. })
  95. }
  96. };
  97. target.Measure(new Size(400, 400));
  98. target.Arrange(new Rect(target.DesiredSize));
  99. Assert.Equal(new Rect(0, 345, 20, 25), rect.Bounds);
  100. }
  101. }
  102. }