Esempio n. 1
0
        public void CloseDoesNotExist()
        {
            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 = Guid.NewGuid().ToString() };
            tabControl.Items.Add(newTabItem);

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

            Assert.AreEqual(1, tabControl.Items.Count);
        }
Esempio n. 2
0
        public void Close()
        {
            var message = new CloseViewMessage(Title);

            MessageBus.Publish<CloseViewMessage>(message);
        }
Esempio n. 3
0
        private void HandleCloseView(CloseViewMessage args)
        {
            TabItem openTabItem = null;
            foreach (TabItem tabItem in MainTabControl.Items)
            {
                if (tabItem.Header.ToString() == args.ViewName)
                {
                    openTabItem = tabItem;
                    break;
                }
            }

            if (openTabItem != null)
            {
                MainTabControl.Items.Remove(openTabItem);
            }
        }