mirror of https://github.com/AMT-Cheif/Stylet.git
Add tests for new conductor Dispose behaviour
This commit is contained in:
parent
c0562205de
commit
46dc485eee
|
@ -46,7 +46,15 @@ namespace StyletUnitTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void ActivateItemDoesActiveIfConductorIsActive()
|
||||
public void ActivateItemDeactivatesIfConductorIsNotActive()
|
||||
{
|
||||
var screen = new Mock<IScreen>();
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
screen.Verify(x => x.Deactivate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActivateItemActivatesfConductorIsActive()
|
||||
{
|
||||
var screen = new Mock<IScreen>();
|
||||
((IActivate)this.conductor).Activate();
|
||||
|
@ -54,6 +62,15 @@ namespace StyletUnitTests
|
|||
screen.Verify(x => x.Activate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActivateItemDoesNotDeactivateIfConductorIsActive()
|
||||
{
|
||||
var screen = new Mock<IScreen>();
|
||||
((IActivate)this.conductor).Activate();
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
screen.Verify(x => x.Deactivate(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeactiveDeactivatesItems()
|
||||
{
|
||||
|
@ -113,7 +130,7 @@ namespace StyletUnitTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemClosesAndDisposesAndRemovesParent()
|
||||
public void RemovingItemClosesAndRemovesParent()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
screen.SetupGet(x => x.Parent).Returns(this.conductor);
|
||||
|
@ -121,9 +138,27 @@ namespace StyletUnitTests
|
|||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.VerifySet(x => x.Parent = null);
|
||||
screen.Verify(x => x.Close());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemDisposesIfDisposeChildrenIsTrue()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
this.conductor.Items.Add(screen.Object);
|
||||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.Verify(x => x.Dispose());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemDoesNotDisposeIfDisposeChildrenIsFalse()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
this.conductor.DisposeChildren = false;
|
||||
this.conductor.Items.Add(screen.Object);
|
||||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.Verify(x => x.Dispose(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddingItemTwiceDoesNotResultInDuplicates()
|
||||
{
|
||||
|
|
|
@ -55,6 +55,14 @@ namespace StyletUnitTests
|
|||
screen.Verify(x => x.Activate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitialActivateDeactivatesItemIfConductorIsDeactivated()
|
||||
{
|
||||
var screen = new Mock<IScreen>();
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
screen.Verify(x => x.Deactivate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActivatesActiveItemWhenActivated()
|
||||
{
|
||||
|
@ -144,17 +152,38 @@ namespace StyletUnitTests
|
|||
Assert.AreEqual(this.conductor.ActiveItem, screen.Object);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CloseRemovesItemsParent()
|
||||
public void CloseClosesAndRemovesItemsParent()
|
||||
{
|
||||
var screen = new Mock<IScreen>();
|
||||
screen.Setup(x => x.CanCloseAsync()).Returns(Task.FromResult(true));
|
||||
screen.Setup(x => x.Parent).Returns(this.conductor);
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
this.conductor.CloseItem(screen.Object);
|
||||
screen.Verify(x => x.Close());
|
||||
screen.VerifySet(x => x.Parent = null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CloseDisposesItemIfDisposeChildrenIsTrue()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
screen.Setup(x => x.CanCloseAsync()).Returns(Task.FromResult(true));
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
this.conductor.CloseItem(screen.Object);
|
||||
screen.Verify(x => x.Dispose());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CloseDoesNotDisposeItemIfDisposeChildrenIsFalse()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
screen.Setup(x => x.CanCloseAsync()).Returns(Task.FromResult(true));
|
||||
this.conductor.DisposeChildren = false;
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
this.conductor.CloseItem(screen.Object);
|
||||
screen.Verify(x => x.Dispose(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanCloseReturnsTrueIfNoActiveItem()
|
||||
|
@ -221,10 +250,8 @@ namespace StyletUnitTests
|
|||
|
||||
((IClose)this.conductor).Close();
|
||||
screen1.Verify(x => x.Close());
|
||||
screen1.Verify(x => x.Dispose());
|
||||
screen1.VerifySet(x => x.Parent = null);
|
||||
screen2.Verify(x => x.Close());
|
||||
screen2.Verify(x => x.Dispose());
|
||||
screen2.VerifySet(x => x.Parent = null);
|
||||
}
|
||||
|
||||
|
@ -237,7 +264,6 @@ namespace StyletUnitTests
|
|||
((IChildDelegate)this.conductor).CloseItem(screen.Object);
|
||||
|
||||
screen.Verify(x => x.Close());
|
||||
screen.Verify(x => x.Dispose());
|
||||
Assert.Null(this.conductor.ActiveItem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,6 +182,7 @@ namespace StyletUnitTests
|
|||
{
|
||||
var screen1 = new Mock<IScreen>();
|
||||
var screen2 = new Mock<IScreen>();
|
||||
((IActivate)this.conductor).Activate();
|
||||
this.conductor.ActivateItem(screen1.Object);
|
||||
this.conductor.Items.Add(screen2.Object);
|
||||
|
||||
|
@ -199,9 +200,27 @@ namespace StyletUnitTests
|
|||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.VerifySet(x => x.Parent = null);
|
||||
screen.Verify(x => x.Close());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemDisposesIfDisposeChildrenIsTrue()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
this.conductor.Items.Add(screen.Object);
|
||||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.Verify(x => x.Dispose());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingItemDoesNotDisposeIfDisposeChildrenIsFalse()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
this.conductor.DisposeChildren = false;
|
||||
this.conductor.Items.Add(screen.Object);
|
||||
this.conductor.Items.Remove(screen.Object);
|
||||
screen.Verify(x => x.Dispose(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemovingActiveItemActivatesAnotherItem()
|
||||
{
|
||||
|
@ -216,7 +235,6 @@ namespace StyletUnitTests
|
|||
Assert.AreEqual(this.conductor.ActiveItem, screen2.Object);
|
||||
screen2.Verify(x => x.Activate());
|
||||
screen1.Verify(x => x.Close());
|
||||
screen1.Verify(x => x.Dispose());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -257,10 +275,30 @@ namespace StyletUnitTests
|
|||
this.conductor.ActivateItem(screen.Object);
|
||||
this.conductor.CloseItem(screen.Object);
|
||||
screen.Verify(x => x.Close());
|
||||
screen.Verify(x => x.Dispose());
|
||||
Assert.AreEqual(0, this.conductor.Items.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CloseItemDisposesIfDisposeChildrenIsTrue()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
screen.Setup(x => x.CanCloseAsync()).Returns(Task.FromResult(true));
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
this.conductor.CloseItem(screen.Object);
|
||||
screen.Verify(x => x.Dispose());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CloseItemDoesNotDisposeIfDisposeChildrenIsFalse()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
this.conductor.DisposeChildren = false;
|
||||
screen.Setup(x => x.CanCloseAsync()).Returns(Task.FromResult(true));
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
this.conductor.CloseItem(screen.Object);
|
||||
screen.Verify(x => x.Dispose(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClosingConductorClosesActiveItem()
|
||||
{
|
||||
|
|
|
@ -194,10 +194,28 @@ namespace StyletUnitTests
|
|||
this.conductor.ActivateItem(screen1.Object);
|
||||
((IClose)this.conductor).Close();
|
||||
screen1.Verify(x => x.Close());
|
||||
screen1.Verify(x => x.Dispose());
|
||||
screen1.VerifySet(x => x.Parent = null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClosingConductorDisposesActiveItemIfDisposeChildrenIsTrue()
|
||||
{
|
||||
var screen = new Mock<IMyScreen>();
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
((IClose)this.conductor).Close();
|
||||
screen.Verify(x => x.Dispose());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClosingConductorDoesNotDisposeActiveItemIfDisposeChildrenIsFalse()
|
||||
{
|
||||
this.conductor.DisposeChildren = false;
|
||||
var screen = new Mock<IMyScreen>();
|
||||
this.conductor.ActivateItem(screen.Object);
|
||||
((IClose)this.conductor).Close();
|
||||
screen.Verify(x => x.Dispose(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClosesItemIfItemRequestsClose()
|
||||
{
|
||||
|
|
|
@ -102,7 +102,6 @@ namespace StyletUnitTests
|
|||
this.child.Object.ConductWith(this.parent);
|
||||
((IClose)this.parent).Close();
|
||||
this.child.Verify(x => x.Close());
|
||||
this.child.Verify(x => x.Dispose());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -223,10 +223,8 @@ namespace StyletUnitTests
|
|||
model.Setup(x => x.CanCloseAsync()).Returns(tcs.Task);
|
||||
window.OnClosing(new CancelEventArgs());
|
||||
model.Verify(x => x.Close(), Times.Never);
|
||||
model.Verify(x => x.Dispose(), Times.Never);
|
||||
tcs.SetResult(true);
|
||||
model.Verify(x => x.Close(), Times.Once);
|
||||
model.Verify(x => x.Dispose(), Times.Once);
|
||||
|
||||
Assert.True(window.OnClosedCalled);
|
||||
|
||||
|
@ -272,7 +270,6 @@ namespace StyletUnitTests
|
|||
((IChildDelegate)parent).CloseItem(model.Object);
|
||||
|
||||
model.Verify(x => x.Close());
|
||||
model.Verify(x => x.Dispose());
|
||||
Assert.True(window.OnClosedCalled);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue