BorderTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Avalonia.Media;
  2. using Avalonia.Rendering;
  3. using Avalonia.UnitTests;
  4. using Moq;
  5. using Xunit;
  6. namespace Avalonia.Controls.UnitTests
  7. {
  8. public class BorderTests
  9. {
  10. [Fact]
  11. public void Measure_Should_Return_BorderThickness_Plus_Padding_When_No_Child_Present()
  12. {
  13. var target = new Border
  14. {
  15. Padding = new Thickness(6),
  16. BorderThickness = new Thickness(4)
  17. };
  18. target.Measure(new Size(100, 100));
  19. Assert.Equal(new Size(20, 20), target.DesiredSize);
  20. }
  21. [Fact]
  22. public void Child_Should_Arrange_With_Zero_Height_Width_If_Padding_Greater_Than_Child_Size()
  23. {
  24. Border content;
  25. var target = new Border
  26. {
  27. Padding = new Thickness(6),
  28. MaxHeight = 12,
  29. MaxWidth = 12,
  30. Child = content = new Border
  31. {
  32. Height = 0,
  33. Width = 0
  34. }
  35. };
  36. target.Arrange(new Rect(0, 0, 100, 100));
  37. Assert.Equal(new Rect(6, 6, 0, 0), content.Bounds);
  38. }
  39. [Fact]
  40. public void Changing_Background_Brush_Color_Should_Invalidate_Visual()
  41. {
  42. var target = new Border()
  43. {
  44. Background = new SolidColorBrush(Colors.Red),
  45. };
  46. var root = new TestRoot(target);
  47. var renderer = Mock.Get(root.Renderer);
  48. renderer.Invocations.Clear();
  49. ((SolidColorBrush)target.Background).Color = Colors.Green;
  50. renderer.Verify(x => x.AddDirty(target), Times.Once);
  51. }
  52. }
  53. }