public void OnIssuesChanged_BufferFileIsChanged_TagsChangedIsRaisedWithAffectedSpan()
        {
            var buffer    = CreateBufferMock(filePath: ValidBufferDocName);
            var oldIssue1 = CreateLocViz(new SnapshotSpan(buffer.Object.CurrentSnapshot, 3, 1));
            var oldIssue2 = CreateLocViz(new SnapshotSpan(buffer.Object.CurrentSnapshot, 20, 2));
            var oldIssues = new[] { oldIssue1, oldIssue2 };

            var storeMock = new Mock <IIssueLocationStore>();

            storeMock.Setup(x => x.GetLocations(ValidBufferDocName)).Returns(oldIssues);

            var testSubject = new LocationTagger(buffer.Object, storeMock.Object, ValidSpanCalculator, ValidLogger);

            var newIssue1 = CreateLocViz(new SnapshotSpan(buffer.Object.CurrentSnapshot, 15, 10));
            var newIssue2 = CreateLocViz(new SnapshotSpan(buffer.Object.CurrentSnapshot, 25, 5));
            var newIssues = new[] { newIssue1, newIssue2 };

            storeMock.Setup(x => x.GetLocations(ValidBufferDocName)).Returns(newIssues);

            SnapshotSpanEventArgs actualTagsChangedArgs = null;

            testSubject.TagsChanged += (senders, args) => actualTagsChangedArgs = args;

            RaiseIssuesChangedEvent(storeMock, ValidBufferDocName);

            actualTagsChangedArgs.Should().NotBeNull();
            actualTagsChangedArgs.Span.Start.Position.Should().Be(3); // oldIssue1.Start
            actualTagsChangedArgs.Span.End.Position.Should().Be(30);  // newIssue2.Start + newIssue2.Length
        }
Ejemplo n.º 2
0
        private void VerifyTagsRaisedWithCorrectAffectedSpan(Span[] tagSpans, Span deletedSpans, Span expectedAffectedSpan, int bufferLength = 100)
        {
            const string validBufferDocName = "a.cpp";

            var buffer = CreateBufferMock(bufferLength, validBufferDocName);

            var(beforeSnapshot, afterSnapshot) = CreateSnapshotChange(buffer.Object, bufferLength, deletedSpans);

            var locations = tagSpans.Select(span => CreateLocationViz(beforeSnapshot, span));
            var store     = CreateLocationStore(validBufferDocName, locations.ToArray());

            var testSubject = CreateTestSubject(buffer.Object, store);

            SnapshotSpanEventArgs actualTagsChangedArgs = null;

            testSubject.TagsChanged += (sender, args) => actualTagsChangedArgs = args;

            RaiseBufferChangedEvent(buffer, beforeSnapshot, afterSnapshot);

            // TagsChanged event should have been raised
            actualTagsChangedArgs.Should().NotBeNull();
            actualTagsChangedArgs.Span.Start.Position.Should().Be(expectedAffectedSpan.Start);
            actualTagsChangedArgs.Span.End.Position.Should().Be(expectedAffectedSpan.End);

            // Location store should have been notified
            CheckStoreRefreshWasCalled(store, validBufferDocName);
        }
Ejemplo n.º 3
0
        public void OnAggregatorTagsChanged_NotifiesEditorOfChange()
        {
            var aggregatorMock = new Mock <ITagAggregator <TrackedTag> >();

            var testSubject = new TestableFilteringTagger(aggregatorMock.Object, ValidBuffer);

            SnapshotSpanEventArgs suppliedArgs = null;
            int          eventCount            = 0;
            SnapshotSpan expectedSnapshotSpan  = new SnapshotSpan(ValidBuffer.CurrentSnapshot, new Span(0, ValidBuffer.CurrentSnapshot.Length));

            testSubject.TagsChanged += (sender, args) => { eventCount++; suppliedArgs = args; };

            // Act
            aggregatorMock.Raise(x => x.BatchedTagsChanged += null, new BatchedTagsChangedEventArgs(Array.Empty <IMappingSpan>()));

            eventCount.Should().Be(1);
            suppliedArgs.Should().NotBeNull();
            suppliedArgs.Span.Should().Be(expectedSnapshotSpan);
        }
Ejemplo n.º 4
0
        public void OnSelectionChanged_ChangeLevelIsNotLocation_EditorIsNotified(SelectionChangeLevel changeLevel)
        {
            var selectionServiceMock = new Mock <IAnalysisIssueSelectionService>();
            var testSubject          = new SelectedIssueLocationTagger(ValidAggregator, ValidBuffer, selectionServiceMock.Object);

            var tagsChangedEventCount             = 0;
            SnapshotSpanEventArgs actualEventArgs = null;

            testSubject.TagsChanged += (sender, args) => { tagsChangedEventCount++; actualEventArgs = args; };

            // Act
            selectionServiceMock.Raise(x => x.SelectionChanged += null, new SelectionChangedEventArgs(changeLevel, null, null, null));

            tagsChangedEventCount.Should().Be(1);
            actualEventArgs.Should().NotBeNull();
            actualEventArgs.Span.Start.Position.Should().Be(0);
            actualEventArgs.Span.End.Position.Should().Be(ValidBuffer.CurrentSnapshot.Length);
            actualEventArgs.Span.Snapshot.Should().Be(ValidBuffer.CurrentSnapshot);
        }