Ejemplo n.º 1
0
        public void MergeOnlyOneClickEventSubscribed()
        {
            using (MessageTest messageTest = new MessageTest())
            {
                messageTest.m_nFirstOneClicked  = 0;
                messageTest.m_nSecondOneClicked = 0;

                MenuExtender menuExtender = new MenuExtender();
                menuExtender.MessageMediator = new Mediator();
                menuExtender.MessageMediator.AddColleague(messageTest);

                MainMenu first    = new MainMenu();
                MenuItem firstOne = new MenuItem("FirstOne");
                first.MenuItems.Add(new MenuItem(MenuMerge.MergeItems, 0, Shortcut.None, "First", null,
                                                 null, null, new MenuItem[] { firstOne }));
                menuExtender.SetCommandId(firstOne, "FirstOne");

                MainMenu second    = new MainMenu();
                MenuItem secondOne = new MenuItem("SecondOne");
                second.MenuItems.Add(new MenuItem(MenuMerge.MergeItems, 0, Shortcut.None, "Second", null,
                                                  null, null, new MenuItem[] { secondOne }));
                menuExtender.SetCommandId(secondOne, "SecondOne");

                MainMenu result = menuExtender.MergeMenus(first, second);
                result.MenuItems[0].MenuItems[0].PerformClick();
                result.MenuItems[0].MenuItems[1].PerformClick();

                Assert.AreEqual(1, messageTest.m_nFirstOneClicked);
                Assert.AreEqual(1, messageTest.m_nSecondOneClicked);
                // Clean up the mess now.
                menuExtender.MessageMediator.RemoveColleague(messageTest);
                menuExtender.MessageMediator.Dispose();
                menuExtender.MessageMediator = null;
            }
        }
Ejemplo n.º 2
0
        public void Merge2MenusLargerSecondMenu()
        {
            MainMenu first = new MainMenu();

            first.MenuItems.Add(new MenuItem(MenuMerge.MergeItems, 0, Shortcut.None, "First", null,
                                             null, null, new MenuItem[] { new MenuItem("FirstOne") }));

            MainMenu second = new MainMenu();

            second.MenuItems.Add(new MenuItem(MenuMerge.MergeItems, 0, Shortcut.None, "Second", null,
                                              null, null, new MenuItem[] { new MenuItem("SecondOne") }));
            second.MenuItems.Add(new MenuItem(MenuMerge.MergeItems, 1, Shortcut.None, "Second2", null,
                                              null, null, new MenuItem[] { new MenuItem("Second2One") }));

            MenuExtender menuExtender = new MenuExtender();
            MainMenu     result       = menuExtender.MergeMenus(first, second);

            Assert.AreEqual(2, result.MenuItems.Count);
            Assert.AreEqual("First", result.MenuItems[0].Text);
            Assert.AreEqual("Second2", result.MenuItems[1].Text);
            Assert.AreEqual(2, result.MenuItems[0].MenuItems.Count);
            Assert.AreEqual("FirstOne", result.MenuItems[0].MenuItems[0].Text);
            Assert.AreEqual("SecondOne", result.MenuItems[0].MenuItems[1].Text);
            Assert.AreEqual(1, result.MenuItems[1].MenuItems.Count);
            Assert.AreEqual("Second2One", result.MenuItems[1].MenuItems[0].Text);
        }
Ejemplo n.º 3
0
        public void Add2MenuItemsMergeOrderSetOn2ndMenu()
        {
            MainMenu first = new MainMenu();

            first.MenuItems.Add(new MenuItem(MenuMerge.Add, 1, Shortcut.None, "First", null,
                                             null, null, null));

            MainMenu second = new MainMenu();

            second.MenuItems.Add(new MenuItem(MenuMerge.Add, 0, Shortcut.None, "Second", null,
                                              null, null, null));

            MenuExtender menuExtender = new MenuExtender();
            MainMenu     result       = menuExtender.MergeMenus(first, second);

            Assert.AreEqual(2, result.MenuItems.Count);
            Assert.AreEqual("Second", result.MenuItems[0].Text);
            Assert.AreEqual("First", result.MenuItems[1].Text);
        }