A cross-platform UI framework for .NET
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.
 
 
 

75 lines
2.2 KiB

// -----------------------------------------------------------------------
// <copyright file="ContentPresenterTests.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls.UnitTests
{
using System.Collections.Specialized;
using System.Linq;
using Perspex.Controls;
using Perspex.Controls.Presenters;
using Xunit;
public class ContentPresenterTests
{
[Fact]
public void Setting_Content_Should_Make_Control_Appear_In_LogicalChildren()
{
var target = new ContentPresenter();
var child = new Control();
target.Content = child;
target.ApplyTemplate();
Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
}
[Fact]
public void Clearing_Content_Should_Remove_From_LogicalChildren()
{
var target = new ContentPresenter();
var child = new Control();
target.Content = child;
target.Content = null;
Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
}
[Fact]
public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ContentPresenter();
var child = new Control();
var called = false;
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
called = e.Action == NotifyCollectionChangedAction.Add;
target.Content = child;
target.ApplyTemplate();
Assert.True(called);
}
[Fact]
public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ContentPresenter();
var child = new Control();
var called = false;
target.Content = child;
target.ApplyTemplate();
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = true;
target.Content = null;
target.ApplyTemplate();
Assert.True(called);
}
}
}