Beispiel #1
0
        public void TestInsertAtOfMultiItems()
        {
            var contextMenuStripFirst      = new ContextMenuStrip();
            var contextMenuStripSecond     = new ContextMenuStrip();
            var clonableToolStripMenuItem1 = new ClonableToolStripMenuItem {
                Text = "item1"
            };
            var clonableToolStripMenuItem2 = new ClonableToolStripMenuItem {
                Text = "item2"
            };
            var clonableToolStripMenuItem3 = new ClonableToolStripMenuItem {
                Text = "item3"
            };

            contextMenuStripFirst.Items.Add(clonableToolStripMenuItem1);
            contextMenuStripFirst.Items.Add(clonableToolStripMenuItem2);

            contextMenuStripSecond.Items.Add(clonableToolStripMenuItem3);

            var menuItemContextMenuStripAdapter1 = new MenuItemContextMenuStripAdapter(contextMenuStripFirst);
            var menuItemContextMenuStripAdapter2 = new MenuItemContextMenuStripAdapter(contextMenuStripSecond);

            menuItemContextMenuStripAdapter2.Insert(0, menuItemContextMenuStripAdapter1);

            var contextMenuStripMerged = menuItemContextMenuStripAdapter2.ContextMenuStrip;

            Assert.AreEqual(3, contextMenuStripMerged.Items.Count);
            Assert.AreEqual("item1", contextMenuStripMerged.Items[0].Text);
            Assert.AreEqual("item2", contextMenuStripMerged.Items[1].Text);
            Assert.AreEqual("item3", contextMenuStripMerged.Items[2].Text);
        }
Beispiel #2
0
        public void TestAdapterCloningForEventHandling()
        {
            ContextMenuStrip contextMenuStripFirst = new ContextMenuStrip();

            ContextMenuStrip          contextMenuStripSecond    = new ContextMenuStrip();
            ClonableToolStripMenuItem clonableToolStripMenuItem = new ClonableToolStripMenuItem {
                Text = "item1"
            };

            contextMenuStripSecond.Items.Add(clonableToolStripMenuItem);

            int counter = 0;

            clonableToolStripMenuItem.CheckedChanged += (o, e) => { counter++; };

            MenuItemContextMenuStripAdapter menuItemContextMenuStripAdapter = new MenuItemContextMenuStripAdapter(contextMenuStripFirst);

            // Add items from second menu to first menu
            menuItemContextMenuStripAdapter.Add(new MenuItemContextMenuStripAdapter(contextMenuStripSecond));

            Assert.AreEqual(1, contextMenuStripFirst.Items.Count);
            Assert.AreEqual(1, contextMenuStripSecond.Items.Count);

            // Both event should call the same eventhandler and thus increment the same counter var.
            ((ToolStripMenuItem)contextMenuStripFirst.Items[0]).Checked = !(((ToolStripMenuItem)contextMenuStripFirst.Items[0]).Checked);
            Assert.AreEqual(1, counter);
            ((ToolStripMenuItem)contextMenuStripSecond.Items[0]).Checked = !(((ToolStripMenuItem)contextMenuStripSecond.Items[0]).Checked);
            Assert.AreEqual(2, counter);
        }
