Exemplo n.º 1
0
        public void Dispose_UnsubscribesFromEventsAndDisposesAggregrator()
        {
            var aggregatorMock = new Mock <ITagAggregator <TrackedTag> >();

            aggregatorMock.SetupAdd(x => x.BatchedTagsChanged += (sender, args) => { });

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

            testSubject.Dispose();

            aggregatorMock.VerifyRemove(x => x.BatchedTagsChanged -= It.IsAny <EventHandler <BatchedTagsChangedEventArgs> >(), Times.Once);
            aggregatorMock.Verify(x => x.Dispose(), Times.Once);
        }
Exemplo n.º 2
0
        public void GetTags_WhenDisposed_ReturnsEmpty()
        {
            // See issue #1693: Object disposed exception thrown by tagger
            // https://github.com/SonarSource/sonarlint-visualstudio/issues/1693
            var aggregatorMock = new Mock <ITagAggregator <TrackedTag> >();

            aggregatorMock.Setup(x => x.GetTags(It.IsAny <NormalizedSnapshotSpanCollection>()))
            .Throws(new ObjectDisposedException("this is a test"));

            var snapshot   = CreateSnapshot(length: 100);
            var inputSpan  = new Span(20, 10);
            var inputSpans = new NormalizedSnapshotSpanCollection(snapshot, inputSpan);

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

            testSubject.Dispose();

            using (new AssertIgnoreScope())
            {
                var actual = testSubject.GetTags(inputSpans).ToArray();
                actual.Should().BeEmpty();
            }
        }