mirror of https://github.com/AMT-Cheif/Stylet.git
Start on unit testing WindowManager, but there's not a lot I can do since Window is so hard to mock
This commit is contained in:
parent
6aacfa87f4
commit
8106e6a3ac
|
@ -35,7 +35,7 @@ namespace Stylet
|
|||
var view = viewManager.LocateViewForModel(viewModel);
|
||||
var window = view as Window;
|
||||
if (window == null)
|
||||
throw new Exception(String.Format("Tried to show {0} as a window, but it isn't a Window", view.GetType().Name));
|
||||
throw new Exception(String.Format("Tried to show {0} as a window, but it isn't a Window", view == null ? "(null)" : view.GetType().Name));
|
||||
|
||||
viewManager.BindViewToModel(window, viewModel);
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
<Compile Include="StyletIoC\StyletIoCGetSingleKeyedTests.cs" />
|
||||
<Compile Include="StyletIoC\StyletIoCGetSingleTests.cs" />
|
||||
<Compile Include="StyletIoC\StyletIoCUnboundGenericTests.cs" />
|
||||
<Compile Include="WindowManagerTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
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, RequiresSTA]
|
||||
public class WindowManagerTests
|
||||
{
|
||||
private Mock<IViewManager> viewManager;
|
||||
private WindowManager windowManager;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
this.viewManager = new Mock<IViewManager>();
|
||||
this.windowManager = new WindowManager();
|
||||
|
||||
IoC.GetInstance = (service, key) => this.viewManager.Object;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowWindowAsksViewManagerForView()
|
||||
{
|
||||
var model = new object();
|
||||
this.viewManager.Setup(x => x.LocateViewForModel(model)).Verifiable();
|
||||
// Don't care if this throws - that's OK
|
||||
try { this.windowManager.ShowWindow(model); }
|
||||
catch (Exception) { }
|
||||
this.viewManager.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowWindowThrowsIfViewIsntAWindow()
|
||||
{
|
||||
var model = new object();
|
||||
this.viewManager.Setup(x => x.LocateViewForModel(model)).Returns(new UIElement());
|
||||
Assert.Throws<Exception>(() => this.windowManager.ShowWindow(model));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue