using Moq; using NUnit.Framework; using Stylet; using Stylet.Xaml; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; namespace StyletUnitTests { [TestFixture, RequiresSTA] public class BootstrapperBaseTests { private class RootViewModel { } private class MyBootstrapperBase : BootstrapperBase where T : class { private IViewManager viewManager; private IWindowManager windowManager; public MyBootstrapperBase(IViewManager viewManager, IWindowManager windowManager) { this.viewManager = viewManager; this.windowManager = windowManager; this.Start(); } public new Application Application { get { return base.Application; } } public bool GetInstanceCalled; public override object GetInstance(Type service) { this.GetInstanceCalled = true; if (service == typeof(IViewManager)) return this.viewManager; if (service == typeof(IWindowManager)) return this.windowManager; if (service == typeof(RootViewModel)) return new RootViewModel(); return null; } public bool OnExitCalled; protected override void OnApplicationExit(object sender, ExitEventArgs e) { this.OnExitCalled = true; } public bool ConfigureCalled; protected override void ConfigureBootstrapper() { this.ConfigureCalled = true; base.ConfigureBootstrapper(); } public new void Start() { base.Start(); } } private MyBootstrapperBase bootstrapper; private Mock viewManager; private Mock windowManager; [TestFixtureSetUp] public void FixtureSetUp() { Execute.TestExecuteSynchronously = true; } [SetUp] public void SetUp() { this.viewManager = new Mock(); this.windowManager = new Mock(); this.bootstrapper = new MyBootstrapperBase(this.viewManager.Object, this.windowManager.Object); } [Test] public void StartAssignsExecuteDispatcher() { Execute.Dispatcher = null; this.bootstrapper.Start(); Assert.NotNull(Execute.Dispatcher); // Can't test any further, unfortunately } [Test] public void StartCallsConfigure() { this.bootstrapper.Start(); Assert.True(this.bootstrapper.ConfigureCalled); } [Test] public void StartAssignsViewManager() { this.bootstrapper.Start(); Assert.AreEqual(View.ViewManager, this.viewManager.Object); } } }