예제 #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);
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();

            ViewPlacer = new ViewPlacer(this, MainTabControl);

            ComponentContainer.Container.Register(Component.For<IViewPlacer>().Instance(ViewPlacer));

            ViewController = ComponentContainer.Container.Resolve<ViewController>();
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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>());
        }