Exemple #1
0
        public void Test_CreateLeafMenuItems_ShouldCreatePanelWithLeafMenu()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu  = new HabaneroMenu("Main");
            string       subMenuName   = TestUtil.GetRandomString();
            HabaneroMenu submenu       = habaneroMenu.AddSubMenu(subMenuName);
            string       menuItemName1 = TestUtil.GetRandomString();

            submenu.AddMenuItem(menuItemName1);
            submenu.AddMenuItem(TestUtil.GetRandomString());
            CollapsibleMenuBuilderWin menuBuilder = (CollapsibleMenuBuilderWin)CreateMenuBuilder();
            IMenuItem menuItem = new CollapsibleSubMenuItemWin(GetControlFactory(), "Some Sub Menu");

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, menuItem.MenuItems.Count);
            ICollapsiblePanel menuItemAsControl = (ICollapsiblePanel)menuItem;

            Assert.AreEqual(1, menuItemAsControl.Controls.Count);
            Assert.AreEqual(2, submenu.MenuItems.Count);
            //---------------Execute Test ----------------------
            menuBuilder.CreateLeafMenuItems(submenu, menuItem);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, menuItem.MenuItems.Count);
            Assert.AreEqual(2, menuItemAsControl.Controls.Count);
            IControlHabanero contentControl = menuItemAsControl.ContentControl;

            Assert.AreEqual(2, contentControl.Controls.Count);
            IControlHabanero firstControl  = contentControl.Controls[0];
            IControlHabanero secondControl = contentControl.Controls[1];

            Assert.GreaterOrEqual(secondControl.Top, firstControl.Top + firstControl.Height);
        }
        public void TestSimpleMenuStructure_AddsCollapsiblePanels()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            string       subMenuName  = TestUtil.GetRandomString();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(subMenuName);
            string       menuItemName = TestUtil.GetRandomString();

            submenu.AddMenuItem(menuItemName);


            IMenuBuilder menuBuilder = CreateMenuBuilder();

            //---------------Assert Preconditions---------------
            Assert.AreEqual(1, habaneroMenu.Submenus.Count);
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);

            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(ICollapsiblePanelGroupControl), menu);
            ICollapsiblePanelGroupControl menuAsCP = (ICollapsiblePanelGroupControl)menu;

            Assert.AreEqual(1, menuAsCP.PanelsList.Count);
            ICollapsiblePanel collapsiblePanel = menuAsCP.PanelsList[0];

            Assert.IsNotNull(collapsiblePanel);
            Assert.IsNotNull(collapsiblePanel.ContentControl);
            Assert.AreEqual(1, collapsiblePanel.ContentControl.Controls.Count);
        }
Exemple #3
0
 /// <summary>
 /// Constructs a <see cref="CollapsibleMenuVWG"/>
 /// </summary>
 public CollapsibleMenuVWG(HabaneroMenu habaneroMenu) : this()
 {
     if (habaneroMenu != null)
     {
         this.Name = habaneroMenu.Name;
     }
 }
        public void TestCloseFormAndClickCreatesNewForm()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu  habaneroMenu = CreateHabaneroMenuFullySetup();
            IFormHabanero frm          = (IFormHabanero)habaneroMenu.Form;

            frm.Show();
            HabaneroMenu submenu = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());


            menuItem.FormControlCreator += (() => new FormControlStubWin());
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];

            formsMenuItem.PerformClick();
            System.Windows.Forms.Form    winForm             = (System.Windows.Forms.Form)frm;
            System.Windows.Forms.Form    childForm           = winForm.MdiChildren[0];
            System.Windows.Forms.Control expectedFormControl = childForm.Controls[0];
            //---------------Execute Test ----------------------

            childForm.Close();
            formsMenuItem.PerformClick();
            //---------------Test Result -----------------------

            Assert.AreEqual(1, winForm.MdiChildren.Length);
            childForm = winForm.MdiChildren[0];
            Assert.AreEqual(1, childForm.Controls.Count);
            Assert.IsInstanceOf(typeof(FormControlStubWin), winForm.MdiChildren[0].Controls[0]);
            Assert.AreNotSame(expectedFormControl, winForm.MdiChildren[0].Controls[0]);
        }
        public virtual void Test_CreateLeafMenuItems_ShouldCreatePanelWithLeafMenu()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu  = new HabaneroMenu("Main");
            string       subMenuName   = TestUtil.GetRandomString();
            HabaneroMenu submenu       = habaneroMenu.AddSubMenu(subMenuName);
            string       menuItemName1 = TestUtil.GetRandomString();

            submenu.AddMenuItem(menuItemName1);
            submenu.AddMenuItem(TestUtil.GetRandomString());
            CollapsibleMenuBuilderVWG menuBuilder = (CollapsibleMenuBuilderVWG)CreateMenuBuilder();
            IMenuItem menuItem = new CollapsibleSubMenuItemVWG(GetControlFactory(), "Some Sub Menu");

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, menuItem.MenuItems.Count);
            ICollapsiblePanel menuItemAsControl = (ICollapsiblePanel)menuItem;

            Assert.AreEqual(1, menuItemAsControl.Controls.Count);
            Assert.AreEqual(2, submenu.MenuItems.Count);
            //---------------Execute Test ----------------------
            menuBuilder.CreateLeafMenuItems(submenu, menuItem);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, menuItem.MenuItems.Count);
            Assert.AreEqual(2, menuItemAsControl.Controls.Count);
            IControlHabanero contentControl = menuItemAsControl.ContentControl;

            Assert.AreEqual(2, contentControl.Controls.Count);
            //Peter - 04/03/2010 - removed the assert below - the line that sets the Top is not working in this test, but the menu works in practice.
            //IControlHabanero firstControl = contentControl.Controls[0];
            //IControlHabanero secondControl = contentControl.Controls[1];
            //Assert.GreaterOrEqual(secondControl.Top, firstControl.Top + firstControl.Height);
        }
