public void PointerEntered_Opens_Item_When_Old_Item_Is_Open()
            {
                var target = new DefaultMenuInteractionHandler(false);
                var menu   = new Mock <IMenu>();
                var item   = Mock.Of <IMenuItem>(x =>
                                                 x.IsSubMenuOpen == true &&
                                                 x.IsTopLevel == true &&
                                                 x.HasSubMenu == true &&
                                                 x.Parent == menu.Object);
                var nextItem = Mock.Of <IMenuItem>(x =>
                                                   x.IsTopLevel == true &&
                                                   x.HasSubMenu == true &&
                                                   x.Parent == menu.Object);
                var e = CreateArgs(MenuItem.PointerEnteredItemEvent, nextItem);

                menu.SetupGet(x => x.SelectedItem).Returns(item);

                target.PointerEntered(nextItem, e);

                Mock.Get(item).Verify(x => x.Close());
                menu.VerifySet(x => x.SelectedItem = nextItem);
                Mock.Get(nextItem).Verify(x => x.Open());
                Mock.Get(nextItem).Verify(x => x.MoveSelection(NavigationDirection.First, true), Times.Never);
                Assert.False(e.Handled);
            }
            public void PointerEntered_Selects_Item()
            {
                var target     = new DefaultMenuInteractionHandler(false);
                var menu       = Mock.Of <IMenu>();
                var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu);
                var item       = Mock.Of <IMenuItem>(x => x.Parent == parentItem);
                var e          = CreateArgs(MenuItem.PointerEnteredItemEvent, item);

                target.PointerEntered(item, e);

                Mock.Get(parentItem).VerifySet(x => x.SelectedItem = item);
                Assert.False(e.Handled);
            }
            public void Selection_Is_Correct_When_Pointer_Temporarily_Exits_Item_To_Select_SubItem()
            {
                var timer      = new TestTimer();
                var target     = new DefaultMenuInteractionHandler(false, null, timer.RunOnce);
                var menu       = Mock.Of <IMenu>();
                var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu);
                var item       = Mock.Of <IMenuItem>(x => x.Parent == parentItem && x.HasSubMenu == true);
                var childItem  = Mock.Of <IMenuItem>(x => x.Parent == item);
                var enter      = CreateArgs(MenuItem.PointerEnteredItemEvent, item);
                var leave      = CreateArgs(MenuItem.PointerExitedItemEvent, item);

                // Pointer enters item; item is selected.
                target.PointerEntered(item, enter);
                Assert.True(timer.ActionIsQueued);
                Mock.Get(parentItem).VerifySet(x => x.SelectedItem = item);
                Mock.Get(parentItem).Invocations.Clear();

                // SubMenu shown after a delay.
                timer.Pulse();
                Mock.Get(item).Verify(x => x.Open());
                Mock.Get(item).SetupGet(x => x.IsSubMenuOpen).Returns(true);
                Mock.Get(item).Invocations.Clear();

                // Pointer briefly exits item, but submenu remains open.
                target.PointerExited(item, leave);
                Mock.Get(item).Verify(x => x.Close(), Times.Never);
                Mock.Get(item).Invocations.Clear();

                // Pointer enters child item; is selected.
                enter.Source = childItem;
                target.PointerEntered(childItem, enter);
                Mock.Get(item).VerifySet(x => x.SelectedItem       = childItem);
                Mock.Get(parentItem).VerifySet(x => x.SelectedItem = item);
                Mock.Get(item).Invocations.Clear();
                Mock.Get(parentItem).Invocations.Clear();
            }
            public void PointerEntered_Opens_Submenu_After_Delay()
            {
                var timer      = new TestTimer();
                var target     = new DefaultMenuInteractionHandler(false, null, timer.RunOnce);
                var menu       = Mock.Of <IMenu>();
                var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu);
                var item       = Mock.Of <IMenuItem>(x => x.Parent == parentItem && x.HasSubMenu == true);
                var e          = CreateArgs(MenuItem.PointerEnteredItemEvent, item);

                target.PointerEntered(item, e);
                Mock.Get(item).Verify(x => x.Open(), Times.Never);

                timer.Pulse();
                Mock.Get(item).Verify(x => x.Open());

                Assert.False(e.Handled);
            }
            public void PointerEntered_Closes_Sibling_Submenu_After_Delay()
            {
                var timer      = new TestTimer();
                var target     = new DefaultMenuInteractionHandler(false, null, timer.RunOnce);
                var menu       = Mock.Of <IMenu>();
                var parentItem = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.HasSubMenu == true && x.Parent == menu);
                var item       = Mock.Of <IMenuItem>(x => x.Parent == parentItem);
                var sibling    = Mock.Of <IMenuItem>(x => x.Parent == parentItem && x.HasSubMenu == true && x.IsSubMenuOpen == true);
                var e          = CreateArgs(MenuItem.PointerEnteredItemEvent, item);

                Mock.Get(parentItem).SetupGet(x => x.SubItems).Returns(new[] { item, sibling });

                target.PointerEntered(item, e);
                Mock.Get(sibling).Verify(x => x.Close(), Times.Never);

                timer.Pulse();
                Mock.Get(sibling).Verify(x => x.Close());

                Assert.False(e.Handled);
            }