public async Task Handle_ExistingComponent_SupportsFileCreationFalse_ReturnsResults() { // Arrange var documentPath = "c:/Test.razor"; var contents = "<Component></Component>"; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(new Position(0, 0), new Position(0, 0)), }; var location = new SourceLocation(1, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: false); var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); // Assert Assert.Collection(commandOrCodeActionContainer, e => { Assert.Equal("@using Fully.Qualified", e.Title); Assert.NotNull(e.Data); Assert.Null(e.Edit); }, e => { Assert.Equal("Fully.Qualified.Component", e.Title); Assert.NotNull(e.Edit); Assert.NotNull(e.Edit.DocumentChanges); Assert.Null(e.Data); }); }
public async Task Handle_NewComponent_SupportsFileCreationTrue_ReturnsResult() { // Arrange var documentPath = "c:/Test.razor"; var contents = "<NewComponent></NewComponent>"; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(new Position(0, 0), new Position(0, 0)), }; var location = new SourceLocation(1, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9), supportsFileCreation: true); var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); // Assert var command = Assert.Single(commandOrCodeActionContainer); Assert.Equal(RazorLS.Resources.Create_Component_FromTag_Title, command.Title); Assert.NotNull(command.Data); }
public async Task Handle_CursorOutsideComponent() { // Arrange var documentPath = "c:/Test.razor"; var contents = " <Component></Component>"; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(new Position(0, 0), new Position(0, 0)), }; var location = new SourceLocation(0, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9)); var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); // Assert Assert.Null(commandOrCodeActionContainer); }
public async Task Handle_NoTagName_DoesNotProvideLightBulb() { // Arrange var documentPath = "c:/Test.razor"; var contents = "<"; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(new Position(0, 1), new Position(0, 1)), }; var location = new SourceLocation(1, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(0, 1)); var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); // Assert Assert.Null(commandOrCodeActionContainer); }
public async Task Handle_InvalidSyntaxTree_NoStartNode() { // Arrange var documentPath = "c:/Test.razor"; var contents = ""; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(), }; var location = new SourceLocation(0, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(0, 0)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer); // Act var commandOrCodeActionContainer = await provider.ProvideAsync(context, default); // Assert Assert.Null(commandOrCodeActionContainer); }