Exemple #6
0
        ///<summary>
        ///Builds the Main Menu based on a <paramref name="habaneroMenu" />
        ///</summary>
        ///<param name="habaneroMenu"></param>
        ///<returns>
        ///</returns>
        public virtual IMainMenuHabanero BuildMainMenu(HabaneroMenu habaneroMenu)
        {
            CollapsibleMenuWin mainMenu = new CollapsibleMenuWin(habaneroMenu);

            BuildSubMenu(habaneroMenu, mainMenu.MenuItems);
            return(mainMenu);
        }
Exemple #7
0
        public void Test_AddMultipleMenuItems_Should_ReturnMultipleMenuItemAfterBuildMainMenu()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            string       menuItemName = TestUtil.GetRandomString();

            habaneroMenu.AddMenuItem(menuItemName);
            string menuItemName2 = TestUtil.GetRandomString();

            habaneroMenu.AddMenuItem(menuItemName2);
            string menuItemName3 = TestUtil.GetRandomString();

            habaneroMenu.AddMenuItem(menuItemName3);


            IMenuBuilder menuBuilder = CreateMenuBuilder();

            //---------------Assert Preconditions---------------
            Assert.AreEqual(3, habaneroMenu.MenuItems.Count);
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);

            //---------------Test Result -----------------------
            Assert.AreEqual(3, menu.MenuItems.Count);
            Assert.AreEqual(menuItemName, menu.MenuItems[0].Text);
            Assert.AreEqual(menuItemName2, menu.MenuItems[1].Text);
            Assert.AreEqual(menuItemName3, menu.MenuItems[2].Text);
        }
Exemple #8
0
        public void TestHandlesError_FromControlManagerCreator()
        {
            //---------------Set up test pack-------------------
            MockExceptionNotifier exceptionNotifier = new MockExceptionNotifier();

            GlobalRegistry.UIExceptionNotifier = exceptionNotifier;
            Exception    exception    = new Exception();
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());
            menuItem.ControlManagerCreator += delegate
            {
                throw exception;
            };
            IMenuBuilder      menuBuilder   = CreateMenuBuilder();
            IMainMenuHabanero menu          = menuBuilder.BuildMainMenu(habaneroMenu);
            IMenuItem         formsMenuItem = menu.MenuItems[0].MenuItems[0];

            menu.DockInForm(habaneroMenu.Form);

            //-------------Assert Preconditions -------------
            Assert.IsNull(exceptionNotifier.Exception);
            Assert.IsNull(exceptionNotifier.FurtherMessage);
            Assert.IsNull(exceptionNotifier.Title);

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.AreEqual(exception, exceptionNotifier.Exception);
            Assert.IsNull(null, exceptionNotifier.FurtherMessage);
            Assert.IsNull(null, exceptionNotifier.Title);
        }
