public void ShouldSetDefaultContentWhenViewModelIsNull() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var defaultContent = new Control(); var target = new WinFormsViewModelViewHost { DefaultContent = defaultContent, ViewLocator = viewLocator }; Assert.Equal(target.CurrentView, defaultContent); Assert.True(target.Controls.Contains(defaultContent)); }
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 SettingViewModelShouldAddTheViewtoItsControls() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var target = new WinFormsViewModelViewHost(); target.ViewLocator = viewLocator; target.ViewModel = new FakeWinformViewModel(); Assert.IsType <FakeWinformsView>(target.CurrentView); 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 ShouldNotCacheViewWhenDisabled() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var defaultContent = new Control(); var target = new WinFormsViewModelViewHost { DefaultContent = defaultContent, ViewLocator = viewLocator, CacheViews = false }; target.ViewModel = new FakeWinformViewModel(); var cachedView = target.CurrentView; target.ViewModel = new FakeWinformViewModel(); Assert.False(object.ReferenceEquals(cachedView, target.CurrentView)); }
public void ShouldCacheViewWhenEnabled() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var defaultContent = new Control(); var target = new WinFormsViewModelViewHost { DefaultContent = defaultContent, ViewLocator = viewLocator, CacheViews = true }; target.ViewModel = new FakeWinformViewModel(); var cachedView = target.Content; target.ViewModel = new FakeWinformViewModel(); Assert.True(ReferenceEquals(cachedView, target.Content)); }
public void ShouldDisposePreviousView() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var target = new ViewModelViewHost(); target.ViewLocator = viewLocator; target.ViewModel = new FakeWinformViewModel(); Control currentView = target.CurrentView; bool isDisposed = false; currentView.Disposed += (o, e) => isDisposed = true; // switch the viewmodel target.ViewModel = 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); }
public void ShouldDisposePreviousView() { var viewLocator = new FakeViewLocator { LocatorFunc = t => new FakeWinformsView() }; var target = new WinFormsViewModelViewHost { CacheViews = false }; target.ViewLocator = viewLocator; target.ViewModel = new FakeWinformViewModel(); var currentView = target.CurrentView; var isDisposed = false; currentView !.Disposed += (o, e) => isDisposed = true; // switch the viewmodel target.ViewModel = new FakeWinformViewModel(); Assert.True(isDisposed); }