Beispiel #3
0
        public void TestIndexOf()
        {
            var contextMenuStrip  = new ContextMenuStrip();
            var toolStripMenuItem = new ToolStripMenuItem()
            {
                Text = "item1", Name = "item1"
            };
            var clonableToolStripMenuItem1 = new ClonableToolStripMenuItem {
                Text = "item2"
            };
            var clonableToolStripMenuItem2 = new ClonableToolStripMenuItem {
                Text = "item3", Name = "item3"
            };

            contextMenuStrip.Items.Add(toolStripMenuItem);
            contextMenuStrip.Items.Add(clonableToolStripMenuItem1);
            contextMenuStrip.Items.Add(clonableToolStripMenuItem2);

            var menuItemContextMenuStripAdapter = new MenuItemContextMenuStripAdapter(contextMenuStrip);

            Assert.AreEqual(0, menuItemContextMenuStripAdapter.IndexOf("item1"));
            Assert.AreEqual(2, menuItemContextMenuStripAdapter.IndexOf("item3"));
            Assert.AreEqual(-1, menuItemContextMenuStripAdapter.IndexOf("haha"));
        }
        public void TestIndexOf()
        {
            var contextMenuStrip = new ContextMenuStrip();
            var toolStripMenuItem = new ToolStripMenuItem() { Text = "item1", Name = "item1"};
            var clonableToolStripMenuItem1 = new ClonableToolStripMenuItem { Text = "item2" };
            var clonableToolStripMenuItem2 = new ClonableToolStripMenuItem { Text = "item3", Name = "item3" };

            contextMenuStrip.Items.Add(toolStripMenuItem);
            contextMenuStrip.Items.Add(clonableToolStripMenuItem1);
            contextMenuStrip.Items.Add(clonableToolStripMenuItem2);

            var menuItemContextMenuStripAdapter = new MenuItemContextMenuStripAdapter(contextMenuStrip);

            Assert.AreEqual(0, menuItemContextMenuStripAdapter.IndexOf("item1"));
            Assert.AreEqual(2, menuItemContextMenuStripAdapter.IndexOf("item3"));
            Assert.AreEqual(-1, menuItemContextMenuStripAdapter.IndexOf("haha"));

        }
        public void TestInsertAtOfMultiItems()
        {
            var contextMenuStripFirst = new ContextMenuStrip();
            var contextMenuStripSecond = new ContextMenuStrip();
            var clonableToolStripMenuItem1 = new ClonableToolStripMenuItem { Text = "item1" };
            var clonableToolStripMenuItem2 = new ClonableToolStripMenuItem { Text = "item2" };
            var clonableToolStripMenuItem3 = new ClonableToolStripMenuItem { Text = "item3" };
            
            contextMenuStripFirst.Items.Add(clonableToolStripMenuItem1);
            contextMenuStripFirst.Items.Add(clonableToolStripMenuItem2);

            contextMenuStripSecond.Items.Add(clonableToolStripMenuItem3);

            var menuItemContextMenuStripAdapter1 = new MenuItemContextMenuStripAdapter(contextMenuStripFirst);
            var menuItemContextMenuStripAdapter2 = new MenuItemContextMenuStripAdapter(contextMenuStripSecond);

            menuItemContextMenuStripAdapter2.Insert(0, menuItemContextMenuStripAdapter1);

            var contextMenuStripMerged = menuItemContextMenuStripAdapter2.ContextMenuStrip;

            Assert.AreEqual(3, contextMenuStripMerged.Items.Count);
            Assert.AreEqual("item1", contextMenuStripMerged.Items[0].Text);
            Assert.AreEqual("item2", contextMenuStripMerged.Items[1].Text);
            Assert.AreEqual("item3", contextMenuStripMerged.Items[2].Text);
        }
        public void TestAdapterCloningForEventHandling()
        {
            ContextMenuStrip contextMenuStripFirst = new ContextMenuStrip();

            ContextMenuStrip contextMenuStripSecond = new ContextMenuStrip();
            ClonableToolStripMenuItem clonableToolStripMenuItem = new ClonableToolStripMenuItem { Text = "item1" };
            contextMenuStripSecond.Items.Add(clonableToolStripMenuItem);

            int counter = 0;
            clonableToolStripMenuItem.CheckedChanged += (o, e) => { counter++; };

            MenuItemContextMenuStripAdapter menuItemContextMenuStripAdapter = new MenuItemContextMenuStripAdapter(contextMenuStripFirst);
            // Add items from second menu to first menu
            menuItemContextMenuStripAdapter.Add(new MenuItemContextMenuStripAdapter(contextMenuStripSecond));

            Assert.AreEqual(1, contextMenuStripFirst.Items.Count);
            Assert.AreEqual(1, contextMenuStripSecond.Items.Count);

            // Both event should call the same eventhandler and thus increment the same counter var.
            ((ToolStripMenuItem)contextMenuStripFirst.Items[0]).Checked = !(((ToolStripMenuItem)contextMenuStripFirst.Items[0]).Checked);
            Assert.AreEqual(1, counter);
            ((ToolStripMenuItem)contextMenuStripSecond.Items[0]).Checked = !(((ToolStripMenuItem)contextMenuStripSecond.Items[0]).Checked);
            Assert.AreEqual(2, counter);
        }