public void MenuItemCollection_Add_MenuItemToCreatedMenu_Success() { using (var menu = new SubMenu(new MenuItem[0])) { Assert.NotEqual(IntPtr.Zero, menu.Handle); var collection = new Menu.MenuItemCollection(menu); var menuItem1 = new MenuItem("text1"); Assert.Equal(0, collection.Add(menuItem1)); Assert.Same(menuItem1, Assert.Single(collection)); Assert.Equal(menu, menuItem1.Parent); Assert.Equal(0, menuItem1.Index); var menuItem2 = new MenuItem("text2"); Assert.Equal(1, collection.Add(menuItem2)); Assert.Equal(2, collection.Count); Assert.Same(menuItem1, collection[0]); Assert.Same(menuItem2, collection[1]); Assert.Equal(menu, menuItem1.Parent); Assert.Equal(0, menuItem1.Index); Assert.Equal(menu, menuItem2.Parent); Assert.Equal(1, menuItem2.Index); } }
public void MenuItemCollection_Add_AlreadyInSameCollection_Success() { var menuItem1 = new MenuItem(); var menuItem2 = new MenuItem(); var parent = new MenuItem("text", new MenuItem[0]); var collection = new Menu.MenuItemCollection(parent); collection.Add(menuItem1); collection.Add(menuItem2); Assert.Equal(0, collection.Add(0, menuItem2)); Assert.Equal(2, collection.Count); Assert.Same(menuItem2, collection[0]); Assert.Same(menuItem1, collection[1]); Assert.Equal(parent, menuItem1.Parent); Assert.Equal(1, menuItem1.Index); Assert.Equal(parent, menuItem2.Parent); Assert.Equal(0, menuItem2.Index); Assert.Equal(1, collection.Add(2, menuItem2)); Assert.Equal(2, collection.Count); Assert.Same(menuItem1, collection[0]); Assert.Same(menuItem2, collection[1]); Assert.Equal(parent, menuItem1.Parent); Assert.Equal(0, menuItem1.Index); Assert.Equal(parent, menuItem2.Parent); Assert.Equal(1, menuItem2.Index); }
public void MenuItemCollection_Add_NullMenuItem_ThrowsArgumentNullException() { var menu = new SubMenu(new MenuItem[0]); var collection = new Menu.MenuItemCollection(menu); Assert.Throws <ArgumentNullException>("item", () => collection.Add((MenuItem)null)); Assert.Throws <ArgumentNullException>("item", () => collection.Add(0, null)); }
public void MenuItemCollection_Add_AlreadyInCollection_InvalidIndex_ThrowsArgumentOutOfRangeException(int index) { var menuItem = new MenuItem(); var parent = new MenuItem("text", new MenuItem[0]); var collection = new Menu.MenuItemCollection(parent); collection.Add(menuItem); Assert.Throws <ArgumentOutOfRangeException>("index", () => collection.Add(index, menuItem)); }
public void MenuItemCollection_Add_IListNotMenuItem_ThrowsArgumentException(object value) { var menu = new SubMenu(new MenuItem[0]); IList collection = new Menu.MenuItemCollection(menu); Assert.Throws <ArgumentException>("value", () => collection.Add(value)); }
public void MenuItemCollection_Add_InvalidIndex_ThrowsArgumentOutOfRangeException(int index) { var menu = new SubMenu(new MenuItem[0]); var collection = new Menu.MenuItemCollection(menu); Assert.Throws <ArgumentOutOfRangeException>("index", () => collection.Add(index, new MenuItem())); }
public void MenuItemCollection_Add_SelfWithParent_ThrowsArgumentException() { var menuItem = new MenuItem("text", new MenuItem[0]); var parent = new MenuItem("parent", new MenuItem[] { menuItem }); var collection = new Menu.MenuItemCollection(menuItem); Assert.Throws <ArgumentException>("item", () => collection.Add(menuItem)); }
public void MenuItemCollection_Add_ParentWithGrandparent_ThrowsArgumentException() { var menuItem = new MenuItem(); var parent = new MenuItem("parent", new MenuItem[] { menuItem }); var grandparent = new MenuItem("grandparent", new MenuItem[] { parent }); var oldCollection = new Menu.MenuItemCollection(menuItem); Assert.Throws <ArgumentException>("item", () => oldCollection.Add(parent)); }
public void MenuItemCollection_Add_StringMenuItemArray_Success(string caption, MenuItem[] items) { var menu = new SubMenu(new MenuItem[0]); var collection = new Menu.MenuItemCollection(menu); MenuItem menuItem = collection.Add(caption, items); Assert.Same(menuItem, Assert.Single(collection)); Assert.Equal(caption ?? string.Empty, menuItem.Text); Assert.Equal(items ?? new MenuItem[0], menuItem.MenuItems.Cast <MenuItem>()); Assert.Equal(menu, menuItem.Parent); Assert.Equal(0, menuItem.Index); }
public void MenuItemCollection_Add_StringEventHandler_Success(string caption, EventHandler onClick) { var menu = new SubMenu(new MenuItem[0]); var collection = new Menu.MenuItemCollection(menu); MenuItem menuItem = collection.Add(caption, onClick); Assert.Same(menuItem, Assert.Single(collection)); Assert.Equal(caption ?? string.Empty, menuItem.Text); Assert.Empty(menuItem.MenuItems); Assert.Equal(menu, menuItem.Parent); Assert.Equal(0, menuItem.Index); }
public void MenuItemCollection_CopyTo_NotEmpty_Success() { var menuItem = new MenuItem(); var menu = new SubMenu(new MenuItem[0]); var collection = new Menu.MenuItemCollection(menu); collection.Add(menuItem); var array = new object[] { 1, 2, 3 }; collection.CopyTo(array, 1); Assert.Equal(new object[] { 1, menuItem, 3 }, array); }
public void MenuItemCollection_Add_IListMenuItem_Success() { var menu = new SubMenu(new MenuItem[0]); IList collection = new Menu.MenuItemCollection(menu); var menuItem1 = new MenuItem("text1"); Assert.Equal(0, collection.Add(menuItem1)); Assert.Same(menuItem1, Assert.Single(collection)); Assert.Equal(menu, menuItem1.Parent); Assert.Equal(0, menuItem1.Index); var menuItem2 = new MenuItem("text2"); Assert.Equal(1, collection.Add(menuItem2)); Assert.Equal(2, collection.Count); Assert.Same(menuItem1, collection[0]); Assert.Same(menuItem2, collection[1]); Assert.Equal(menu, menuItem1.Parent); Assert.Equal(0, menuItem1.Index); Assert.Equal(menu, menuItem2.Parent); Assert.Equal(1, menuItem2.Index); }
public void MenuItemCollection_Add_CreatedMenuItemToMenu_Success() { var menuItem = new MenuItem("text1"); using (var otherMenu = new SubMenu(new MenuItem[] { menuItem })) { Assert.NotEqual(IntPtr.Zero, otherMenu.Handle); var menu = new SubMenu(new MenuItem[0]); var collection = new Menu.MenuItemCollection(menu); Assert.Equal(0, collection.Add(menuItem)); Assert.Same(menuItem, Assert.Single(collection)); Assert.Equal(menu, menuItem.Parent); Assert.Equal(0, menuItem.Index); } }
public void MenuItemCollection_Add_AlreadyInDifferentCollection_Success() { var oldParent = new MenuItem("text", new MenuItem[0]); var oldCollection = new Menu.MenuItemCollection(oldParent); var newParent = new MenuItem("text", new MenuItem[0]); var newCollection = new Menu.MenuItemCollection(newParent); var menuItem = new MenuItem(); oldCollection.Add(menuItem); Assert.Equal(0, newCollection.Add(menuItem)); Assert.Empty(oldCollection); Assert.Same(menuItem, Assert.Single(newCollection)); Assert.Equal(newParent, menuItem.Parent); Assert.Equal(0, menuItem.Index); }
private void m_CreateMenuInfo(Menu owner) { m_Language = m_GetLanguageFromCulture(HathiForm.preferences.GetString("Language")); m_ShowAllLanguage = HathiForm.preferences.GetBool("ShowAllLanguages",true); m_Owner = owner; Actions=new Hashtable(); MenuItems=new Menu.MenuItemCollection(owner); MenuItem menu; try { ShowAllLanguageMenuItem = new MenuItem(HathiForm.Globalization["LBL_SHOW_ALL_LANGUAGES"],new EventHandler(ShowAllLanguageMenuItem_Click)); ShowAllLanguageMenuItem.DefaultItem = true; ShowAllLanguageMenuItem.Checked = m_ShowAllLanguage; MenuItems.Add(ShowAllLanguageMenuItem); menu=new MenuItem("-"); MenuItems.Add(menu); XmlDocument doc = new XmlDocument(); doc.Load(Application.StartupPath + Path.DirectorySeparatorChar + "webSearchs.xml"); XmlNodeList nodes = doc.DocumentElement["Searchs"].ChildNodes; foreach (XmlElement el in nodes) { if (el.Name=="Search") { if ((el.Attributes.Count>2) && (el.Attributes["SiteName"].InnerText!="")&& (el.Attributes["URL"].InnerText!="")&& (el.Attributes["Language"].InnerText!="")) { String NodeLanguage = el.Attributes["Language"].InnerText; if (!m_ShowAllLanguage && NodeLanguage!=m_Language && NodeLanguage!="All") { m_DisplayBar = false; } else { m_DisplayBar = true; menu=new MenuItem(el.Attributes["SiteName"].InnerText+"\t("+el.Attributes["Language"].InnerText+")",new EventHandler(OnItemClicked)); MenuItems.Add(menu); Actions.Add(menu,el.Attributes["URL"].InnerText); } } else if (m_DisplayBar && el.Attributes["SiteName"].InnerText=="-") { menu=new MenuItem("-"); MenuItems.Add(menu); } } } if (MenuItems[MenuItems.Count-1].Text=="-") MenuItems.RemoveAt(MenuItems.Count-1); } catch (Exception e) { Debug.WriteLine(e.ToString()); } }