public void WhenRoutedToViewModelItShouldAddViewToControls() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var router = new RoutingState(); var target = new WinFormsRoutedViewHost { Router = router, ViewLocator = viewLocator }; router.Navigate.Execute(new FakeWinformViewModel()); Assert.Equal(1, target.Controls.OfType<FakeWinformsView>().Count()); }
public void WhenRoutedToViewModelItShouldAddViewToControls() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var router = new RoutingState(); var target = new WinFormsRoutedViewHost { Router = router, ViewLocator = viewLocator }; router.Navigate.Execute(new FakeWinformViewModel()); Assert.Equal(1, target.Controls.OfType <FakeWinformsView>().Count()); }
public void ShouldSetDefaultContentWhenViewModelIsNull() { var defaultContent = new Control(); var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var router = new RoutingState(); var target = new WinFormsRoutedViewHost { Router = router, ViewLocator = viewLocator, DefaultContent = defaultContent }; Assert.True(target.Controls.Contains(defaultContent)); }
public void ShouldDisposePreviousView() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var router = new RoutingState(); var target = new WinFormsRoutedViewHost { Router = router, ViewLocator = viewLocator }; router.Navigate.Execute(new FakeWinformViewModel()); FakeWinformsView currentView = target.Controls.OfType<FakeWinformsView>().Single(); bool isDisposed = false; currentView.Disposed += (o, e) => isDisposed = true; // switch the viewmodel router.Navigate.Execute(new FakeWinformViewModel()); Assert.True(isDisposed); }
public void ShouldDisposePreviousView() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var router = new RoutingState(); var target = new WinFormsRoutedViewHost { Router = router, ViewLocator = viewLocator }; router.Navigate.Execute(new FakeWinformViewModel()); FakeWinformsView currentView = target.Controls.OfType <FakeWinformsView>().Single(); bool isDisposed = false; currentView.Disposed += (o, e) => isDisposed = true; // switch the viewmodel router.Navigate.Execute(new FakeWinformViewModel()); Assert.True(isDisposed); }