Ejemplo n.º 1
0
        public void ShouldFirePrefixChangedIfPrefixChangedAndCurrentItemChangeIsRaised()
        {
            var    lookupItems  = LookupItemsMockUtils.MockLookupItemList(4);
            string actualPrefix = null;
            IEnumerable <ILookupItem> actualItems = null;

            _manager.OnPrefixChanged += (prefix, items) =>
            {
                actualPrefix = prefix;
                actualItems  = items;
            };

            _mockLookup.Setup(l => l.Prefix).Returns(() => "set");
            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(lookupItems);
            WhenCurrentItemChangedIsRaised(lookupItems[0]);
            const string expectedPrefix = "setM";

            _mockLookup.Setup(l => l.Prefix).Returns(() => expectedPrefix);
            var expectedItems = lookupItems.Take(2).ToList();

            _mockLookup.Setup(l => l.DisplayedItems).Returns(expectedItems);
            WhenCurrentItemChangedIsRaised(lookupItems[0]);

            Assert.AreEqual(expectedPrefix, actualPrefix);
            CollectionAssert.AreEqual(expectedItems, actualItems);
        }
Ejemplo n.º 2
0
        public void ShouldFireAppliedWhenItemIsCompletedAfterClose_TriggerClickWithSelectionChange()
        {
            var         lookupItems       = LookupItemsMockUtils.MockLookupItemList(4);
            var         invocations       = 0;
            var         detectedTrigger   = default(EventTrigger);
            ILookupItem actualAppliedItem = null;

            _manager.OnApplied += (trigger, item) =>
            {
                invocations++;
                detectedTrigger   = trigger;
                actualAppliedItem = item;
            };

            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(lookupItems);
            WhenClosedIsRaised();
            WhenMouseDownIsRaised();
            WhenCurrentItemChangedIsRaised(lookupItems[1]);
            WhenItemCompletedIsRaised(lookupItems[1]);

            Assert.AreEqual(1, invocations);
            Assert.AreEqual(EventTrigger.Click, detectedTrigger);
            Assert.AreEqual(lookupItems[1], actualAppliedItem);
        }
Ejemplo n.º 3
0
 private void SetUpLookup()
 {
     _mockLookup = new Mock <IExtendedLookup>();
     _mockLookup.Setup(l => l.DisplayedItems).Returns(LookupItemsMockUtils.MockLookupItemList(3));
     _mockLookupWindowManager = new Mock <IExtendedLookupWindowManager>();
     _mockLookupWindowManager.Setup(m => m.CurrentLookup).Returns(_mockLookup.Object);
 }
Ejemplo n.º 4
0
        public void SetUpSubsequentCompletionEvents()
        {
            _proposalCollection = LookupItemsMockUtils.MockLookupItemList(5).ToProposalCollection();
            var now            = DateTime.Now;
            var activeWindow   = Names.Window("w testWindow");
            var activeDocument = Names.Document("d testDocument");

            _event = new CompletionEvent
            {
                IDESessionUUID     = "TestUUID",
                ActiveWindow       = activeWindow,
                ActiveDocument     = activeDocument,
                TriggeredAt        = now,
                ProposalCollection = _proposalCollection,
                TerminatedAt       = now.AddMilliseconds(100)
            };

            _subsequentEvent = new CompletionEvent
            {
                IDESessionUUID     = "TestUUID",
                ActiveWindow       = activeWindow,
                ActiveDocument     = activeDocument,
                TriggeredAt        = now.AddMilliseconds(200),
                ProposalCollection = new ProposalCollection(_proposalCollection.Proposals.Take(3).ToList()),
                TerminatedAt       = now.AddMilliseconds(300),
                TerminatedState    = TerminationState.Applied,
                TerminatedBy       = EventTrigger.Shortcut
            };
        }
Ejemplo n.º 5
0
        public void ShouldSetProposalCount(int testProposalCount)
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(testProposalCount);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandleClosed();
            _generator.HandleApplied(EventTrigger.Typing, lookupItems[1]);

            var completionEvent = GetSinglePublished <CompletionEvent>();

            Assert.AreEqual(testProposalCount, completionEvent.ProposalCount);
        }
