10 changed files with 147 additions and 76 deletions
@ -0,0 +1,86 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="ContentPresenterTests.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Controls.UnitTests |
|||
{ |
|||
using System; |
|||
using System.Collections.Specialized; |
|||
using System.Linq; |
|||
using Moq; |
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Presenters; |
|||
using Perspex.Controls.Templates; |
|||
using Perspex.Layout; |
|||
using Perspex.Platform; |
|||
using Perspex.Styling; |
|||
using Perspex.VisualTree; |
|||
using Ploeh.AutoFixture; |
|||
using Ploeh.AutoFixture.AutoMoq; |
|||
using Splat; |
|||
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 = e.Action == NotifyCollectionChangedAction.Remove; |
|||
|
|||
target.Content = null; |
|||
target.ApplyTemplate(); |
|||
|
|||
Assert.True(called); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue