示例#1
0
        private static DefaultRazorEditorFactoryService CreateFactoryService(
            VisualStudioDocumentTracker documentTracker = null,
            VisualStudioRazorParser parser   = null,
            BraceSmartIndenter smartIndenter = null)
        {
            documentTracker ??= Mock.Of <VisualStudioDocumentTracker>(MockBehavior.Strict);
            parser ??= Mock.Of <VisualStudioRazorParser>(MockBehavior.Strict);
            smartIndenter ??= Mock.Of <BraceSmartIndenter>(MockBehavior.Strict);

            var documentTrackerFactory = Mock.Of <VisualStudioDocumentTrackerFactory>(f => f.Create(It.IsAny <ITextBuffer>()) == documentTracker, MockBehavior.Strict);
            var parserFactory          = Mock.Of <VisualStudioRazorParserFactory>(f => f.Create(It.IsAny <VisualStudioDocumentTracker>()) == parser, MockBehavior.Strict);
            var smartIndenterFactory   = Mock.Of <BraceSmartIndenterFactory>(f => f.Create(It.IsAny <VisualStudioDocumentTracker>()) == smartIndenter, MockBehavior.Strict);

            var services = TestServices.Create(new ILanguageService[]
            {
                documentTrackerFactory,
                parserFactory,
                smartIndenterFactory
            });

            Workspace workspace         = TestWorkspace.Create(services);
            var       workspaceAccessor = new Mock <VisualStudioWorkspaceAccessor>(MockBehavior.Strict);

            workspaceAccessor.Setup(p => p.TryGetWorkspace(It.IsAny <ITextBuffer>(), out workspace))
            .Returns(true);

            var factoryService = new DefaultRazorEditorFactoryService(workspaceAccessor.Object);

            return(factoryService);
        }
        public override bool TryGetParser(ITextBuffer textBuffer, out VisualStudioRazorParser parser)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            if (!textBuffer.IsRazorBuffer())
            {
                parser = null;
                return(false);
            }

            var textBufferInitialized = TryInitializeTextBuffer(textBuffer);

            if (!textBufferInitialized)
            {
                parser = null;
                return(false);
            }

            if (!textBuffer.Properties.TryGetProperty(typeof(VisualStudioRazorParser), out parser))
            {
                Debug.Fail("Parser should have been stored on the text buffer during initialization.");
                return(false);
            }

            return(true);
        }
        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);
        }
示例#4
0
        private static DefaultRazorEditorFactoryService CreateFactoryService(
            VisualStudioDocumentTracker documentTracker = null,
            VisualStudioRazorParser parser   = null,
            BraceSmartIndenter smartIndenter = null)
        {
            documentTracker = documentTracker ?? Mock.Of <VisualStudioDocumentTracker>();
            parser          = parser ?? Mock.Of <VisualStudioRazorParser>();
            smartIndenter   = smartIndenter ?? Mock.Of <BraceSmartIndenter>();

            var documentTrackerFactory = Mock.Of <VisualStudioDocumentTrackerFactory>(f => f.Create(It.IsAny <ITextBuffer>()) == documentTracker);
            var parserFactory          = Mock.Of <VisualStudioRazorParserFactory>(f => f.Create(It.IsAny <VisualStudioDocumentTracker>()) == parser);
            var smartIndenterFactory   = Mock.Of <BraceSmartIndenterFactory>(f => f.Create(It.IsAny <VisualStudioDocumentTracker>()) == smartIndenter);
            var factoryService         = new DefaultRazorEditorFactoryService(documentTrackerFactory, parserFactory, smartIndenterFactory);

            return(factoryService);
        }
        public RazorDirectiveCompletionSource(
            ForegroundDispatcher foregroundDispatcher,
            VisualStudioRazorParser parser,
            RazorCompletionFactsService completionFactsService)
        {
            if (foregroundDispatcher == null)
            {
                throw new ArgumentNullException(nameof(foregroundDispatcher));
            }

            if (parser == null)
            {
                throw new ArgumentNullException(nameof(parser));
            }

            if (completionFactsService == null)
            {
                throw new ArgumentNullException(nameof(completionFactsService));
            }

            _foregroundDispatcher = foregroundDispatcher;
            _parser = parser;
            _completionFactsService = completionFactsService;
        }
 public abstract bool TryGetParser(ITextBuffer textBuffer, out VisualStudioRazorParser parser);