Ejemplo n.º 1
0
 public the_ribbon_factory()
 {
     viewProvider = Substitute.For<IViewProvider<TestRibbonTypes>>();
     viewModelFactory = new TestViewModelFactory();
     ribbonFactoryUnderTest = new TestRibbonFactory(
         viewModelFactory,
         () => Substitute.For<CustomTaskPaneCollection>(),
         viewProvider,
         new TestContextProvider(),
         Assembly.GetExecutingAssembly());
 }
 public the_ribbon_factory()
 {
     viewProvider = Substitute.For<IViewProvider>();
     viewModelFactory = new TestViewModelFactory();
     testAddInBase = AddInBaseFactory.Create();
     if (Core.RibbonFactory.RibbonFactory.Current == null)
     {
         ribbonFactoryUnderTest = new TestRibbonFactory(
         testAddInBase,
         viewProvider,
         new TestContextProvider(),
         "Foo",
         Assembly.GetExecutingAssembly())
         {
             ViewModelFactory = viewModelFactory
         };
     }
     else
     {
         ribbonFactoryUnderTest = (TestRibbonFactory)Core.RibbonFactory.RibbonFactory.Current;
     }
 }
Ejemplo n.º 3
0
        public void new_window_with_different_context_does_not_create_new_viewmodel()
        {
            // arrange
            ribbonFactoryUnderTest.ClearCurrent();
            var ribbonFactory = new TestRibbonFactory(viewModelFactory,
                () => Substitute.For<CustomTaskPaneCollection>(),
                viewProvider, new TestContextProvider(), Assembly.GetExecutingAssembly());
            ribbonFactory.SetApplication(null, AddInBaseFactory.Create());
            //Open new view to create a viewmodel for view
            var viewInstance = new TestWindow { Context = new TestWindowContext() };
            var view2Instance = new TestWindow { Context = new TestWindowContext() };

            // act

            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs<TestRibbonTypes>(
                                                                        viewInstance, viewInstance.Context,
                                                                        TestRibbonTypes.RibbonType1));
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs<TestRibbonTypes>(
                                                                        view2Instance, view2Instance.Context,
                                                                        TestRibbonTypes.RibbonType1));

            // assert
            Assert.Equal(2, viewModelFactory.ViewModels.Count);
        }
Ejemplo n.º 4
0
        public void ribbon_factory_calls_back_to_correct_view_model()
        {
            // arrange
            ribbonFactoryUnderTest.ClearCurrent();
            var ribbonFactory = new TestRibbonFactory(
                viewModelFactory,
                () => Substitute.For<CustomTaskPaneCollection>(),
                viewProvider,
                new TestContextProvider(), Assembly.GetExecutingAssembly());
            ribbonFactory.SetApplication(null, AddInBaseFactory.Create());
            var processedRibbon = ribbonFactory.GetCustomUI(TestRibbonTypes.RibbonType1.GetEnumDescription());
            //Open new view to create a viewmodel for view
            var viewInstance = new TestWindow { Context = new TestWindowContext() };
            var view2Instance = new TestWindow { Context = new TestWindowContext() };
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs<TestRibbonTypes>(
                viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1));
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs<TestRibbonTypes>(
                view2Instance, view2Instance.Context, TestRibbonTypes.RibbonType1));
            var buttonTag = GetTag(processedRibbon, "testTogglePanelButton");

            // act
            viewModelFactory.ViewModels[1].PanelShown = true;
            var ribbonControl = GetRibbonControl("testTogglePanelButton", buttonTag, viewInstance);
            var ribbon2Control = GetRibbonControl("testTogglePanelButton", buttonTag, view2Instance);
            var isPressed = ribbonFactory.GetPressed(ribbonControl);
            var is2Pressed = ribbonFactory.GetPressed(ribbon2Control);

            // assert
            Assert.False(isPressed);
            Assert.True(is2Pressed);
        }
        public void new_window_with_same_context_does_not_create_new_viewmodel()
        {
            // arrange
            ribbonFactoryUnderTest.ClearCurrent();
            var ribbonFactory = new TestRibbonFactory(
                testAddInBase,
                viewProvider, new TestContextProvider(), "Foo", Assembly.GetExecutingAssembly());
            testAddInBase.TestAddin.OnStartup();
            //Open new view to create a viewmodel for view
            var viewInstance = new TestWindow { Context = new TestWindowContext() };
            var view2Instance = new TestWindow { Context = new TestWindowContext() };

            // act

            var viewEventArgs = new NewViewEventArgs(viewInstance, viewInstance.Context,
                TestRibbonTypes.RibbonType1.GetEnumDescription());
            viewProvider.NewView += Raise.EventWith(viewProvider, viewEventArgs);
            var newViewEventArgs = new NewViewEventArgs(view2Instance, viewInstance.Context,
                TestRibbonTypes.RibbonType1.GetEnumDescription());
            viewProvider.NewView += Raise.EventWith(viewProvider, newViewEventArgs);

            // assert
            Assert.Equal(1, viewModelFactory.ViewModels.Count);
        }