Exemple #9
0
        public void TestMultiLevels()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu  = new HabaneroMenu("Main");
            string       subMenuName   = TestUtil.GetRandomString();
            HabaneroMenu submenu       = habaneroMenu.AddSubMenu(subMenuName);
            string       menuItemName1 = TestUtil.GetRandomString();

            submenu.AddMenuItem(menuItemName1);

            string       subsubMenuName = TestUtil.GetRandomString();
            HabaneroMenu subsubmenu     = submenu.AddSubMenu(subsubMenuName);

            string menuItemName2 = TestUtil.GetRandomString();

            subsubmenu.AddMenuItem(menuItemName2);
            IMenuBuilder menuBuilder = CreateMenuBuilder();
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, menu.MenuItems.Count);
            IMenuItem createdSubMenu = menu.MenuItems[0];

            Assert.AreEqual(2, createdSubMenu.MenuItems.Count);
            IMenuItem createdSubsubMenu = createdSubMenu.MenuItems[0];

            Assert.AreEqual(1, createdSubsubMenu.MenuItems.Count);
            Assert.AreEqual(menuItemName1, createdSubMenu.MenuItems[1].Text);
            Assert.AreEqual(menuItemName2, createdSubsubMenu.MenuItems[0].Text);
        }
Exemple #10
0
        public void TestControlManagerCreatorCalledIfSet()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem   = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool                  called = false;
            IControlFactory       controlFactoryPassedToCreator = null;
            ControlManagerCreator formControlCreatorDelegate    = delegate(IControlFactory controlFactory)
            {
                called = true;
                controlFactoryPassedToCreator = controlFactory;
                return(new ControlManagerStub(controlFactory));
            };

            menuItem.ControlManagerCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(called);
            Assert.AreSame(habaneroMenu.ControlFactory, controlFactoryPassedToCreator);
        }
Exemple #11
0
        public void TestCustomMenuHandlerTakesPrecedence()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem       = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool         customHandlerCalled = false;
            EventHandler customerHandler     = delegate
            {
                customHandlerCalled = true;
            };
            bool formControlHandlerCalled = false;
            FormControlCreator formControlCreatorDelegate = delegate
            {
                formControlHandlerCalled = true;
                return(CreateFormControlStub());
            };

            menuItem.CustomHandler      += customerHandler;
            menuItem.FormControlCreator += formControlCreatorDelegate;
            IMenuBuilder menuBuilder = CreateMenuBuilder();
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu          = menuBuilder.BuildMainMenu(habaneroMenu);
            IMenuItem         formsMenuItem = menu.MenuItems[0].MenuItems[0];

            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsFalse(formControlHandlerCalled);
            Assert.IsTrue(customHandlerCalled);
        }
Exemple #12
0
        public void TestFormControlCreatorCalledOnClickIfSet()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool called = false;
            FormControlCreator formControlCreatorDelegate = delegate
            {
                called = true;
                return(CreateFormControlStub());
            };

            menuItem.FormControlCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(called);
        }
Exemple #13
0
        public virtual void Test_Click_WhenFormControlCreatorSet_ShouldCallSetFormOnFormControl()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());

            bool               creatorCalled              = false;
            IFormControlStub   formControlStub            = CreateFormControlStub();
            FormControlCreator formControlCreatorDelegate = delegate
            {
                creatorCalled = true;
                return(formControlStub);
            };

            menuItem.FormControlCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(creatorCalled);
            Assert.IsFalse(formControlStub.SetFormCalled);
            Assert.IsNull(formControlStub.SetFormArgument);
            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(creatorCalled);
            Assert.IsTrue(formControlStub.SetFormCalled);
            Assert.IsNotNull(formControlStub.SetFormArgument);
        }
Exemple #14
0
        public void TestClickSecondItemDocksNewControlInForm()
        {
            //---------------Set up test pack-------------------

            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem1            = submenu.AddMenuItem(TestUtil.GetRandomString());
            IFormControl      expectedFormControl1 = CreateFormControlStub();

            menuItem1.FormControlCreator += (() => expectedFormControl1);
            HabaneroMenu.Item menuItem2            = submenu.AddMenuItem(TestUtil.GetRandomString());
            IFormControl      expectedFormControl2 = CreateFormControlStub();

            menuItem2.FormControlCreator += (() => expectedFormControl2);

            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem1 = menu.MenuItems[0].MenuItems[0];
            IMenuItem formsMenuItem2 = menu.MenuItems[0].MenuItems[1];

            formsMenuItem1.PerformClick();

            //-------------Assert Preconditions -------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl1, (IFormHabanero)habaneroMenu.Form);

            //---------------Execute Test ----------------------
            formsMenuItem2.PerformClick();

            //---------------Test Result -----------------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl2, (IFormHabanero)habaneroMenu.Form);
        }
