A particular menu item that will be built into a Leaf Node of the Relevant Menu. The MenuBulder will build a menu item represented by this Item. This Item can be set up with either a CustomHandler
or a ControlManagerCreator or a FormControlCreator. These are used by the relevant MenuItemControl to respond the its click event.
 public virtual void Test_AddLeafMenuItem_ShouldAddButtonToCollapsiblePanel()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item ownerItem = new HabaneroMenu.Item(null, name);
     CollapsibleSubMenuItemVWG subMenuItem = new CollapsibleSubMenuItemVWG(GetControlFactory(), ownerItem);
     CollapsibleMenuItemCollectionVWG collapsibleMenuItemCollection = new CollapsibleMenuItemCollectionVWG
         (subMenuItem);
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     CollapsibleMenuItemVWG menuLeafItem = new CollapsibleMenuItemVWG(GetControlFactory(), item);
     //---------------Assert Precondition----------------
     Assert.AreSame(subMenuItem, collapsibleMenuItemCollection.OwnerMenuItem);
     Assert.IsInstanceOf(typeof(CollapsibleMenuItemVWG), menuLeafItem);
     Assert.AreEqual(1, subMenuItem.Controls.Count, "CollapsiblePanel always has header button");
     Assert.AreEqual(0, collapsibleMenuItemCollection.Count);
     //---------------Execute Test ----------------------
     collapsibleMenuItemCollection.Add(menuLeafItem);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, collapsibleMenuItemCollection.Count);
     Assert.AreEqual(2, subMenuItem.Controls.Count, "Should have additional button control");
     IControlHabanero contentControl = subMenuItem.ContentControl;
     Assert.IsInstanceOf(typeof(IPanel), contentControl);
     Assert.AreEqual(1, contentControl.Controls.Count);
     Assert.IsInstanceOf(typeof(IButton), contentControl.Controls[0]);
     Assert.AreEqual(menuLeafItem.Dock, DockStyleVWG.GetDockStyle(DockStyle.Top));
 }
 public void Test_ConstructMenuItem_WithHabaneroMenuItem_ShouldSetName()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     IMenuItem menuItem = CreateMenuItem(item);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     IMenuItemCollection collapsibleMenuItemCollection = CreateControl(menuItem);
     //---------------Test Result -----------------------
     Assert.AreSame(menuItem, collapsibleMenuItemCollection.OwnerMenuItem);
 }
 public void Test_ConstructMenuItem_WithHabaneroMenuItem_ShouldSetName()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     IMenuItem collapsibleMenuItem = CreateControl(item);
     //---------------Test Result -----------------------
     Assert.AreEqual(name, collapsibleMenuItem.Text);
     Assert.AreEqual(item.Name, collapsibleMenuItem.Text);
     Assert.IsNotNull(collapsibleMenuItem.MenuItems);
 }
 public void TestSetFormControlCreator()
 {
     //---------------Set up test pack-------------------
     FormControlStub formControlStub = new FormControlStub();
     HabaneroMenu.Item menuItem = new HabaneroMenu.Item(null, TestUtil.GetRandomString());
     //---------------Assert PreConditions---------------            
     Assert.IsNull(menuItem.FormControlCreator);
     //---------------Execute Test ----------------------
     menuItem.FormControlCreator += (() => formControlStub);
     IFormControl formControl = menuItem.FormControlCreator();
     //---------------Test Result -----------------------
     Assert.IsNotNull(menuItem.FormControlCreator);
     Assert.IsNotNull(formControl);
     Assert.IsInstanceOf(typeof(FormControlStub), formControl);
     Assert.AreSame(formControlStub,formControl);
     //---------------Tear Down -------------------------          
 }
 public void Test_ConstructMenuItem_ControlFactoryNull_ShouldRaiseError()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     try
     {
         CreateControl(null, item);
         Assert.Fail("expected ArgumentNullException");
     }
         //---------------Test Result -----------------------
     catch (ArgumentNullException ex)
     {
         StringAssert.Contains("Value cannot be null", ex.Message);
         StringAssert.Contains("controlFactory", ex.ParamName);
     }
 }
 public virtual void Test_AddSubMenuItem_ShouldAddCollapsiblePanel()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     CollapsibleMenuVWG menu = new CollapsibleMenuVWG();
     CollapsibleMenuItemCollectionVWG collapsibleMenuItemCollection = new CollapsibleMenuItemCollectionVWG(menu);
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     IMenuItem menuLeafItem = new CollapsibleSubMenuItemVWG(GetControlFactory(), item);
     //---------------Assert Precondition----------------
     Assert.AreSame(menu, collapsibleMenuItemCollection.OwnerMenuItem);
     Assert.IsInstanceOf(typeof(CollapsibleSubMenuItemVWG), menuLeafItem);
     Assert.AreEqual(0, collapsibleMenuItemCollection.Count);
     //---------------Execute Test ----------------------
     collapsibleMenuItemCollection.Add(menuLeafItem);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, collapsibleMenuItemCollection.Count);
     Assert.AreEqual(1, menu.PanelsList.Count);
     ICollapsiblePanel collapsiblePanel = menu.PanelsList[0];
     Assert.AreEqual(name, collapsiblePanel.Text);
 }
