示例#1
0
        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());
        }
示例#2
0
        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());
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }