public async Task GetDescriptionAsync_AddsDirectiveDescriptionIfPropertyExists()
        {
            // Arrange
            var document            = CreateDocument();
            var expectedDescription = "The expected description";
            var item = CompletionItem.Create("TestDirective")
                       .WithProperties((new Dictionary <string, string>()
            {
                [RazorDirectiveCompletionProvider.DescriptionKey] = expectedDescription,
            }).ToImmutableDictionary());
            var codeDocumentProvider = new Mock <RazorCodeDocumentProvider>();
            var completionProvider   = new RazorDirectiveCompletionProvider(
                new Lazy <RazorCodeDocumentProvider>(() => codeDocumentProvider.Object),
                new Lazy <RazorCompletionFactsService>(() => CompletionFactsService),
                CompletionBroker,
                TextBufferProvider);

            // Act
            var description = await completionProvider.GetDescriptionAsync(document, item, CancellationToken.None);

            // Assert
            var part = Assert.Single(description.TaggedParts);

            Assert.Equal(TextTags.Text, part.Tag);
            Assert.Equal(expectedDescription, part.Text);
            Assert.Equal(expectedDescription, description.Text);
        }
        private static CompletionContext CreateContext(int position, RazorDirectiveCompletionProvider completionProvider, Document document)
        {
            var context = new CompletionContext(
                completionProvider,
                document,
                position,
                TextSpan.FromBounds(position, position),
                CompletionTrigger.Invoke,
                new Mock <OptionSet>().Object,
                CancellationToken.None);

            return(context);
        }
Ejemplo n.º 3
0
        public async Task GetDescriptionAsync_DoesNotAddDescriptionWhenPropertyAbsent()
        {
            // Arrange
            var document             = CreateDocument();
            var item                 = CompletionItem.Create("TestDirective");
            var codeDocumentProvider = new Mock <RazorCodeDocumentProvider>();
            var completionProvider   = new RazorDirectiveCompletionProvider(new Lazy <RazorCodeDocumentProvider>(() => codeDocumentProvider.Object));

            // Act
            var description = await completionProvider.GetDescriptionAsync(document, item, CancellationToken.None);

            // Assert
            Assert.Empty(description.TaggedParts);
            Assert.Equal(string.Empty, description.Text);
        }
Ejemplo n.º 4
0
        public void GetCompletionItems_ProvidesCompletionsForDirectivesWithoutDescription()
        {
            // Arrange
            var customDirective      = DirectiveDescriptor.CreateSingleLineDirective("custom");
            var codeDocumentProvider = CreateCodeDocumentProvider("@", new[] { customDirective });
            var completionProvider   = new RazorDirectiveCompletionProvider(codeDocumentProvider);
            var document             = CreateDocument();

            codeDocumentProvider.Value.TryGetFromDocument(document, out var codeDocument);
            var syntaxTree = codeDocument.GetSyntaxTree();

            // Act
            var completionItems = completionProvider.GetCompletionItems(syntaxTree);

            // Assert
            var customDirectiveCompletion = Assert.Single(completionItems, item => item.DisplayText == customDirective.Directive);

            AssertRazorCompletionItemDefaults(customDirectiveCompletion);
            Assert.DoesNotContain(customDirectiveCompletion.Properties, property => property.Key == RazorDirectiveCompletionProvider.DescriptionKey);
        }
Ejemplo n.º 5
0
        public void GetCompletionItems_ProvidesCompletionsForDefaultDirectives()
        {
            // Arrange
            var codeDocumentProvider = CreateCodeDocumentProvider("@", Enumerable.Empty <DirectiveDescriptor>());
            var completionProvider   = new RazorDirectiveCompletionProvider(codeDocumentProvider);
            var document             = CreateDocument();

            codeDocumentProvider.Value.TryGetFromDocument(document, out var codeDocument);
            var syntaxTree = codeDocument.GetSyntaxTree();

            // Act
            var completionItems = completionProvider.GetCompletionItems(syntaxTree);

            // Assert
            Assert.Collection(
                completionItems,
                item => AssertRazorCompletionItem(DefaultDirectives[0].Description, item),
                item => AssertRazorCompletionItem(DefaultDirectives[1].Description, item),
                item => AssertRazorCompletionItem(DefaultDirectives[2].Description, item));
        }