Esempio n. 1
0
        public void TryGetFromBuffer_PrefersVisualStudioRazorParserIfRazorEditorParserIsAvailable()
        {
            // Arrange
            var properties           = new PropertyCollection();
            var expectedCodeDocument = TestRazorCodeDocument.Create("Hello World");
            var parser = new VisualStudioRazorParser(expectedCodeDocument);

            properties.AddProperty(typeof(VisualStudioRazorParser), parser);
            var unexpectedCodeDocument = TestRazorCodeDocument.Create("Unexpected");
            var legacyParser           = new RazorEditorParser(unexpectedCodeDocument);

            properties.AddProperty(typeof(RazorEditorParser), legacyParser);
            var textBuffer = new Mock <ITextBuffer>();

            textBuffer.Setup(buffer => buffer.Properties)
            .Returns(properties);
            var provider = new DefaultVisualStudioCodeDocumentProvider();

            // Act
            var result = provider.TryGetFromBuffer(textBuffer.Object, out var codeDocument);

            // Assert
            Assert.True(result);
            Assert.Same(expectedCodeDocument, codeDocument);
        }
Esempio n. 2
0
        public void TryGetFromBuffer_FailsIfNoParserIsAvailable()
        {
            // Arrange
            var properties = new PropertyCollection();
            var textBuffer = new Mock <ITextBuffer>();

            textBuffer.Setup(buffer => buffer.Properties)
            .Returns(properties);
            var provider = new DefaultVisualStudioCodeDocumentProvider();

            // Act
            var result = provider.TryGetFromBuffer(textBuffer.Object, out var codeDocument);

            // Assert
            Assert.False(result);
            Assert.Null(codeDocument);
        }