From 7ef6d6521a07113404e587e732bd974e5cff180c Mon Sep 17 00:00:00 2001 From: Antony Male Date: Wed, 12 Mar 2014 21:51:36 +0000 Subject: [PATCH] Start writing unit tests for Conductor --- StyletUnitTests/ConductorTests.cs | 88 ++++++++++++++++++++++++++ StyletUnitTests/StyletUnitTests.csproj | 2 +- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 StyletUnitTests/ConductorTests.cs diff --git a/StyletUnitTests/ConductorTests.cs b/StyletUnitTests/ConductorTests.cs new file mode 100644 index 0000000..41625d0 --- /dev/null +++ b/StyletUnitTests/ConductorTests.cs @@ -0,0 +1,88 @@ +using Moq; +using NUnit.Framework; +using Stylet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StyletUnitTests +{ + [TestFixture] + public class ConductorTests + { + private Conductor conductor; + + [SetUp] + public void SetUp() + { + this.conductor = new Conductor(); + } + + [Test] + public void ActiveItemIsNullBeforeAnyItemsActivated() + { + Assert.IsNull(this.conductor.ActiveItem); + Assert.That(this.conductor.GetChildren(), Is.EquivalentTo(new IScreen[] { null })); + } + + [Test] + public void InitialActivateSetsItemAsActiveItem() + { + var screen = new Mock(); + this.conductor.ActivateItem(screen.Object); + Assert.AreEqual(screen.Object, this.conductor.ActiveItem); + } + + [Test] + public void InitialActivateDoesNotActivateItemIfConductorIsNotActive() + { + var screen = new Mock(); + this.conductor.ActivateItem(screen.Object); + screen.Verify(x => x.Activate(), Times.Never); + } + + [Test] + public void InitialActivateActivatesItemIfConductorIsActive() + { + ((IActivate)this.conductor).Activate(); + var screen = new Mock(); + this.conductor.ActivateItem(screen.Object); + screen.Verify(x => x.Activate()); + } + + [Test] + public void ActivatesActiveItemWhenActivated() + { + var screen = new Mock(); + this.conductor.ActivateItem(screen.Object); + screen.Verify(x => x.Activate(), Times.Never); + + ((IActivate)this.conductor).Activate(); + screen.Verify(x => x.Activate()); + } + + [Test] + public void DeactivatesActiveItemWhenDeactivated() + { + ((IActivate)this.conductor).Activate(); + var screen = new Mock(); + this.conductor.ActivateItem(screen.Object); + ((IDeactivate)this.conductor).Deactivate(false); + screen.Verify(x => x.Deactivate(false)); + } + + [Test] + public void ActivateDeactivatesPreviousItemIfConductorIsActiveAndPreviousItemCanClose() + { + var screen1 = new Mock(); + var screen2 = new Mock(); + ((IActivate)this.conductor).Activate(); + this.conductor.ActivateItem(screen1.Object); + screen1.Setup(x => x.CanCloseAsync()).Returns(Task.FromResult(true)); + this.conductor.ActivateItem(screen2.Object); + screen1.Verify(x => x.Deactivate(true)); + } + } +} diff --git a/StyletUnitTests/StyletUnitTests.csproj b/StyletUnitTests/StyletUnitTests.csproj index 072c257..6beaf9d 100644 --- a/StyletUnitTests/StyletUnitTests.csproj +++ b/StyletUnitTests/StyletUnitTests.csproj @@ -53,7 +53,7 @@ - +