Ejemplo n.º 6
0
        public void ShouldFireEventOnFilter()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(0);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandlePrefixChanged("a", lookupItems);

            var ce = GetSinglePublished <CompletionEvent>();

            Assert.AreEqual(TerminationState.Filtered, ce.TerminatedState);
            Assert.AreEqual(EventTrigger.Automatic, ce.TerminatedBy);
        }
Ejemplo n.º 7
0
        public void ShouldFireDisplayedItemsUpdatedWhenLookupItemsBecomeAvailable()
        {
            var expectedLookupItems = LookupItemsMockUtils.MockLookupItemList(4);
            IEnumerable <ILookupItem> actualLookupItems = null;

            _manager.DisplayedItemsUpdated += items => actualLookupItems = items;

            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(expectedLookupItems);

            CollectionAssert.AreEqual(expectedLookupItems, actualLookupItems);
        }
Ejemplo n.º 8
0
        public void ShouldHandleCodeCompletionWithCancellation()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(1);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandleClosed();
            _generator.HandleCancelled(EventTrigger.Shortcut);

            var ce = GetSinglePublished <CompletionEvent>();

            Assert.AreEqual(TerminationState.Cancelled, ce.TerminatedState);
        }
Ejemplo n.º 9
0
        public void ShouldCreateFollowupEventAfterFiltering()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(0);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandlePrefixChanged("a", lookupItems);
            _generator.HandleClosed();
            _generator.HandleCancelled(EventTrigger.Click);

            var ce = GetLastPublished <CompletionEvent>();

            Assert.AreEqual(EventTrigger.Automatic, ce.TriggeredBy);
        }
Ejemplo n.º 10
0
        public void ShouldNotAddSelectionToFollowupEventOnFilteringIfThereWasNoSelectionBefore()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(1);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandlePrefixChanged("a", lookupItems);
            _generator.HandleClosed();
            _generator.HandleCancelled(EventTrigger.Click);

            var ce = GetLastPublished <CompletionEvent>();

            Assert.IsTrue(ce.Selections.IsEmpty());
        }
Ejemplo n.º 11
0
        public void ShouldFireClosedWhenLookupIsClosed()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(4);
            var invocations = 0;

            _manager.OnClosed += () => invocations++;

            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(lookupItems);
            WhenClosedIsRaised();

            Assert.AreEqual(1, invocations);
        }
Ejemplo n.º 12
0
        public void ShouldHandleCodeCompletionWithApplication()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(3);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandleSelectionChanged(lookupItems[0]);
            _generator.HandleClosed();
            _generator.HandleApplied(EventTrigger.Click, lookupItems[0]);

            var ce = GetSinglePublished <CompletionEvent>();

            Assert.AreEqual(TerminationState.Applied, ce.TerminatedState);
        }
Ejemplo n.º 13
0
        public void ShouldNotDuplicateLastSelectionToFollowupEventOnFilteringIfLastSelectionWasFiltered()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(1);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandleSelectionChanged(lookupItems[0]);
            _generator.HandlePrefixChanged("a", new List <ILookupItem>());
            _generator.HandleClosed();
            _generator.HandleCancelled(EventTrigger.Click);

            var ce = GetLastPublished <CompletionEvent>();

            Assert.IsTrue(ce.Selections.IsEmpty());
        }
Ejemplo n.º 14
0
        public void ShouldOverrideProposalCollectionIfDisplayedItemsAreUpdated()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(4);
            var expected    = lookupItems.ToProposalCollection();

            _generator.HandleTriggered("", LookupItemsMockUtils.MockLookupItemList(1));
            _generator.HandleDisplayedItemsChanged(lookupItems);
            _generator.HandleClosed();
            _generator.HandleCancelled(EventTrigger.Click);

            var ce = GetLastPublished <CompletionEvent>();

            Assert.AreEqual(expected, ce.ProposalCollection);
        }
Ejemplo n.º 15
0
        public void ShouldNotFireSelectionChangedMultipleTimesWhenCurrentItemStaysTheSame()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(4);
            IList <ILookupItem> actualSelectedItems = new List <ILookupItem>();

            _manager.OnSelectionChanged += actualSelectedItems.Add;

            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(lookupItems);
            WhenCurrentItemChangedIsRaised(lookupItems[0]);
            WhenCurrentItemChangedIsRaised(lookupItems[0]);

            Assert.AreEqual(1, actualSelectedItems.Count);
        }
