Yes, I would just modify my Bootstrapper a bit to help with testing:
public class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
base.InitializeShell();
Window app_window = Shell as Window;
if((app_window != null) && (Application.Current != null))
{
Application.Current.MainWindow = app_window;
Application.Current.MainWindow.Show();
}
}
protected override void ConfigureModuleCatalog()
{
ModuleCatalog moduleCatalog = (ModuleCatalog)ModuleCatalog;
moduleCatalog.AddModule(typeof(MainShellModule));
}
}
Then you could make your unit test look like this:
[TestFixture, RequiresSTA]
public class BootstrapperTest
{
Bootstrapper b;
[TestFixtureSetUp]
public void FixtureSetup()
{
b = new Bootstrapper();
b.Run();
}
[Test]
public void ShellInitialization()
{
Assert.That(b.Container, Is.Not.Null);
}
[Test]
public void ShellModuleCatalog()
{
IModuleCatalog mod = ServiceLocator.Current.TryResolve<IModuleCatalog>();
Assert.That(mod, Is.Not.Null);
}
}
source
share