public void PointerExited_Doesnt_Deselect_Item_If_Pointer_Over_Submenu()
            {
                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 && x.HasSubMenu == true && x.IsPointerOverSubMenu == true);
                var e          = CreateArgs(MenuItem.PointerExitedItemEvent, item);

                target.PointerExited(item, e);

                Mock.Get(parentItem).VerifySet(x => x.SelectedItem = null, Times.Never);
                Assert.False(e.Handled);
            }
            public void PointerExited_Deselects_Item_When_Menu_Not_Open()
            {
                var target = new DefaultMenuInteractionHandler(false);
                var menu   = new Mock <IMenu>();
                var item   = Mock.Of <IMenuItem>(x => x.IsTopLevel == true && x.Parent == menu.Object);
                var e      = CreateArgs(MenuItem.PointerExitedItemEvent, item);

                menu.SetupGet(x => x.SelectedItem).Returns(item);
                target.PointerExited(item, e);

                menu.VerifySet(x => x.SelectedItem = null);
                Assert.False(e.Handled);
            }
            public void PointerExited_Deselects_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.PointerExitedItemEvent, item);

                Mock.Get(parentItem).SetupGet(x => x.SelectedItem).Returns(item);
                target.PointerExited(item, e);

                Mock.Get(parentItem).VerifySet(x => x.SelectedItem = null);
                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();
            }