1
0

MeasureTests.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Perspex.Controls;
  4. using Xunit;
  5. namespace Perspex.Layout.UnitTests
  6. {
  7. public class MeasureTests
  8. {
  9. [Fact]
  10. public void Margin_Should_Be_Included_In_DesiredSize()
  11. {
  12. var decorator = new Decorator
  13. {
  14. Width = 100,
  15. Height = 100,
  16. Margin = new Thickness(8),
  17. };
  18. decorator.Measure(Size.Infinity);
  19. Assert.Equal(new Size(116, 116), decorator.DesiredSize);
  20. }
  21. [Fact]
  22. public void Invalidating_Child_Should_Not_Invalidate_Parent()
  23. {
  24. var panel = new StackPanel();
  25. var child = new Border();
  26. panel.Children.Add(child);
  27. panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  28. Assert.Equal(new Size(0, 0), panel.DesiredSize);
  29. child.Width = 100;
  30. child.Height = 100;
  31. Assert.True(panel.IsMeasureValid);
  32. Assert.False(child.IsMeasureValid);
  33. panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  34. Assert.Equal(new Size(0, 0), panel.DesiredSize);
  35. }
  36. [Fact]
  37. public void Negative_Margin_Larger_Than_Constraint_Should_Request_Width_0()
  38. {
  39. Control target;
  40. var outer = new Decorator
  41. {
  42. Width = 100,
  43. Height = 100,
  44. Child = target = new Control
  45. {
  46. Margin = new Thickness(-100, 0, 0, 0),
  47. }
  48. };
  49. outer.Measure(Size.Infinity);
  50. Assert.Equal(0, target.DesiredSize.Width);
  51. }
  52. [Fact]
  53. public void Negative_Margin_Larger_Than_Constraint_Should_Request_Height_0()
  54. {
  55. Control target;
  56. var outer = new Decorator
  57. {
  58. Width = 100,
  59. Height = 100,
  60. Child = target = new Control
  61. {
  62. Margin = new Thickness(0, -100, 0, 0),
  63. }
  64. };
  65. outer.Measure(Size.Infinity);
  66. Assert.Equal(0, target.DesiredSize.Height);
  67. }
  68. }
  69. }