public void toggle_button_is_bound_to_property_listens_to_property_changed_events()
        {
            // arrange
            //Open new view to create a viewmodel for view
            testAddInBase.TestAddin.OnStartup();
            var viewInstance = new TestWindow {
                Context = new TestWindowContext()
            };

            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs(
                                                        viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1.GetEnumDescription()));
            var ribbon = Substitute.For <IRibbonUI>();

            ribbonFactoryUnderTest.Ribbon_Load(ribbon);

            // act
            viewModelFactory.ViewModels.Single().OnPropertyChanged(new PropertyChangedEventArgs("PanelShown"));

            // assert
            ribbon.Received().InvalidateControl("testTogglePanelButton");
        }
        public void toggle_button_is_bound_to_property_get()
        {
            // arrange
            testAddInBase.TestAddin.OnStartup();
            var processedRibbon = ribbonFactoryUnderTest.GetCustomUI(TestRibbonTypes.RibbonType1.GetEnumDescription());
            //Open new view to create a viewmodel for view
            var viewInstance = new TestWindow {
                Context = new TestWindowContext()
            };

            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs(
                                                        viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1.GetEnumDescription()));
            viewModelFactory.ViewModels.Single().PanelShown = true;
            var toggleButtonTag = GetTag(processedRibbon, "testTogglePanelButton");

            // act
            var ribbonControl = GetRibbonControl("testTogglePanelButton", toggleButtonTag, viewInstance);
            var isPressed     = ribbonFactoryUnderTest.GetPressed(ribbonControl);

            // assert
            Assert.True(isPressed);
        }
        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);
        }
        public void toggle_button_is_bound_to_property_set()
        {
            // arrange
            ribbonFactoryUnderTest.SetApplication(null, AddInBaseFactory.Create());
            var processedRibbon = ribbonFactoryUnderTest.GetCustomUI(TestRibbonTypes.RibbonType1.GetEnumDescription());
            //Open new view to create a viewmodel for view
            var viewInstance = new TestWindow { Context = new TestWindowContext() };
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs<TestRibbonTypes>(
                viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1));
            viewModelFactory.ViewModels.Single().PanelShown = true;
            var toggleButtonTag = GetTag(processedRibbon, "testTogglePanelButton");

            // act
            var ribbonControl = GetRibbonControl("testTogglePanelButton", toggleButtonTag, viewInstance);
            ribbonFactoryUnderTest.PressedOnAction(ribbonControl, false);

            // assert
            Assert.False(viewModelFactory.ViewModels.Single().PanelShown);
        }
        public void toggle_button_is_bound_to_property_listens_to_property_changed_events()
        {
            // arrange
            //Open new view to create a viewmodel for view
            ribbonFactoryUnderTest.SetApplication(null, AddInBaseFactory.Create());
            var viewInstance = new TestWindow { Context = new TestWindowContext() };
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs<TestRibbonTypes>(
                viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1));
            var ribbon = Substitute.For<IRibbonUI>();
            ribbonFactoryUnderTest.Ribbon_Load(ribbon);

            // act
            viewModelFactory.ViewModels.Single().OnPropertyChanged(new PropertyChangedEventArgs("PanelShown"));

            // assert
            ribbon.Received().InvalidateControl("testTogglePanelButton");
        }
        public void ribbon_xml_getenabled_can_bind_to_method()
        {
            // arrange
            ribbonFactoryUnderTest.SetApplication(null, AddInBaseFactory.Create());
            var processedRibbon = ribbonFactoryUnderTest.GetCustomUI(TestRibbonTypes.RibbonType1.GetEnumDescription());
            //Open new view to create a viewmodel for view
            var viewInstance = new TestWindow
                                   {
                                       Context = new TestWindowContext()
                                   };
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs<TestRibbonTypes>(
                viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1));
            viewModelFactory.ViewModels.Single().PanelShown = true;
            var buttonTag = GetTag(processedRibbon, "actionButton");

            // act
            var ribbonControl = GetRibbonControl("actionButton", buttonTag, viewInstance);
            var isEnabled = ribbonFactoryUnderTest.GetEnabled(ribbonControl);

            // assert
            Assert.True(isEnabled);
        }
        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_different_context_does_not_create_new_viewmodel()
        {
            // arrange
            ribbonFactoryUnderTest.ClearCurrent();
            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 newViewEventArgs = new NewViewEventArgs(viewInstance, viewInstance.Context,
                TestRibbonTypes.RibbonType1.GetEnumDescription());
            var viewEventArgs = new NewViewEventArgs(view2Instance, view2Instance.Context,
                TestRibbonTypes.RibbonType1.GetEnumDescription());
            viewProvider.NewView += Raise.EventWith(viewProvider, newViewEventArgs);
            viewProvider.NewView += Raise.EventWith(viewProvider, viewEventArgs);

            // assert
            Assert.Equal(2, viewModelFactory.ViewModels.Count);
        }
        public void toggle_button_is_bound_to_property_get()
        {
            // arrange
            testAddInBase.TestAddin.OnStartup();
            var processedRibbon = ribbonFactoryUnderTest.GetCustomUI(TestRibbonTypes.RibbonType1.GetEnumDescription());
            //Open new view to create a viewmodel for view
            var viewInstance = new TestWindow { Context = new TestWindowContext() };
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs(
                viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1.GetEnumDescription()));
            viewModelFactory.ViewModels.Single().PanelShown = true;
            var toggleButtonTag = GetTag(processedRibbon, "testTogglePanelButton");

            // act
            var ribbonControl = GetRibbonControl("testTogglePanelButton", toggleButtonTag, viewInstance);
            var isPressed = ribbonFactoryUnderTest.GetPressed(ribbonControl);

            // assert
            Assert.True(isPressed);
        }
        public void ribbon_factory_calls_back_to_correct_view_model()
        {
            // arrange
            ribbonFactoryUnderTest.ClearCurrent();
            testAddInBase.TestAddin.OnStartup();
            var processedRibbon = ribbonFactoryUnderTest.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(
                viewInstance, viewInstance.Context, TestRibbonTypes.RibbonType1.GetEnumDescription()));
            viewProvider.NewView += Raise.EventWith(viewProvider, new NewViewEventArgs(
                view2Instance, view2Instance.Context, TestRibbonTypes.RibbonType1.GetEnumDescription()));
            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 = ribbonFactoryUnderTest.GetPressed(ribbonControl);
            var is2Pressed = ribbonFactoryUnderTest.GetPressed(ribbon2Control);

            // assert
            Assert.False(isPressed);
            Assert.True(is2Pressed);
        }