AddMenuItem() public method

Adds a MenuItem. Creates a Menu Item with the name menuItemName
public AddMenuItem ( string menuItemName ) : System.Item
menuItemName string
return System.Item
        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 -------------------------          
        }
        public void Test_AddMenuItem_Should_ReturnMenuItemAfterBuildMainMenu()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            string menuItemName = TestUtil.GetRandomString();
            habaneroMenu.AddMenuItem(menuItemName);


            IMenuBuilder menuBuilder = CreateMenuBuilder();
            //---------------Assert Preconditions---------------
            Assert.AreEqual(1, habaneroMenu.MenuItems.Count);
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, menu.MenuItems.Count);
            Assert.AreEqual(menuItemName, menu.MenuItems[0].Text);
        }
        public void TestCustomMenuHandlerTakesPrecedence()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            var menuItem = habaneroMenu.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];
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsFalse(formControlHandlerCalled);
            Assert.IsTrue(customHandlerCalled);
        }
        public void TestCustomMenuHandlerCalledIfSet()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            var menuItem = habaneroMenu.AddMenuItem(TestUtil.GetRandomString());
            bool called = false;
            System.EventHandler customerHandler = delegate { called = true; };
            menuItem.CustomHandler += customerHandler;
            IMenuBuilder menuBuilder = CreateMenuBuilder();
            //---------------Execute Test ----------------------
            IMainMenuHabanero menu = menuBuilder.BuildMainMenu(habaneroMenu);
            IMenuItem formsMenuItem = menu.MenuItems[0];
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(called);
            //---------------Tear Down -------------------------                
        }
 public void Test_PerformClick_WhenMenuFormHasNoControlSet_ShouldNotCallCreators()
 {
     //---------------Set up test pack-------------------
     HabaneroMenu habaneroMenu = new HabaneroMenu("Main", GetControlFactory().CreateForm(), GetControlFactory());
     var menuItem = habaneroMenu.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];
     formsMenuItem.PerformClick();
     //---------------Test Result -----------------------
     Assert.IsFalse(called);
 }
        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);
        }
        public void Test_BuildMainMenu_WhenAddingHabaneroMenuWithOneMenuItem_ShouldReturnMenuWithOneMenuItem()
        {
            //---------------Set up test pack-------------------
            IMenuBuilder contextMenuBuilderWin = new ContextMenuBuilderWin(GlobalUIRegistry.ControlFactory);
            HabaneroMenu habaneroMenu = new HabaneroMenu("Main");
            string menuNameItem = "test";
            habaneroMenu.AddMenuItem(menuNameItem);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, habaneroMenu.MenuItems.Count);

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

            //---------------Test Result -----------------------
            Assert.AreEqual(1, menu.MenuItems.Count);

        }