Ejemplo n.º 1
0
        public void GetClassificationSpansFromSnapShot(string pattern, string classification)
        {
            Settings.Load();
            var mockServiceProvider = new Mock <IServiceProvider>();
            var mockClassificationTypeRegistryService = new Mock <IClassificationTypeRegistryService>();

            mockClassificationTypeRegistryService
            .Setup(c => c.GetClassificationType(classification))
            .Returns(new Mock <IClassificationType>().Object);

            var outputClassifier = new OutputClassifier();

            outputClassifier.Initialize(mockClassificationTypeRegistryService.Object, null);
            var mockSnapshot     = new Mock <ITextSnapshot>();
            var mockSnapshotLine = new Mock <ITextSnapshotLine>();

            mockSnapshot.SetupGet(s => s.Length).Returns(1);
            mockSnapshot.Setup(s => s.GetLineFromPosition(0)).Returns(mockSnapshotLine.Object);
            mockSnapshot.Setup(s => s.GetLineFromLineNumber(0)).Returns(mockSnapshotLine.Object);
            mockSnapshot.Setup(s => s.GetText(It.IsAny <Span>())).Returns(pattern);

            mockSnapshotLine.SetupGet(l => l.Start).Returns(new SnapshotPoint(mockSnapshot.Object, 0));
            mockSnapshotLine.SetupGet(l => l.Length).Returns(1);
            mockSnapshotLine.SetupGet(l => l.LineNumber).Returns(0);
            mockSnapshotLine.SetupGet(l => l.Snapshot).Returns(mockSnapshot.Object);

            var snapshotSpan = new SnapshotSpan(mockSnapshot.Object, 0, 1);
            var spans        = outputClassifier.GetClassificationSpans(snapshotSpan);

            spans.Should().NotBeEmpty();
            mockSnapshot.VerifyAll();
            mockSnapshotLine.VerifyAll();
            mockServiceProvider.VerifyAll();
            mockClassificationTypeRegistryService.VerifyAll();
        }
Ejemplo n.º 2
0
        public void GetClassificationSpansNullSnapShot()
        {
            var outputClassifier = new OutputClassifier();

            outputClassifier.Initialize(null, null);
            outputClassifier.GetClassificationSpans(new SnapshotSpan()).Should().BeEmpty();
        }
        public void GetClassificationSpans_EmptyWhenNonMatchingSnapshot()
        {
            // Arrange
            var         classificationTypeRegistryServiceMock = new Mock <IClassificationTypeRegistryService>();
            IClassifier classifier = new OutputClassifier(classificationTypeRegistryServiceMock.Object);

            void ClassifierClassificationChanged(object sender, ClassificationChangedEventArgs args) => Assert.Fail("This shouldn't be invoked.");

            classifier.ClassificationChanged -= ClassifierClassificationChanged;
            classifier.ClassificationChanged += ClassifierClassificationChanged;
            const string text         = "foobar";
            var          span         = new Span(0, text.Length);
            var          snapshotMock = new Mock <ITextSnapshot>();

            snapshotMock.Setup(m => m.GetText(span)).Returns(text);
            snapshotMock.SetupGet(m => m.Length).Returns(text.Length);
            var snapshotSpan = new SnapshotSpan(snapshotMock.Object, span);

            // Act
            var spans = classifier.GetClassificationSpans(snapshotSpan);

            // Assert
            Assert.IsNotNull(spans);
            Assert.AreEqual(0, spans.Count);
        }
