public async Task Handle_MultipleProviderSameTrigger_UsesFirstSuccessful()
        {
            // Arrange
            var codeDocument     = CreateCodeDocument();
            var uri              = new Uri("file://path/test.razor");
            var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument);
            var insertProvider1  = new TestOnAutoInsertProvider(">", canResolve: true)
            {
                ResolvedTextEdit = new TextEdit()
            };
            var insertProvider2 = new TestOnAutoInsertProvider(">", canResolve: true)
            {
                ResolvedTextEdit = new TextEdit()
            };
            var endpoint = new OnAutoInsertEndpoint(Dispatcher, documentResolver, new[] { insertProvider1, insertProvider2 });
            var @params  = new OnAutoInsertParams()
            {
                TextDocument = new TextDocumentIdentifier(uri),
                Character    = ">",
                Options      = new FormattingOptions
                {
                    TabSize      = 4,
                    InsertSpaces = true
                },
            };

            // Act
            var result = await endpoint.Handle(@params, CancellationToken.None);

            // Assert
            Assert.NotNull(result);
            Assert.True(insertProvider1.Called);
            Assert.False(insertProvider2.Called);
            Assert.Same(insertProvider1.ResolvedTextEdit, result.TextEdit);
        }
        public async Task Handle_SingleProvider_InvokesProvider()
        {
            // Arrange
            var codeDocument     = CreateCodeDocument();
            var uri              = new Uri("file://path/test.razor");
            var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument);
            var insertProvider   = new TestOnAutoInsertProvider(">", canResolve: true);
            var endpoint         = new OnAutoInsertEndpoint(Dispatcher, documentResolver, new[] { insertProvider });
            var @params          = new OnAutoInsertParams()
            {
                TextDocument = new TextDocumentIdentifier(uri),
                Character    = ">",
                Options      = new FormattingOptions
                {
                    TabSize      = 4,
                    InsertSpaces = true
                },
            };

            // Act
            var result = await endpoint.Handle(@params, CancellationToken.None);

            // Assert
            Assert.NotNull(result);
            Assert.True(insertProvider.Called);
        }
Esempio n. 3
0
        public async Task Handle_UnsupportedCodeDocument_ReturnsNull()
        {
            // Arrange
            var codeDocument = CreateCodeDocument();

            codeDocument.SetUnsupported();
            var uri = new Uri("file://path/test.razor");
            var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument);
            var insertProvider   = new TestOnAutoInsertProvider(">", canResolve: true, LoggerFactory);
            var endpoint         = new OnAutoInsertEndpoint(Dispatcher, documentResolver, new[] { insertProvider }, TestAdhocWorkspaceFactory.Instance);
            var @params          = new OnAutoInsertParams()
            {
                TextDocument = new TextDocumentIdentifier(uri),
                Character    = ">",
                Options      = new FormattingOptions
                {
                    TabSize      = 4,
                    InsertSpaces = true
                },
            };

            // Act
            var result = await endpoint.Handle(@params, CancellationToken.None);

            // Assert
            Assert.Null(result);
            Assert.False(insertProvider.Called);
        }
        public async Task Handle_DocumentNotFound_ReturnsNull()
        {
            // Arrange
            var insertProvider = new TestOnAutoInsertProvider(">", canResolve: true);
            var endpoint       = new OnAutoInsertEndpoint(Dispatcher, EmptyDocumentResolver, new[] { insertProvider });
            var uri            = new Uri("file://path/test.razor");
            var @params        = new OnAutoInsertParams()
            {
                TextDocument = new TextDocumentIdentifier(uri),
                Character    = ">",
                Options      = new FormattingOptions(),
            };

            // Act
            var result = await endpoint.Handle(@params, CancellationToken.None);

            // Assert
            Assert.Null(result);
            Assert.False(insertProvider.Called);
        }
        public async Task Handle_MultipleProviderUnmatchingTrigger_ReturnsNull()
        {
            // Arrange
            var codeDocument     = CreateCodeDocument();
            var uri              = new Uri("file://path/test.razor");
            var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument);
            var insertProvider1  = new TestOnAutoInsertProvider(">", canResolve: true);
            var insertProvider2  = new TestOnAutoInsertProvider("<", canResolve: true);
            var endpoint         = new OnAutoInsertEndpoint(Dispatcher, documentResolver, new[] { insertProvider1, insertProvider2 });
            var @params          = new OnAutoInsertParams()
            {
                TextDocument = new TextDocumentIdentifier(uri),
                Character    = "!",
                Options      = new FormattingOptions(),
            };

            // Act
            var result = await endpoint.Handle(@params, CancellationToken.None);

            // Assert
            Assert.Null(result);
            Assert.False(insertProvider1.Called);
            Assert.False(insertProvider2.Called);
        }