Exemple #15
0
        public void Test_PerformClick_WhenMenuFormHasNoControlSet_ShouldNotCallCreators()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main", GetControlFactory().CreateForm(), GetControlFactory());
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool called = false;

            menuItem.FormControlCreator = delegate
            {
                called = true;
                return(CreateFormControlStub());
            };
            menuItem.ControlManagerCreator = delegate
            {
                called = true;
                return(new ControlManagerStub(GetControlFactory()));
            };
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            //---------------Assert Precondition ---------------
            Assert.IsNotNull(menuItem.Form);
            Assert.AreEqual(0, menuItem.Form.Controls.Count);
            //---------------Execute Test ----------------------
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];

            formsMenuItem.PerformClick();
            //---------------Test Result -----------------------
            Assert.IsFalse(called);
        }
Exemple #16
0
        public virtual void Test_Click_WhenFormControlCreatorSet_ShouldCallSetFormOnFormControl()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            var          menuItem     = habaneroMenu.AddMenuItem(TestUtil.GetRandomString());

            bool               creatorCalled              = false;
            IFormControlStub   formControlStub            = CreateFormControlStub();
            FormControlCreator formControlCreatorDelegate = delegate
            {
                creatorCalled = true;
                return(formControlStub);
            };

            menuItem.FormControlCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);
            //menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem = menu.MenuItems[0];

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(creatorCalled);
            Assert.IsFalse(formControlStub.SetFormCalled);
            Assert.IsNull(formControlStub.SetFormArgument);
            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(creatorCalled);
            Assert.IsTrue(formControlStub.SetFormCalled);
            //The MenuBuilderVWG sites the control on a UserControl instead of a form (VWG does not support MDI Children), so this next assert would fail.
            //Assert.IsNotNull(formControlStub.SetFormArgument);
        }
Exemple #17
0
        public void Test_PerformClick_NoCreatorsCalledWhenMenuFormNotSet()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            string       menuItemName = TestUtil.GetRandomString();
            var          menuItem     = habaneroMenu.AddMenuItem(menuItemName);
            //HabaneroMenu submenu = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());
            //HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool called = false;

            menuItem.FormControlCreator = delegate
            {
                called = true;
                return(CreateFormControlStub());
            };
            menuItem.ControlManagerCreator = delegate
            {
                called = true;
                return(new ControlManagerStub(GetControlFactory()));
            };
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            //---------------Assert Precondition ---------------
            Assert.IsNull(menuItem.Form);
            //---------------Execute Test ----------------------
            IMenuItem formsMenuItem = menu.MenuItems[0];

            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsFalse(called);
        }
Exemple #18
0
        public void TestClickMenuItemTwiceOnlyLeavesSameControlDocked()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem            = submenu.AddMenuItem(TestUtil.GetRandomString());
            IFormControl      expectedFormControl = CreateFormControlStub();

            menuItem.FormControlCreator += (() => expectedFormControl);
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];

            formsMenuItem.PerformClick();

            //-------------Assert Preconditions -------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl, (IFormHabanero)habaneroMenu.Form);

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl, (IFormHabanero)habaneroMenu.Form);
        }
Exemple #19
0
 /// <summary>
 /// Builds the Sub Menu based on the <paramref name="habaneroMenu"/> definition.
 /// The Sub Menu items created are added to the menuItems Collection <see cref="IMenuItemCollection"/>
 /// </summary>
 /// <param name="habaneroMenu">The definition of the Sub Menu</param>
 /// <param name="menuItems">The collection to which the Sub Menu items are added</param>
 public virtual void BuildSubMenu(HabaneroMenu habaneroMenu, IMenuItemCollection menuItems)
 {
     foreach (HabaneroMenu submenu in habaneroMenu.Submenus)
     {
         menuItems.Add(BuildMenu(submenu));
     }
 }
 public MainMenuWin(HabaneroMenu habaneroMenu) : this()
 {
     _habaneroMenu = habaneroMenu;
     if (_habaneroMenu != null)
     {
         this.Name = _habaneroMenu.Name;
     }
 }
Exemple #21
0
        /// <summary>
        /// Builds a Menu for Win.
        /// </summary>
        /// <param name="habaneroMenu"></param>
        /// <returns></returns>
        protected virtual IMenuItem BuildMenu(HabaneroMenu habaneroMenu)
        {
            IMenuItem subMenuItem = new CollapsibleSubMenuItemWin(this.ControlFactory, habaneroMenu.Name);

            BuildSubMenu(habaneroMenu, subMenuItem.MenuItems);
            CreateLeafMenuItems(habaneroMenu, subMenuItem);
            return(subMenuItem);
        }