Ejemplo n.º 4
0
        public void GetClassificationSpansZeroLengthSnapShot()
        {
            var mockServiceProvider = new Mock <IServiceProvider>();
            var mockClassificationTypeRegistryService = new Mock <IClassificationTypeRegistryService>();
            var outputClassifier = new OutputClassifier(mockClassificationTypeRegistryService.Object, mockServiceProvider.Object);
            var mockSnapshot     = new Mock <ITextSnapshot>();

            mockSnapshot.SetupGet(s => s.Length).Returns(0);
            var snapshotSpan = new SnapshotSpan(mockSnapshot.Object, 0, 0);

            outputClassifier.GetClassificationSpans(snapshotSpan).Should().BeEmpty();
            mockSnapshot.VerifyAll();
            mockServiceProvider.VerifyAll();
            mockClassificationTypeRegistryService.VerifyAll();
        }
        public void GetClassificationSpans_EmptyWhenNoSnapshot()
        {
            // Arrange
            var         classificationTypeRegistryServiceMock = new Mock <IClassificationTypeRegistryService>();
            IClassifier classifier = new OutputClassifier(classificationTypeRegistryServiceMock.Object);

            void ClassifierClassificationChanged(object sender, ClassificationChangedEventArgs args) => Assert.Fail("This shouldn't be invoked.");

            classifier.ClassificationChanged -= ClassifierClassificationChanged;
            classifier.ClassificationChanged += ClassifierClassificationChanged;
            var span = new SnapshotSpan();

            // Act
            var spans = classifier.GetClassificationSpans(span);

            // Assert
            Assert.IsNotNull(spans);
            Assert.AreEqual(0, spans.Count);
        }
        public void GetClassificationSpans_ClassifyAsCritical()
        {
            // Arrange
            var criticalClassificationType            = Mock.Of <IClassificationType>();
            var errorClassificationType               = Mock.Of <IClassificationType>();
            var warningClassificationType             = Mock.Of <IClassificationType>();
            var debugClassificationType               = Mock.Of <IClassificationType>();
            var traceClassificationType               = Mock.Of <IClassificationType>();
            var doneClassificationType                = Mock.Of <IClassificationType>();
            var classificationTypeRegistryServiceMock = new Mock <IClassificationTypeRegistryService>();

            classificationTypeRegistryServiceMock.Setup(m => m.GetClassificationType(ClassificationTypes.Critical)).Returns(criticalClassificationType);
            classificationTypeRegistryServiceMock.Setup(m => m.GetClassificationType(ClassificationTypes.Error)).Returns(errorClassificationType);
            classificationTypeRegistryServiceMock.Setup(m => m.GetClassificationType(ClassificationTypes.Warning)).Returns(warningClassificationType);
            classificationTypeRegistryServiceMock.Setup(m => m.GetClassificationType(ClassificationTypes.Debug)).Returns(debugClassificationType);
            classificationTypeRegistryServiceMock.Setup(m => m.GetClassificationType(ClassificationTypes.Trace)).Returns(traceClassificationType);
            classificationTypeRegistryServiceMock.Setup(m => m.GetClassificationType(ClassificationTypes.Done)).Returns(doneClassificationType);
            IClassifier classifier = new OutputClassifier(classificationTypeRegistryServiceMock.Object);

            void ClassifierClassificationChanged(object sender, ClassificationChangedEventArgs args) => Assert.Fail("This shouldn't be invoked.");

            classifier.ClassificationChanged -= ClassifierClassificationChanged;
            classifier.ClassificationChanged += ClassifierClassificationChanged;
            const string text         = "CRITICAL: foobar";
            var          span         = new Span(0, text.Length);
            var          snapshotMock = new Mock <ITextSnapshot>();

            snapshotMock.Setup(m => m.GetText(span)).Returns(text);
            snapshotMock.SetupGet(m => m.Length).Returns(text.Length);
            var snapshotSpan = new SnapshotSpan(snapshotMock.Object, span);

            // Act
            var spans = classifier.GetClassificationSpans(snapshotSpan);

            // Assert
            Assert.IsNotNull(spans);
            Assert.AreEqual(1, spans.Count);
            Assert.AreEqual(snapshotSpan, spans[0].Span);
            classificationTypeRegistryServiceMock.Verify(m => m.GetClassificationType(It.IsAny <string>()), Times.Once);
            Assert.AreSame(criticalClassificationType, spans[0].ClassificationType);
        }