csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.3 KiB
83 lines
2.3 KiB
using System;
|
|
using Avalonia.Controls;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace Avalonia.Layout.UnitTests
|
|
{
|
|
public class LayoutableTests
|
|
{
|
|
[Fact]
|
|
public void Only_Calls_LayoutManager_InvalidateMeasure_Once()
|
|
{
|
|
var target = new Mock<ILayoutManager>();
|
|
var control = new Decorator();
|
|
var root = new LayoutTestRoot
|
|
{
|
|
Child = control,
|
|
LayoutManager = target.Object,
|
|
};
|
|
|
|
root.Measure(Size.Infinity);
|
|
root.Arrange(new Rect(root.DesiredSize));
|
|
target.ResetCalls();
|
|
|
|
control.InvalidateMeasure();
|
|
control.InvalidateMeasure();
|
|
|
|
target.Verify(x => x.InvalidateMeasure(control), Times.Once());
|
|
}
|
|
|
|
[Fact]
|
|
public void Only_Calls_LayoutManager_InvalidateArrange_Once()
|
|
{
|
|
var target = new Mock<ILayoutManager>();
|
|
var control = new Decorator();
|
|
var root = new LayoutTestRoot
|
|
{
|
|
Child = control,
|
|
LayoutManager = target.Object,
|
|
};
|
|
|
|
root.Measure(Size.Infinity);
|
|
root.Arrange(new Rect(root.DesiredSize));
|
|
target.ResetCalls();
|
|
|
|
control.InvalidateArrange();
|
|
control.InvalidateArrange();
|
|
|
|
target.Verify(x => x.InvalidateArrange(control), Times.Once());
|
|
}
|
|
|
|
[Fact]
|
|
public void Attaching_Control_To_Tree_Invalidates_Parent_Measure()
|
|
{
|
|
var target = new Mock<ILayoutManager>();
|
|
var control = new Decorator();
|
|
var root = new LayoutTestRoot
|
|
{
|
|
Child = control,
|
|
LayoutManager = target.Object,
|
|
};
|
|
|
|
root.Measure(Size.Infinity);
|
|
root.Arrange(new Rect(root.DesiredSize));
|
|
Assert.True(control.IsMeasureValid);
|
|
|
|
root.Child = null;
|
|
root.Measure(Size.Infinity);
|
|
root.Arrange(new Rect(root.DesiredSize));
|
|
|
|
Assert.False(control.IsMeasureValid);
|
|
Assert.True(root.IsMeasureValid);
|
|
|
|
target.ResetCalls();
|
|
|
|
root.Child = control;
|
|
|
|
Assert.False(root.IsMeasureValid);
|
|
Assert.False(control.IsMeasureValid);
|
|
target.Verify(x => x.InvalidateMeasure(root), Times.Once());
|
|
}
|
|
}
|
|
}
|
|
|