MeasureTests.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Invalidating_Child_Should_Not_Invalidate_Parent()
  11. {
  12. var panel = new StackPanel();
  13. var child = new Border();
  14. panel.Children.Add(child);
  15. panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  16. Assert.Equal(new Size(0, 0), panel.DesiredSize);
  17. child.Width = 100;
  18. child.Height = 100;
  19. Assert.True(panel.IsMeasureValid);
  20. Assert.False(child.IsMeasureValid);
  21. panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  22. Assert.Equal(new Size(0, 0), panel.DesiredSize);
  23. }
  24. [Fact]
  25. public void Negative_Margin_Larger_Than_Constraint_Should_Request_Width_0()
  26. {
  27. Control target;
  28. var outer = new Decorator
  29. {
  30. Width = 100,
  31. Height = 100,
  32. Child = target = new Control
  33. {
  34. Margin = new Thickness(-100, 0, 0, 0),
  35. }
  36. };
  37. outer.Measure(Size.Infinity);
  38. Assert.Equal(0, target.DesiredSize.Width);
  39. }
  40. [Fact]
  41. public void Negative_Margin_Larger_Than_Constraint_Should_Request_Height_0()
  42. {
  43. Control target;
  44. var outer = new Decorator
  45. {
  46. Width = 100,
  47. Height = 100,
  48. Child = target = new Control
  49. {
  50. Margin = new Thickness(0, -100, 0, 0),
  51. }
  52. };
  53. outer.Measure(Size.Infinity);
  54. Assert.Equal(0, target.DesiredSize.Height);
  55. }
  56. }
  57. }