Ejemplo n.º 16
0
        public void ShouldSetIndexOfSelections()
        {
            const int testIndex   = 4;
            var       lookupItems = LookupItemsMockUtils.MockLookupItemList(5);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandleSelectionChanged(lookupItems[testIndex]);
            _generator.HandleClosed();
            _generator.HandleApplied(EventTrigger.Typing, lookupItems[1]);

            var actualEvent = GetSinglePublished <CompletionEvent>();

            Assert.AreEqual(testIndex, actualEvent.Selections[0].Index);
        }
Ejemplo n.º 17
0
        public void ShouldNotFirePrefixChangedIfPrefixDidNotChangedAndCurrentItemChangeIsRaised()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(4);
            var invokations = 0;

            _manager.OnPrefixChanged += (prefix, items) => invokations++;

            _mockLookup.Setup(l => l.Prefix).Returns(() => "set");
            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(lookupItems);
            WhenCurrentItemChangedIsRaised(lookupItems[0]);
            WhenCurrentItemChangedIsRaised(lookupItems[0]);

            Assert.AreEqual(0, invokations);
        }
Ejemplo n.º 18
0
        public void ShouldDuplicateLastSelectionToFollowupEventOnFiltering()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(1);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandleSelectionChanged(lookupItems[0]);
            _generator.HandlePrefixChanged("a", lookupItems);
            _generator.HandleClosed();
            _generator.HandleCancelled(EventTrigger.Click);

            var ce = GetLastPublished <CompletionEvent>();

            Assert.AreEqual(1, ce.Selections.Count);
            Assert.AreEqual(lookupItems[0].ToProposal(), ce.Selections[0].Proposal);
        }
Ejemplo n.º 19
0
        public void ShouldAddSelectionChangesToCompletionEvent()
        {
            var lookupItems = LookupItemsMockUtils.MockLookupItemList(5);

            _generator.HandleTriggered("", lookupItems);
            _generator.HandleSelectionChanged(lookupItems[3]);
            _generator.HandleSelectionChanged(lookupItems[2]);
            _generator.HandleSelectionChanged(lookupItems[1]);
            _generator.HandleClosed();
            _generator.HandleApplied(EventTrigger.Typing, lookupItems[1]);

            var ce = GetSinglePublished <CompletionEvent>();

            Assert.AreEqual(3, ce.Selections.Count);
            Assert.AreEqual(lookupItems[3].ToProposal(), ce.Selections[0].Proposal);
            Assert.AreEqual(lookupItems[2].ToProposal(), ce.Selections[1].Proposal);
            Assert.AreEqual(lookupItems[1].ToProposal(), ce.Selections[2].Proposal);
        }
Ejemplo n.º 20
0
        public void ShouldFireCancelledByUnknownTriggerAfterLookupIsClosedWhenItIsNotAppliedWithin10Seconds()
        {
            var lookupItems     = LookupItemsMockUtils.MockLookupItemList(4);
            var invocations     = 0;
            var detectedTrigger = default(EventTrigger);

            _manager.OnCancelled += trigger =>
            {
                invocations++;
                detectedTrigger = trigger;
            };

            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(lookupItems);
            WhenClosedIsRaised();

            Thread.Sleep(11000);

            Assert.AreEqual(1, invocations);
            Assert.AreEqual(EventTrigger.Unknown, detectedTrigger);
        }
Ejemplo n.º 21
0
        public void ShouldFireAppliedWhenItemIsCompletedAfterClose_TriggerTab()
        {
            var         lookupItems       = LookupItemsMockUtils.MockLookupItemList(4);
            var         invocations       = 0;
            var         detectedTrigger   = default(EventTrigger);
            ILookupItem actualAppliedItem = null;

            _manager.OnApplied += (trigger, item) =>
            {
                invocations++;
                detectedTrigger   = trigger;
                actualAppliedItem = item;
            };

            WhenBeforeLookupWindowShownIsRaised();
            WhenBeforeShownItemsUpdatedIsRaised(lookupItems);
            WhenActionIsExecuted(TabActionId);
            WhenClosedIsRaised();
            WhenItemCompletedIsRaised(lookupItems[0]);

            Assert.AreEqual(1, invocations);
            Assert.AreEqual(EventTrigger.Shortcut, detectedTrigger);
            Assert.AreEqual(lookupItems[0], actualAppliedItem);
        }