Esempio n. 1
0
        public void ContextMenu_ProcessCmdKey_HasItemWithShoutcutKey_ReturnsExpected(MenuItem menuItem, bool expectedResult, int expectedOnClickCallCount, int expectedOnPopupCallCount)
        {
            var control          = new Control();
            int onClickCallCount = 0;

            menuItem.Click += (sender, e) =>
            {
                onClickCallCount++;
                Assert.Same(menuItem, sender);
                Assert.Equal(EventArgs.Empty, e);
            };

            int onPopupCallCount = 0;

            menuItem.Popup += (sender, e) =>
            {
                onPopupCallCount++;
                Assert.Same(menuItem, sender);
                Assert.Equal(EventArgs.Empty, e);
            };

            var menu    = new ContextMenu(new MenuItem[] { menuItem });
            var message = new Message();

            Assert.Equal(expectedResult, menu.ProcessCmdKey(ref message, Keys.Control | Keys.A, control));
            Assert.Same(control, menu.SourceControl);
            Assert.Equal(expectedOnClickCallCount, onClickCallCount);
            Assert.Equal(expectedOnPopupCallCount, onPopupCallCount);
        }