mirror of https://github.com/AMT-Cheif/Stylet.git
Finish off having conductors with collections respond property to that collection being manipulated
This commit is contained in:
parent
d0ce17ec17
commit
6a1e8e688e
|
@ -31,25 +31,37 @@ namespace Stylet
|
|||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
this.SetParent(e.NewItems, true);
|
||||
this.ActivateAndSetParent(e.NewItems);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
this.SetParent(e.OldItems, false);
|
||||
this.CloseAndCleanUp(e.OldItems);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Replace:
|
||||
this.SetParent(e.NewItems, true);
|
||||
this.SetParent(e.OldItems, false);
|
||||
this.ActivateAndSetParent(e.NewItems);
|
||||
this.CloseAndCleanUp(e.OldItems);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Reset:
|
||||
this.SetParent(this.items, true);
|
||||
this.ActivateAndSetParent(this.items);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected virtual void ActivateAndSetParent(IEnumerable items)
|
||||
{
|
||||
this.SetParent(items, true);
|
||||
if (this.IsActive)
|
||||
{
|
||||
foreach (var item in items.OfType<IActivate>())
|
||||
{
|
||||
item.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
foreach (var item in this.items.OfType<IActivate>())
|
||||
|
|
|
@ -99,21 +99,24 @@ namespace StyletUnitTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void AddingItemSetsParent()
|
||||
public void AddingItemActivatesAndSetsParent()
|
||||
{
|
||||
((IActivate)this.conductor).Activate();
|
||||
var screen = new Mock<IScreen>();
|
||||
this.conductor.Items.Add(screen.Object);
|
||||
screen.VerifySet(x => x.Parent = this.conductor);
|
||||
screen.Verify(x => x.Activate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemRemovesParent()
|
||||
public void RemovingItemClosesAndRemovesParent()
|
||||
{
|
||||
var screen = new Mock<IScreen>();
|
||||
screen.SetupGet(x => x.Parent).Returns(this.conductor);
|
||||
this.conductor.Items.Add(screen.Object);
|
||||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.VerifySet(x => x.Parent = null);
|
||||
screen.Verify(x => x.Close());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -164,13 +164,43 @@ namespace StyletUnitTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemRemovesParent()
|
||||
public void AddingItemDoesNotChangeActiveItem()
|
||||
{
|
||||
var screen1 = new Mock<IScreen>();
|
||||
var screen2 = new Mock<IScreen>();
|
||||
this.conductor.ActivateItem(screen1.Object);
|
||||
this.conductor.Items.Add(screen2.Object);
|
||||
|
||||
Assert.AreEqual(this.conductor.ActiveItem, screen1.Object);
|
||||
screen2.Verify(x => x.Activate(), Times.Never);
|
||||
screen1.Verify(x => x.Deactivate(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemClosesAndRemovesParent()
|
||||
{
|
||||
var screen = new Mock<IScreen>();
|
||||
screen.SetupGet(x => x.Parent).Returns(this.conductor);
|
||||
this.conductor.Items.Add(screen.Object);
|
||||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.VerifySet(x => x.Parent = null);
|
||||
screen.Verify(x => x.Close());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingActiveItemActivatesAnotherItem()
|
||||
{
|
||||
((IActivate)this.conductor).Activate();
|
||||
var screen1 = new Mock<IScreen>();
|
||||
var screen2 = new Mock<IScreen>();
|
||||
this.conductor.ActivateItem(screen1.Object);
|
||||
this.conductor.Items.Add(screen2.Object);
|
||||
|
||||
this.conductor.Items.Remove(screen1.Object);
|
||||
|
||||
Assert.AreEqual(this.conductor.ActiveItem, screen2.Object);
|
||||
screen2.Verify(x => x.Activate());
|
||||
screen1.Verify(x => x.Close());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
Loading…
Reference in New Issue