Exemplo n.º 1
1
        public void CloseExists()
        {
            CreateContainerWithRealMessageBus();

            var title = Guid.NewGuid().ToString();

            var viewModel = Substitute.For<ITitledViewModel>();
            viewModel.Title.Returns(title);

            var view = new FrameworkElement();
            view.DataContext = viewModel;
            var viewTarget = ViewTargets.DefaultView;

            var viewResult = new ViewResult(view, viewTarget);
            var viewBuilder = Substitute.For<IViewFactory>();
            viewBuilder.Build(Arg.Any<ViewTargets>(), Arg.Any<Object>())
                .Returns(viewResult);
            ComponentContainer.Container.Register(Component.For<IViewFactory>().Instance(viewBuilder));

            var window = new Window();
            var tabControl = new TabControl();
            var viewController = new ViewPlacer(window, tabControl);
            var newTabItem = new TabItem() { Header = title };
            tabControl.Items.Add(newTabItem);

            var message = new CloseViewMessage(title);
            _MessageBus.Publish<CloseViewMessage>(message);

            Assert.AreEqual(0, tabControl.Items.Count);
        }
Exemplo n.º 2
0
        public void PlaceView(ViewResult viewResult)
        {
            if (viewResult.ViewTarget == MoviesViewTargets.AdvancedSearch)
            {
                ModalViewPlacer.PlaceView(viewResult);
            }
            else
            {
                var exists = false;
                var title = GetTitleFromViewModel(viewResult.View.DataContext);
                foreach (TabItem tabItem in MainTabControl.Items)
                {
                    if (tabItem.Header.ToString() == title)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    var newTabItem = new TabItem() { Header = title, Content = viewResult.View };
                    MainTabControl.Items.Add(newTabItem);

                    newTabItem.Focus();
                }
            }
        }
Exemplo n.º 3
0
        public void Create()
        {
            var view = new FrameworkElement();

            var viewResult = new ViewResult(view, ViewTargets.DefaultView);

            Assert.AreSame(view, viewResult.View);
            Assert.AreEqual(ViewTargets.DefaultView, viewResult.ViewTarget);
        }
        public void PlaceView_ThrowsExceptionWithBadView()
        {
            var appWindow = new Window();
            var messageBus = Substitute.For<IMessageBus>();

            var view = new FrameworkElement();
            var viewResult = new ViewResult(view, ViewTargets.DefaultView);

            var viewPlacer = new ModalViewPlacer(appWindow, messageBus);

            viewPlacer.PlaceView(viewResult);
        }
        public void ShowView()
        {
            var view = new FrameworkElement();
            var viewController = GetViewController(false);

            var viewResult = new ViewResult(view, ViewTargets.DefaultView);
            _viewFactory.Build(Arg.Any<ViewTargets>(), Arg.Any<Object>())
                .Returns(viewResult);

            var message = new ShowViewMessage(ViewTargets.DefaultView);
            _messageBus.Publish<ShowViewMessage>(message);

            _viewPlacer.Received().PlaceView(viewResult);
        }
        public void PlaceView()
        {
            var appWindow = new Window();
            var messageBus = Substitute.For<IMessageBus>();

            var viewModel = Substitute.For<IModalViewModel>();
            var view = new MockModalView();
            view.DataContext = viewModel;

            var viewResult = new ViewResult(view, ViewTargets.DefaultView);

            var viewPlacer = new ModalViewPlacer(appWindow, messageBus);

            viewPlacer.PlaceView(viewResult);

            Assert.IsTrue(view.ShowModalCalled);
            messageBus.Received().Publish<ModalViewClosedMessage>(Arg.Any<ModalViewClosedMessage>());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Places a view into the user interface.
        /// </summary>
        /// <param name="viewResult">
        /// The <see cref="ViewResult"/> containing the view to be placed.
        /// </param>
        public void PlaceView(ViewResult viewResult)
        {
            var view = viewResult.View as IModalView;
            if (view != null)
            {
                var modalViewModel = viewResult.View.DataContext as IModalViewModel;
                if (modalViewModel != null)
                {
                    modalViewModel.RequestClose += view.OnRequestClose;
                }

                view.Owner = AppWindow;
                view.ShowModal();

                var closedMessage = new ModalViewClosedMessage(viewResult.ViewTarget, view.Accepted, view.ViewResult);
                MessageBus.Publish<ModalViewClosedMessage>(closedMessage);
            }
            else
            {
                throw new ArgumentException("Views must implement IModalView.");
            }
        }
Exemplo n.º 8
0
        public void ShowView()
        {
            CreateContainer();

            var title = Guid.NewGuid().ToString();

            var viewModel = Substitute.For<ITitledViewModel>();
            viewModel.Title.Returns(title);

            var view = new FrameworkElement();
            view.DataContext = viewModel;
            var viewTarget = ViewTargets.DefaultView;

            var viewResult = new ViewResult(view, viewTarget);

            var window = new Window();
            var tabControl = new TabControl();
            var viewPlacer = new ViewPlacer(window, tabControl);

            viewPlacer.PlaceView(viewResult);

            var viewFound = false;
            foreach (TabItem tabItem in tabControl.Items)
            {
                if (tabItem.Header.ToString() == title)
                {
                    viewFound = true;
                }
            }

            Assert.IsTrue(viewFound);
        }
Exemplo n.º 9
0
        public void ShowView_InvalidViewModel()
        {
            CreateContainer();

            var viewModel = new object();

            var view = new FrameworkElement();
            view.DataContext = viewModel;
            var viewTarget = ViewTargets.DefaultView;

            var viewResult = new ViewResult(view, viewTarget);

            var window = new Window();
            var tabControl = new TabControl();
            var viewPlacer = new ViewPlacer(window, tabControl);

            viewPlacer.PlaceView(viewResult);
        }
Exemplo n.º 10
0
        public void ShowView_AdvancedSearch()
        {
            CreateContainer();

            var title = Guid.NewGuid().ToString();

            var viewModel = Substitute.For<IModalViewModel>();

            var view = new MockModalView();
            view.DataContext = viewModel;
            var viewTarget = MoviesViewTargets.AdvancedSearch;

            var viewResult = new ViewResult(view, viewTarget);

            var window = new Window();
            var tabControl = new TabControl();
            var viewPlacer = new ViewPlacer(window, tabControl);

            viewPlacer.PlaceView(viewResult);

            Assert.IsTrue(view.ShowModalCalled);
            _MessageBus.Received().Publish<ModalViewClosedMessage>(Arg.Any<ModalViewClosedMessage>());
        }
Exemplo n.º 11
0
        public void ShowViewDoNotDisplay()
        {
            var view = new FrameworkElement();
            var viewController = GetViewController(true);

            var viewResult = new ViewResult(view, ViewTargets.DefaultView);
            _viewFactory.Build(Arg.Any<ViewTargets>(), Arg.Any<Object>())
                .Returns(viewResult);

            _viewAuthorizer.AuthorizeView(Arg.Any<ViewTargets>())
                .Returns(ViewAuthorizations.DoNotDisplay);

            var message = new ShowViewMessage(ViewTargets.DefaultView);
            _messageBus.Publish<ShowViewMessage>(message);

            _viewPlacer.DidNotReceive().PlaceView(viewResult);
        }