Пример #1
0
        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));
        }
Пример #2
0
        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());
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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);
        }