AddSubMenu() public method

Adds a sub menu to this menu. This method creates a new HabaneroMenu with the name menuName and adds it as a sub menu.
public AddSubMenu ( string menuName ) : HabaneroMenu
menuName string
return HabaneroMenu
 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 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 -------------------------          
 }
 public void TestMultipleSubmenus()
 {
     //---------------Set up test pack-------------------
     HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
     string subMenuName1 = TestUtil.GetRandomString();
     HabaneroMenu submenu1 = habaneroMenu.AddSubMenu(subMenuName1);
     string subMenuName2 = TestUtil.GetRandomString();
     HabaneroMenu submenu2 = habaneroMenu.AddSubMenu(subMenuName2);
     submenu1.AddMenuItem(TestUtil.GetRandomString());
     submenu2.AddMenuItem(TestUtil.GetRandomString());
     submenu2.AddMenuItem(TestUtil.GetRandomString());
     IMenuBuilder menuBuilder = CreateMenuBuilder();
     //---------------Execute Test ----------------------
     IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);
     //---------------Test Result -----------------------
     Assert.AreEqual(2, menu.MenuItems.Count);
     Assert.AreEqual(subMenuName1, menu.MenuItems[0].Text);
     Assert.AreEqual(1, menu.MenuItems[0].MenuItems.Count);
     Assert.AreEqual(subMenuName2, menu.MenuItems[1].Text);
     Assert.AreEqual(2, menu.MenuItems[1].MenuItems.Count);
               
 }
 public void TestSimpleMenuStructure()
 {
     //---------------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();
     //---------------Execute Test ----------------------
     IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, menu.MenuItems.Count);
     Assert.AreEqual(subMenuName, menu.MenuItems[0].Text);
     Assert.AreEqual(1, menu.MenuItems[0].MenuItems.Count);
     Assert.AreEqual(menuItemName, menu.MenuItems[0].MenuItems[0].Text);
               
 }
        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);
        }
 public void Test_CreateSubMenuItems_ShouldCreatePanelWithLeafMenu()
 {
     //---------------Set up test pack-------------------
     HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
     string subMenuName = TestUtil.GetRandomString();
     habaneroMenu.AddSubMenu(subMenuName);
     habaneroMenu.AddSubMenu("SecondSubMenu");
     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, habaneroMenu.Submenus.Count);
     //---------------Execute Test ----------------------
     menuBuilder.BuildSubMenu(habaneroMenu, menuItem.MenuItems);
     //---------------Test Result -----------------------
     Assert.AreEqual(2, menuItem.MenuItems.Count);
     Assert.AreEqual(1, menuItemAsControl.Controls.Count);
 }
        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);
        }
        public void TestCustomMenuHandlerCalledIfSet()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            HabaneroMenu submenu = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());
            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool called = false;
            EventHandler customerHandler = delegate
            {
                called = true;
            };
            menuItem.CustomHandler += customerHandler;
            IMenuBuilder menuBuilder = CreateMenuBuilder();
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(called);
                            
        }
 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);      
 }
        public void Test_BuildMainMenu_TwoSubMenus_ShouldCreateSubMenusAndLeafMenuItems()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            string subMenuName = "sub_" + TestUtil.GetRandomString();
            HabaneroMenu submenu = habaneroMenu.AddSubMenu(subMenuName);
            string menuItemName = "menu_" + TestUtil.GetRandomString();
            submenu.AddMenuItem(menuItemName);
            HabaneroMenu submenu2 = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());
            submenu2.AddMenuItem("subsub_" + TestUtil.GetRandomString());
            submenu2.AddMenuItem("subsub_" + TestUtil.GetRandomString());

            IMenuBuilder menuBuilder = CreateMenuBuilder();
            //---------------Assert Preconditions---------------
            Assert.AreEqual(2, habaneroMenu.Submenus.Count);
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);
            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(ICollapsiblePanelGroupControl), menu);
            ICollapsiblePanelGroupControl menuAsCP = (ICollapsiblePanelGroupControl)menu;
            Assert.AreEqual(2, menuAsCP.PanelsList.Count);
            ICollapsiblePanel collapsiblePanel1 = menuAsCP.PanelsList[0];
            Assert.AreEqual(subMenuName, collapsiblePanel1.CollapseButton.Text);
            Assert.IsNotNull(collapsiblePanel1);
            Assert.IsNotNull(collapsiblePanel1.ContentControl);
            Assert.AreEqual(1, collapsiblePanel1.ContentControl.Controls.Count);

            ICollapsiblePanel collapsiblePanel2 = menuAsCP.PanelsList[1];
            Assert.AreEqual(submenu2.Name, collapsiblePanel2.Text);
            Assert.AreEqual(submenu2.Name, collapsiblePanel2.Name);
            Assert.AreEqual(submenu2.Name, collapsiblePanel2.CollapseButton.Text);

            Assert.IsNotNull(collapsiblePanel2);
            Assert.IsNotNull(collapsiblePanel2.ContentControl);
            Assert.AreEqual(2, collapsiblePanel2.ContentControl.Controls.Count);

            Assert.GreaterOrEqual(collapsiblePanel1.Top, collapsiblePanel2.Top + collapsiblePanel2.Height, "The collapsible panel are put in reverse order.");
        }