ImageTests.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.PixelWidth == 50 && x.PixelHeight == 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.PixelWidth == 50 && x.PixelHeight == 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.PixelWidth == 50 && x.PixelHeight == 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.PixelWidth == 50 && x.PixelHeight == 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. }
  52. }