예제 #1
0
        public void TryGetFromDocument_ReturnsTrueForValidDocuments()
        {
            // Arrange
            var textBuffer         = CreateTextBuffer();
            var bufferGraphService = CreateBufferGraphService(textBuffer);
            var document           = CreateDocument(textBuffer);
            var bufferProvider     = new DefaultTextBufferProvider(bufferGraphService);

            // Act
            var result = bufferProvider.TryGetFromDocument(document, out var buffer);

            // Assert
            Assert.True(result);
            Assert.Same(textBuffer, buffer);
        }
예제 #2
0
        public void TryGetFromDocument_ReturnsFalseIfCannotExtractSourceText()
        {
            // Arrange
            var textBuffer         = CreateTextBuffer();
            var bufferGraphService = CreateBufferGraphService(textBuffer);
            var document           = CreateDocumentWithoutText();
            var bufferProvider     = new DefaultTextBufferProvider(bufferGraphService);

            // Act
            var result = bufferProvider.TryGetFromDocument(document, out var buffer);

            // Assert
            Assert.False(result);
            Assert.Null(buffer);
        }
예제 #3
0
        public void TryGetFromDocument_ReturnsFalseIfSourceContainerNotConstructedFromTextBuffer()
        {
            // Arrange
            var bufferGraphService = CreateBufferGraphService(null);
            var text     = SourceText.From("Hello World");
            var document = CreateDocumentWithoutText();

            document = document.WithText(text);
            var bufferProvider = new DefaultTextBufferProvider(bufferGraphService);

            // Act
            var result = bufferProvider.TryGetFromDocument(document, out var buffer);

            // Assert
            Assert.False(result);
            Assert.Null(buffer);
        }
예제 #4
0
        public void TryGetFromDocument_ReturnsFalseIfBufferGraphCanNotFindRazorBuffer()
        {
            // Arrange
            var textBuffer  = CreateTextBuffer();
            var bufferGraph = new Mock <IBufferGraph>();

            bufferGraph.Setup(graph => graph.GetTextBuffers(It.IsAny <Predicate <ITextBuffer> >()))
            .Returns(new Collection <ITextBuffer>());
            var bufferGraphService = new Mock <IBufferGraphFactoryService>();

            bufferGraphService.Setup(service => service.CreateBufferGraph(textBuffer))
            .Returns(bufferGraph.Object);
            var document       = CreateDocument(textBuffer);
            var bufferProvider = new DefaultTextBufferProvider(bufferGraphService.Object);

            // Act
            var result = bufferProvider.TryGetFromDocument(document, out var buffer);

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