ImageTests.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 Moq;
  4. using Avalonia.Media;
  5. using Avalonia.Media.Imaging;
  6. using Xunit;
  7. namespace Avalonia.Controls.UnitTests
  8. {
  9. public class ImageTests
  10. {
  11. [Fact]
  12. public void Measure_Should_Return_Correct_Size_For_No_Stretch()
  13. {
  14. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  15. var target = new Image();
  16. target.Stretch = Stretch.None;
  17. target.Source = bitmap;
  18. target.Measure(new Size(50, 50));
  19. Assert.Equal(new Size(50, 50), target.DesiredSize);
  20. }
  21. [Fact]
  22. public void Measure_Should_Return_Correct_Size_For_Fill_Stretch()
  23. {
  24. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  25. var target = new Image();
  26. target.Stretch = Stretch.Fill;
  27. target.Source = bitmap;
  28. target.Measure(new Size(50, 50));
  29. Assert.Equal(new Size(50, 50), target.DesiredSize);
  30. }
  31. [Fact]
  32. public void Measure_Should_Return_Correct_Size_For_Uniform_Stretch()
  33. {
  34. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  35. var target = new Image();
  36. target.Stretch = Stretch.Uniform;
  37. target.Source = bitmap;
  38. target.Measure(new Size(50, 50));
  39. Assert.Equal(new Size(25, 50), target.DesiredSize);
  40. }
  41. [Fact]
  42. public void Measure_Should_Return_Correct_Size_For_UniformToFill_Stretch()
  43. {
  44. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  45. var target = new Image();
  46. target.Stretch = Stretch.UniformToFill;
  47. target.Source = bitmap;
  48. target.Measure(new Size(50, 50));
  49. Assert.Equal(new Size(50, 50), target.DesiredSize);
  50. }
  51. [Fact]
  52. public void Arrange_Should_Return_Correct_Size_For_No_Stretch()
  53. {
  54. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  55. var target = new Image();
  56. target.Stretch = Stretch.None;
  57. target.Source = bitmap;
  58. target.Measure(new Size(50, 50));
  59. target.Arrange(new Rect(0, 0, 100, 400));
  60. Assert.Equal(new Size(50, 100), target.Bounds.Size);
  61. }
  62. [Fact]
  63. public void Arrange_Should_Return_Correct_Size_For_Fill_Stretch()
  64. {
  65. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  66. var target = new Image();
  67. target.Stretch = Stretch.Fill;
  68. target.Source = bitmap;
  69. target.Measure(new Size(50, 50));
  70. target.Arrange(new Rect(0, 0, 25, 100));
  71. Assert.Equal(new Size(25, 100), target.Bounds.Size);
  72. }
  73. [Fact]
  74. public void Arrange_Should_Return_Correct_Size_For_Uniform_Stretch()
  75. {
  76. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  77. var target = new Image();
  78. target.Stretch = Stretch.Uniform;
  79. target.Source = bitmap;
  80. target.Measure(new Size(50, 50));
  81. target.Arrange(new Rect(0, 0, 25, 100));
  82. Assert.Equal(new Size(25, 50), target.Bounds.Size);
  83. }
  84. [Fact]
  85. public void Arrange_Should_Return_Correct_Size_For_UniformToFill_Stretch()
  86. {
  87. var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
  88. var target = new Image();
  89. target.Stretch = Stretch.UniformToFill;
  90. target.Source = bitmap;
  91. target.Measure(new Size(50, 50));
  92. target.Arrange(new Rect(0, 0, 25, 100));
  93. Assert.Equal(new Size(25, 100), target.Bounds.Size);
  94. }
  95. }
  96. }