Browse Source

Added failing tests for #3371.

pull/3373/head
Steven Kirk 6 years ago
parent
commit
a0f72ff47c
  1. 57
      tests/Avalonia.Controls.UnitTests/ImageTests.cs

57
tests/Avalonia.Controls.UnitTests/ImageTests.cs

@ -13,7 +13,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Measure_Should_Return_Correct_Size_For_No_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.None;
target.Source = bitmap;
@ -26,7 +26,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Measure_Should_Return_Correct_Size_For_Fill_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.Fill;
target.Source = bitmap;
@ -39,7 +39,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Measure_Should_Return_Correct_Size_For_Uniform_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.Uniform;
target.Source = bitmap;
@ -52,7 +52,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Measure_Should_Return_Correct_Size_For_UniformToFill_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.UniformToFill;
target.Source = bitmap;
@ -62,10 +62,46 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(50, 50), target.DesiredSize);
}
[Fact]
public void Measure_Should_Return_Correct_Size_For_Infinite_Height()
{
var bitmap = CreateBitmap(50, 100);
var image = new Image();
image.Source = bitmap;
image.Measure(new Size(200, double.PositiveInfinity));
Assert.Equal(new Size(200, 400), image.DesiredSize);
}
[Fact]
public void Measure_Should_Return_Correct_Size_For_Infinite_Width()
{
var bitmap = CreateBitmap(50, 100);
var image = new Image();
image.Source = bitmap;
image.Measure(new Size(double.PositiveInfinity, 400));
Assert.Equal(new Size(200, 400), image.DesiredSize);
}
[Fact]
public void Measure_Should_Return_Correct_Size_For_Infinite_Width_Height()
{
var bitmap = CreateBitmap(50, 100);
var image = new Image();
image.Source = bitmap;
image.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
Assert.Equal(new Size(50, 100), image.DesiredSize);
}
[Fact]
public void Arrange_Should_Return_Correct_Size_For_No_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.None;
target.Source = bitmap;
@ -79,7 +115,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Arrange_Should_Return_Correct_Size_For_Fill_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.Fill;
target.Source = bitmap;
@ -93,7 +129,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Arrange_Should_Return_Correct_Size_For_Uniform_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.Uniform;
target.Source = bitmap;
@ -107,7 +143,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void Arrange_Should_Return_Correct_Size_For_UniformToFill_Stretch()
{
var bitmap = Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(50, 100));
var bitmap = CreateBitmap(50, 100);
var target = new Image();
target.Stretch = Stretch.UniformToFill;
target.Source = bitmap;
@ -117,5 +153,10 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(25, 100), target.Bounds.Size);
}
private IBitmap CreateBitmap(int width, int height)
{
return Mock.Of<IBitmap>(x => x.PixelSize == new PixelSize(width, height));
}
}
}

Loading…
Cancel
Save