@ -1,13 +1,9 @@
using System ;
using Avalonia.Controls.Documents ;
using Avalonia.Controls.Templates ;
using Avalonia.Data ;
using Avalonia.Inp ut ;
using Avalonia.Layo ut ;
using Avalonia.Media ;
using Avalonia.Metadata ;
using Avalonia.Rendering ;
using Avalonia.UnitTests ;
using Moq ;
using Xunit ;
namespace Avalonia.Controls.UnitTests
@ -37,20 +33,74 @@ namespace Avalonia.Controls.UnitTests
{
var textBlock = new TestTextBlock { Text = "Hello World" } ;
Assert . Equal ( Size . Infinity , textBlock . Constraint ) ;
textBlock . Measure ( new Size ( 1 0 0 , 1 0 0 ) ) ;
var textLayout = textBlock . TextLayout ;
Assert . Equal ( new Size ( 1 0 0 , 1 0 0 ) , textBlock . Constraint ) ;
Assert . Equal ( new Size ( 1 1 0 , 1 0 ) , textBlock . Constraint ) ;
textBlock . Measure ( new Size ( 5 0 , 1 0 0 ) ) ;
Assert . Equal ( new Size ( 5 0 , 1 0 0 ) , textBlock . Constraint ) ;
Assert . NotEqual ( textLayout , textBlock . TextLayout ) ;
}
}
[Fact]
public void Calling_Arrange_With_Different_Size_Should_Update_Constraint_And_TextLayout ( )
{
using ( UnitTestApplication . Start ( TestServices . MockPlatformRenderInterface ) )
{
var textBlock = new TestTextBlock { Text = "Hello World" } ;
textBlock . Measure ( Size . Infinity ) ;
var textLayout = textBlock . TextLayout ;
var constraint = LayoutHelper . RoundLayoutSizeUp ( new Size ( textLayout . WidthIncludingTrailingWhitespace , textLayout . Height ) , 1 , 1 ) ;
Assert . Equal ( constraint , textBlock . Constraint ) ;
textBlock . Arrange ( new Rect ( constraint ) ) ;
Assert . Equal ( constraint , textBlock . Constraint ) ;
Assert . Equal ( textLayout , textBlock . TextLayout ) ;
textBlock . Measure ( constraint ) ;
Assert . Equal ( textLayout , textBlock . TextLayout ) ;
constraint + = new Size ( 5 0 , 0 ) ;
textBlock . Arrange ( new Rect ( constraint ) ) ;
Assert . Equal ( constraint , textBlock . Constraint ) ;
Assert . NotEqual ( textLayout , textBlock . TextLayout ) ;
}
}
[Fact]
public void Calling_Measure_With_Infinite_Space_Should_Set_DesiredSize ( )
{
using ( UnitTestApplication . Start ( TestServices . MockPlatformRenderInterface ) )
{
var textBlock = new TestTextBlock { Text = "Hello World" } ;
textBlock . Measure ( new Size ( double . PositiveInfinity , double . PositiveInfinity ) ) ;
var textLayout = textBlock . TextLayout ;
Assert . Equal ( new Size ( 1 1 0 , 1 0 ) , textBlock . Constraint ) ;
var constraint = LayoutHelper . RoundLayoutSizeUp ( new Size ( textLayout . WidthIncludingTrailingWhitespace , textLayout . Height ) , 1 , 1 ) ;
Assert . Equal ( constraint , textBlock . DesiredSize ) ;
}
}
[Fact]
public void Changing_InlinesCollection_Should_Invalidate_Measure ( )
{