mirror of https://github.com/AMT-Cheif/Stylet.git
Start writing unit tests for Screen
This commit is contained in:
parent
3247acfde9
commit
20509d9c77
|
@ -43,6 +43,13 @@ namespace Stylet
|
||||||
this.CloseItem(this.ActiveItem);
|
this.CloseItem(this.ActiveItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
foreach (var item in this.history)
|
||||||
|
this.CloseAndCleanUp(item);
|
||||||
|
this.history.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public override async void CloseItem(T item)
|
public override async void CloseItem(T item)
|
||||||
{
|
{
|
||||||
if (item == null || !await this.CanCloseItem(item))
|
if (item == null || !await this.CanCloseItem(item))
|
||||||
|
@ -60,6 +67,7 @@ namespace Stylet
|
||||||
}
|
}
|
||||||
else if (this.history.Contains(item))
|
else if (this.history.Contains(item))
|
||||||
{
|
{
|
||||||
|
this.CloseAndCleanUp(item);
|
||||||
this.history.Remove(item);
|
this.history.Remove(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,201 @@
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Stylet;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace StyletUnitTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ScreenTests
|
||||||
|
{
|
||||||
|
private class MyScreen : Screen
|
||||||
|
{
|
||||||
|
public bool OnActivateCalled;
|
||||||
|
protected override void OnActivate()
|
||||||
|
{
|
||||||
|
this.OnActivateCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnInitialActivateCalled;
|
||||||
|
protected override void OnInitialActivate()
|
||||||
|
{
|
||||||
|
this.OnInitialActivateCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnDeactivateCalled;
|
||||||
|
protected override void OnDeactivate()
|
||||||
|
{
|
||||||
|
this.OnDeactivateCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnCloseCalled;
|
||||||
|
protected override void OnClose()
|
||||||
|
{
|
||||||
|
this.OnCloseCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnViewLoadedCalled;
|
||||||
|
protected override void OnViewLoaded()
|
||||||
|
{
|
||||||
|
this.OnViewLoadedCalled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MyScreen screen;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
this.screen = new MyScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SettingDisplayNameNotifies()
|
||||||
|
{
|
||||||
|
string changedProperty = null;
|
||||||
|
this.screen.PropertyChanged += (o, e) => changedProperty = e.PropertyName;
|
||||||
|
|
||||||
|
this.screen.DisplayName = "test";
|
||||||
|
|
||||||
|
Assert.AreEqual("test", this.screen.DisplayName);
|
||||||
|
Assert.AreEqual("DisplayName", changedProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ScreenIsInitiallyNotActive()
|
||||||
|
{
|
||||||
|
Assert.IsFalse(this.screen.IsActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ActivateActivatesIfNotAlreadyActive()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
Assert.IsTrue(this.screen.IsActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ActivateFiresActivatedEvent()
|
||||||
|
{
|
||||||
|
bool fired = false;
|
||||||
|
this.screen.Activated += (o, e) => fired = true;
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
Assert.IsTrue(fired);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ActivateCallsOnActivate()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
Assert.IsTrue(this.screen.OnActivateCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DoubleActivationDoesntActivate()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
this.screen.OnActivateCalled = false;
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
Assert.IsFalse(this.screen.OnActivateCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void InitialActivationCallsOnInitialActivate()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
this.screen.OnInitialActivateCalled = false;
|
||||||
|
((IDeactivate)this.screen).Deactivate();
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
Assert.IsFalse(this.screen.OnInitialActivateCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DeactivateDeactivates()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate(); ;
|
||||||
|
((IDeactivate)this.screen).Deactivate();
|
||||||
|
Assert.IsFalse(this.screen.IsActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DeactivateFiredDeactivatedEvent()
|
||||||
|
{
|
||||||
|
bool fired = false;
|
||||||
|
this.screen.Deactivated += (o, e) => fired = true;
|
||||||
|
((IActivate)this.screen).Activate(); ;
|
||||||
|
((IDeactivate)this.screen).Deactivate();
|
||||||
|
Assert.IsTrue(fired);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DeactivateCallsOnDeactivate()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
((IDeactivate)this.screen).Deactivate();
|
||||||
|
Assert.IsTrue(this.screen.OnDeactivateCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DoubleDeactivationDoesntDeactivate()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
((IDeactivate)this.screen).Deactivate();
|
||||||
|
this.screen.OnDeactivateCalled = false;
|
||||||
|
((IDeactivate)this.screen).Deactivate();
|
||||||
|
Assert.IsFalse(this.screen.OnDeactivateCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CloseDeactivates()
|
||||||
|
{
|
||||||
|
((IActivate)this.screen).Activate();
|
||||||
|
((IClose)this.screen).Close();
|
||||||
|
Assert.IsTrue(this.screen.OnDeactivateCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CloseClearsView()
|
||||||
|
{
|
||||||
|
((IViewAware)this.screen).AttachView(new UIElement());
|
||||||
|
((IClose)this.screen).Close();
|
||||||
|
Assert.IsNull(this.screen.View);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CloseFiresClosed()
|
||||||
|
{
|
||||||
|
bool fired = false;
|
||||||
|
this.screen.Closed += (o, e) => fired = true;
|
||||||
|
((IClose)this.screen).Close();
|
||||||
|
Assert.IsTrue(fired);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CloseCallsOnClose()
|
||||||
|
{
|
||||||
|
((IClose)this.screen).Close();
|
||||||
|
Assert.IsTrue(this.screen.OnCloseCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AttachViewAttachesView()
|
||||||
|
{
|
||||||
|
var view = new UIElement();
|
||||||
|
((IViewAware)this.screen).AttachView(view);
|
||||||
|
Assert.AreEqual(view, this.screen.View);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AttachViewThrowsIfViewAlreadyAttached()
|
||||||
|
{
|
||||||
|
var view = new UIElement();
|
||||||
|
((IViewAware)this.screen).AttachView(view);
|
||||||
|
Assert.Throws<Exception>(() => ((IViewAware)this.screen).AttachView(view));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -61,6 +61,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="PropertyChangedBaseTests.cs" />
|
<Compile Include="PropertyChangedBaseTests.cs" />
|
||||||
<Compile Include="PropertyChangedExtensionsTests.cs" />
|
<Compile Include="PropertyChangedExtensionsTests.cs" />
|
||||||
|
<Compile Include="ScreenTests.cs" />
|
||||||
<Compile Include="StyletIoC\StyletIoCAutobindingTests.cs" />
|
<Compile Include="StyletIoC\StyletIoCAutobindingTests.cs" />
|
||||||
<Compile Include="StyletIoC\StyletIoCBindingChecksTests.cs" />
|
<Compile Include="StyletIoC\StyletIoCBindingChecksTests.cs" />
|
||||||
<Compile Include="StyletIoC\StyletIoCPropertyInjectionTests.cs" />
|
<Compile Include="StyletIoC\StyletIoCPropertyInjectionTests.cs" />
|
||||||
|
|
Loading…
Reference in New Issue