|
@@ -13,7 +13,7 @@ namespace Avalonia.Controls.UnitTests
|
|
[Fact]
|
|
[Fact]
|
|
public void Measure_Should_Return_Correct_Size_For_No_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.None;
|
|
target.Stretch = Stretch.None;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -26,7 +26,7 @@ namespace Avalonia.Controls.UnitTests
|
|
[Fact]
|
|
[Fact]
|
|
public void Measure_Should_Return_Correct_Size_For_Fill_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.Fill;
|
|
target.Stretch = Stretch.Fill;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -39,7 +39,7 @@ namespace Avalonia.Controls.UnitTests
|
|
[Fact]
|
|
[Fact]
|
|
public void Measure_Should_Return_Correct_Size_For_Uniform_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.Uniform;
|
|
target.Stretch = Stretch.Uniform;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -52,7 +52,7 @@ namespace Avalonia.Controls.UnitTests
|
|
[Fact]
|
|
[Fact]
|
|
public void Measure_Should_Return_Correct_Size_For_UniformToFill_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.UniformToFill;
|
|
target.Stretch = Stretch.UniformToFill;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -62,10 +62,46 @@ namespace Avalonia.Controls.UnitTests
|
|
Assert.Equal(new Size(50, 50), target.DesiredSize);
|
|
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]
|
|
[Fact]
|
|
public void Arrange_Should_Return_Correct_Size_For_No_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.None;
|
|
target.Stretch = Stretch.None;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -79,7 +115,7 @@ namespace Avalonia.Controls.UnitTests
|
|
[Fact]
|
|
[Fact]
|
|
public void Arrange_Should_Return_Correct_Size_For_Fill_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.Fill;
|
|
target.Stretch = Stretch.Fill;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -93,7 +129,7 @@ namespace Avalonia.Controls.UnitTests
|
|
[Fact]
|
|
[Fact]
|
|
public void Arrange_Should_Return_Correct_Size_For_Uniform_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.Uniform;
|
|
target.Stretch = Stretch.Uniform;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -107,7 +143,7 @@ namespace Avalonia.Controls.UnitTests
|
|
[Fact]
|
|
[Fact]
|
|
public void Arrange_Should_Return_Correct_Size_For_UniformToFill_Stretch()
|
|
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();
|
|
var target = new Image();
|
|
target.Stretch = Stretch.UniformToFill;
|
|
target.Stretch = Stretch.UniformToFill;
|
|
target.Source = bitmap;
|
|
target.Source = bitmap;
|
|
@@ -117,5 +153,10 @@ namespace Avalonia.Controls.UnitTests
|
|
|
|
|
|
Assert.Equal(new Size(25, 100), target.Bounds.Size);
|
|
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));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|