public void TryGetFromBuffer_FailsIfNoParserIsAvailable()
        {
            // Arrange
            var textBuffer = Mock.Of <ITextBuffer>(buffer => buffer.Properties == new PropertyCollection());
            var provider   = new DefaultTextBufferCodeDocumentProvider();

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

            // Assert
            Assert.False(result);
            Assert.Null(codeDocument);
        }
        public void TryGetFromBuffer_FailsIfNoParserIsAvailable()
        {
            // Arrange
            VisualStudioRazorParser parser = null;
            var parserProvider             = Mock.Of <RazorEditorFactoryService>(p => p.TryGetParser(It.IsAny <ITextBuffer>(), out parser) == false);
            var textBuffer = Mock.Of <ITextBuffer>();
            var provider   = new DefaultTextBufferCodeDocumentProvider(parserProvider);

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

            // Assert
            Assert.False(result);
            Assert.Null(codeDocument);
        }
        public void TryGetFromBuffer_SucceedsIfParserFromProviderHasCodeDocument()
        {
            // Arrange
            var expectedCodeDocument       = TestRazorCodeDocument.Create("Hello World");
            VisualStudioRazorParser parser = new DefaultVisualStudioRazorParser(expectedCodeDocument);
            var parserProvider             = Mock.Of <RazorEditorFactoryService>(p => p.TryGetParser(It.IsAny <ITextBuffer>(), out parser) == true);
            var textBuffer = Mock.Of <ITextBuffer>();
            var provider   = new DefaultTextBufferCodeDocumentProvider(parserProvider);

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

            // Assert
            Assert.True(result);
            Assert.Same(expectedCodeDocument, codeDocument);
        }
        public void TryGetFromBuffer_FailsIfParserMissingCodeDocument()
        {
            // Arrange
            VisualStudioRazorParser parser = new DefaultVisualStudioRazorParser(codeDocument: null);
            var properties = new PropertyCollection()
            {
                [typeof(VisualStudioRazorParser)] = parser
            };
            var textBuffer = Mock.Of <ITextBuffer>(buffer => buffer.Properties == properties);
            var provider   = new DefaultTextBufferCodeDocumentProvider();

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

            // Assert
            Assert.False(result);
            Assert.Null(codeDocument);
        }
        public void TryGetFromBuffer_SucceedsIfParserHasCodeDocument()
        {
            // Arrange
            var expectedCodeDocument       = TestRazorCodeDocument.Create("Hello World");
            VisualStudioRazorParser parser = new DefaultVisualStudioRazorParser(expectedCodeDocument);
            var properties = new PropertyCollection()
            {
                [typeof(VisualStudioRazorParser)] = parser
            };
            var textBuffer = Mock.Of <ITextBuffer>(buffer => buffer.Properties == properties);
            var provider   = new DefaultTextBufferCodeDocumentProvider();

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

            // Assert
            Assert.True(result);
            Assert.Same(expectedCodeDocument, codeDocument);
        }
Пример #6
0
        public void TryGetFromBuffer_FailsIfParserMissingCodeDocument()
        {
            // Arrange
#pragma warning disable CS0618 // Type or member is obsolete
            VisualStudioRazorParser parser = new DefaultVisualStudioRazorParser(codeDocument: null);
#pragma warning restore CS0618 // Type or member is obsolete
            var properties = new PropertyCollection()
            {
                [typeof(VisualStudioRazorParser)] = parser
            };
            var textBuffer = Mock.Of <ITextBuffer>(buffer => buffer.Properties == properties, MockBehavior.Strict);
            var provider   = new DefaultTextBufferCodeDocumentProvider();

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

            // Assert
            Assert.False(result);
            Assert.Null(codeDocument);
        }
Пример #7
0
        public void TryGetFromBuffer_SucceedsIfParserHasCodeDocument()
        {
            // Arrange
            var expectedCodeDocument = TestRazorCodeDocument.Create("Hello World");

#pragma warning disable CS0618 // Type or member is obsolete
            VisualStudioRazorParser parser = new DefaultVisualStudioRazorParser(expectedCodeDocument);
#pragma warning restore CS0618 // Type or member is obsolete
            var properties = new PropertyCollection()
            {
                [typeof(VisualStudioRazorParser)] = parser
            };
            var textBuffer = Mock.Of <ITextBuffer>(buffer => buffer.Properties == properties, MockBehavior.Strict);
            var provider   = new DefaultTextBufferCodeDocumentProvider();

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

            // Assert
            Assert.True(result);
            Assert.Same(expectedCodeDocument, codeDocument);
        }