Browse Source

Fixed failing test.

pull/227/head
Steven Kirk 11 years ago
parent
commit
005d95780b
  1. 8
      src/Perspex.Controls/Presenters/ContentPresenter.cs
  2. 18
      tests/Perspex.Controls.UnitTests/ContentPresenterTests.cs
  3. 6
      tests/Perspex.Controls.UnitTests/Utils/HotKeyManagerTests.cs

8
src/Perspex.Controls/Presenters/ContentPresenter.cs

@ -104,8 +104,12 @@ namespace Perspex.Controls.Presenters
var logicalHost = this.FindReparentingHost();
var logicalChildren = logicalHost?.LogicalChildren ?? LogicalChildren;
logicalChildren.Remove(old);
ClearVisualChildren();
if (old != null)
{
logicalChildren.Remove(old);
((ISetLogicalParent)old).SetParent(null);
ClearVisualChildren();
}
Child = result;

18
tests/Perspex.Controls.UnitTests/ContentPresenterTests.cs

@ -4,6 +4,7 @@
using System.Collections.Specialized;
using System.Linq;
using Perspex.Controls.Presenters;
using Perspex.LogicalTree;
using Xunit;
namespace Perspex.Controls.UnitTests
@ -29,11 +30,28 @@ namespace Perspex.Controls.UnitTests
var child = new Control();
target.Content = child;
target.ApplyTemplate();
target.Content = null;
target.ApplyTemplate();
Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
}
[Fact]
public void Clearing_Content_Clear_Childs_Parent()
{
var target = new ContentPresenter();
var child = new Control();
target.Content = child;
target.ApplyTemplate();
target.Content = null;
target.ApplyTemplate();
Assert.Null(child.Parent);
Assert.Null(child.GetLogicalParent());
}
[Fact]
public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{

6
tests/Perspex.Controls.UnitTests/Utils/HotKeyManagerTests.cs

@ -43,11 +43,13 @@ namespace Perspex.Controls.UnitTests.Utils
HotKeyManager.SetHotKey(button, gesture2);
Assert.Equal(gesture2, tl.KeyBindings[0].Gesture);
button.SetValue(Control.ParentProperty, null);
tl.Content = null;
tl.Presenter.ApplyTemplate();
Assert.Empty(tl.KeyBindings);
button.SetValue(Control.ParentProperty, tl);
tl.Content = button;
tl.Presenter.ApplyTemplate();
Assert.Equal(gesture2, tl.KeyBindings[0].Gesture);

Loading…
Cancel
Save