Exemple #22
0
 /// <summary>
 /// Creates the Leaf Items defined by the <see cref="HabaneroMenu"/> and addts them
 /// to the <paramref name="menuItem"/>'s MenuItems Collection.
 /// </summary>
 /// <param name="habaneroMenu">The definition of the Menu</param>
 /// <param name="menuItem">The Menu Item that the MenuItems will be added to.</param>
 public virtual void CreateLeafMenuItems(HabaneroMenu habaneroMenu, IMenuItem menuItem)
 {
     foreach (HabaneroMenu.Item habaneroMenuItem in habaneroMenu.MenuItems)
     {
         IMenuItem childMenuItem = new CollapsibleMenuItemWin(habaneroMenuItem);
         childMenuItem.Click += delegate { childMenuItem.DoClick(); };
         menuItem.MenuItems.Add(childMenuItem);
     }
 }
Exemple #23
0
        public void TestCreateMenu()
        {
            //---------------Set up test pack-------------------

            //---------------Execute Test ----------------------
            HabaneroMenu menu = new HabaneroMenu("Main");

            //---------------Test Result -----------------------
            Assert.AreEqual(0, menu.Submenus.Count);
            //---------------Tear Down -------------------------
        }
        ///<summary>
        /// Builds the Main Menu based on a <paramref name="habaneroMenu"/>
        ///</summary>
        ///<param name="habaneroMenu"></param>
        ///<returns></returns>
        public IMainMenuHabanero BuildMainMenu(HabaneroMenu habaneroMenu)
        {
            IMainMenuHabanero mainMenu = ControlFactory.CreateMainMenu();

            mainMenu.Name = habaneroMenu.Name;
            foreach (HabaneroMenu submenu in habaneroMenu.Submenus)
            {
                mainMenu.MenuItems.Add(BuildMenu(submenu));
            }
            return(mainMenu);
        }
Exemple #25
0
        public void Test_ConstructContextMenu_WithHabaneroMenu()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu menu = new HabaneroMenu(TestUtil.GetRandomString());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            IMainMenuHabanero contextMenu = CreateControl(menu);

            //---------------Test Result -----------------------
            Assert.IsNotNull(contextMenu);
            Assert.IsNotNull(contextMenu.MenuItems);
            Assert.AreEqual(menu.Name, contextMenu.Name);
        }
Exemple #26
0
        public void Test_BuildMainMenu_ShouldReturnTypeOf_ContextMenuWin()
        {
            //---------------Set up test pack-------------------
            //---------------Set up test pack-------------------
            IMenuBuilder contextMenuBuilderWin = new ContextMenuBuilderWin(GlobalUIRegistry.ControlFactory);
            HabaneroMenu habaneroMenu          = new HabaneroMenu("Main");
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var menu = contextMenuBuilderWin.BuildMainMenu(habaneroMenu);

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <ContextMenuWin>(menu);
        }
Exemple #27
0
        public void Test_BuildMainMenu()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            IMenuBuilder menuBuilder  = CreateMenuBuilder();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);

            //---------------Test Result -----------------------
            Assert.IsNotNull(menu);
            Assert.AreEqual(habaneroMenu.Name, menu.Name);
        }
Exemple #28
0
        public void TestAddSubMenu()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu menu     = new HabaneroMenu("Main");
            string       menuName = TestUtil.GetRandomString();
            //---------------Execute Test ----------------------
            HabaneroMenu submenu = menu.AddSubMenu(menuName);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, menu.Submenus.Count);
            Assert.AreSame(submenu, menu.Submenus[0]);
            Assert.AreEqual(menuName, submenu.Name);
            //---------------Tear Down -------------------------
        }
Exemple #29
0
        public void TestAddMenuItem()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu submenu      = new HabaneroMenu("Main").AddSubMenu("Submenu");
            string       menuItemName = TestUtil.GetRandomString();

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            HabaneroMenu.Item menuItem = submenu.AddMenuItem(menuItemName);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, submenu.MenuItems.Count);
            Assert.AreSame(menuItem, submenu.MenuItems[0]);
            Assert.AreEqual(menuItemName, menuItem.Name);
            //---------------Tear Down -------------------------
        }
        ///<summary>
        /// Builds the Context Menu based on a <paramref name="habaneroMenu"/>
        ///</summary>
        ///<param name="habaneroMenu"></param>
        ///<returns></returns>
        public IMainMenuHabanero BuildMainMenu(HabaneroMenu habaneroMenu)
        {
            IMainMenuHabanero mainMenu = ControlFactory.CreateContextMenu();

            mainMenu.Name = habaneroMenu.Name;

            foreach (HabaneroMenu.Item habaneroMenuItem in habaneroMenu.MenuItems)
            {
                IMenuItem menuItem = this.ControlFactory.CreateMenuItem(habaneroMenuItem);
                menuItem.Click += delegate { menuItem.DoClick(); };
                mainMenu.MenuItems.Add(menuItem);
            }

            return(mainMenu);
        }