Esempio n. 7
0
 ///<summary>
 /// Adds a MenuItem. Creates a Menu <see cref="Item"/> with the name <paramref name="menuItemName"/>
 ///</summary>
 ///<param name="menuItemName"></param>
 ///<returns></returns>
 public Item AddMenuItem(string menuItemName)
 {
     HabaneroMenu.Item menuItem = new HabaneroMenu.Item(this, menuItemName, _form, _controlFactory);
     _menuItems.Add(menuItem);
     return menuItem;
 }
 public void Test_CreateMenuItem_FromHabaneroMenuItem()
 {
     //---------------Set up test pack-------------------
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, TestUtil.GetRandomString());
     DisposeOnTearDown(item);     
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     IMenuItem mmenu = _factory.CreateMenuItem(item);
     DisposeOnTearDown(mmenu);
     //---------------Test Result -----------------------
     Assert.IsNotNull(mmenu);
     Assert.AreEqual(item.Name, mmenu.Text);
 }
 public void Test_DoClick_ShouldExpandTheCollapsiblePanel()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item item = new HabaneroMenu.Item(null,name);
     IMenuItem collapsibleMenuItem = CreateControl( item);
     ICollapsiblePanel subMenuAsCollapsiblePanel = (ICollapsiblePanel) collapsibleMenuItem;
     //---------------Assert Precondition----------------
     Assert.IsTrue(subMenuAsCollapsiblePanel.Collapsed);
     //---------------Execute Test ----------------------
     collapsibleMenuItem.DoClick();
     //---------------Test Result -----------------------
     Assert.IsFalse(subMenuAsCollapsiblePanel.Collapsed);
 }
 public void Test_MenuItems_ShouldAlwaysReturnTheSameInstance()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     IMenuItem collapsibleMenuItem = CreateControl( item);
     IMenuItemCollection expectedMenuItems = collapsibleMenuItem.MenuItems;
     //---------------Assert Precondition----------------
     Assert.IsNotNull(collapsibleMenuItem);
     Assert.IsNotNull(expectedMenuItems);
     //---------------Execute Test ----------------------
     IMenuItemCollection secondCallToMenuItems = collapsibleMenuItem.MenuItems;
     //---------------Test Result -----------------------
     Assert.AreSame(expectedMenuItems, secondCallToMenuItems);
 }
 public void Test_ConstructSubMenu_ShouldBeCollapsed()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     IMenuItem collapsibleMenuItem = CreateControl( item);
     ICollapsiblePanel subMenuAsCollapsiblePanel = (ICollapsiblePanel) collapsibleMenuItem;
     //---------------Test Result -----------------------
     Assert.IsTrue(subMenuAsCollapsiblePanel.Collapsed);
     Assert.AreEqual
         (subMenuAsCollapsiblePanel.CollapseButton.Height, subMenuAsCollapsiblePanel.MinimumSize.Height);
 }
 public virtual void Test_AddLeafMenuItem_ShouldIncreaseMinSizeOfCollapsiblePanel()
 {
     //---------------Set up test pack-------------------
     string name = TestUtil.GetRandomString();
     HabaneroMenu.Item ownerItem = new HabaneroMenu.Item(null, name);
     CollapsibleSubMenuItemVWG subMenuItem = new CollapsibleSubMenuItemVWG(GetControlFactory(), ownerItem);
     CollapsibleMenuItemCollectionVWG collapsibleMenuItemCollection = new CollapsibleMenuItemCollectionVWG
         (subMenuItem);
     HabaneroMenu.Item item = new HabaneroMenu.Item(null, name);
     CollapsibleMenuItemVWG menuLeafItem = new CollapsibleMenuItemVWG(GetControlFactory(), item);
     //---------------Assert Precondition----------------
     Assert.AreSame(subMenuItem, collapsibleMenuItemCollection.OwnerMenuItem);
     Assert.IsInstanceOf(typeof(CollapsibleMenuItemVWG), menuLeafItem);
     Assert.AreEqual(subMenuItem.CollapseButton.Height, subMenuItem.MinimumSize.Height);
     //---------------Execute Test ----------------------
     collapsibleMenuItemCollection.Add(menuLeafItem);
     //---------------Test Result -----------------------
     int expectedHeight = subMenuItem.CollapseButton.Height + menuLeafItem.Height;
     Assert.AreEqual(expectedHeight, subMenuItem.Height);
     Assert.AreEqual
         (expectedHeight, subMenuItem.ExpandedHeight, "this will be zero untill the first time this is collapsed");
 }
 public void TestSetManagedControl_ShouldSetADefaultControlManagerCreator()
 {
     //---------------Set up test pack-------------------
     HabaneroMenu.Item menuItem = new HabaneroMenu.Item(null, TestUtil.GetRandomString());
     var control = new ControlHabaneroFake();
     //---------------Assert PreConditions---------------            
     Assert.IsNull(menuItem.ControlManagerCreator);
     //---------------Execute Test ----------------------
     menuItem.ManagedControl = control;
     Assert.IsNotNull(menuItem.ControlManagerCreator);
     var controlManager = menuItem.ControlManagerCreator(null);
     //---------------Test Result -----------------------
     Assert.AreSame(control, controlManager.Control);
 }
 public void TestSetControlManagerCreator()
 {
     //---------------Set up test pack-------------------
     HabaneroMenu.Item menuItem = new HabaneroMenu.Item(null, TestUtil.GetRandomString());
     //---------------Assert PreConditions---------------            
     Assert.IsNull(menuItem.ControlManagerCreator);
     //---------------Execute Test ----------------------
     menuItem.ControlManagerCreator += delegate { return new ControlManagerStub(); };
     IControlManager controlManager = menuItem.ControlManagerCreator(null);
     //---------------Test Result -----------------------
     Assert.IsNotNull(menuItem.ControlManagerCreator);
     Assert.IsNotNull(controlManager);
     Assert.IsInstanceOf(typeof(ControlManagerStub), controlManager);
 }
 public void TestSetManagedControl_WithNull_ShouldClearControlManagerCreator()
 {
     //---------------Set up test pack-------------------
     HabaneroMenu.Item menuItem = new HabaneroMenu.Item(null, TestUtil.GetRandomString());
     ControlHabaneroFake control = new ControlHabaneroFake();
     menuItem.ManagedControl = control;
     //---------------Assert PreConditions---------------            
     Assert.IsNotNull(menuItem.ControlManagerCreator);
     //---------------Execute Test ----------------------
     menuItem.ManagedControl = null;
     //---------------Test Result -----------------------
     Assert.IsNull(menuItem.ControlManagerCreator);
 }
Esempio n. 16
0
 ///<summary>
 /// Adds a MenuItem. Creates a Menu <see cref="Item"/> with the name <paramref name="menuItemName"/>
 ///</summary>
 ///<param name="menuItemName"></param>
 ///<returns></returns>
 public Item AddMenuItem(string menuItemName)
 {
     HabaneroMenu.Item menuItem = new HabaneroMenu.Item(this, menuItemName, _form, _controlFactory);
     _menuItems.Add(menuItem);
     return(menuItem);
 }