public async Task Handle_MissingDiagnostics_ReturnsEmpty() { // Arrange var documentPath = "c:/Test.razor"; var contents = ""; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(), Context = new CodeActionContext() { Diagnostics = null } }; 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 ImplementInterfaceAbstractClassCodeActionProvider(); var csharpCodeActions = new[] { new RazorCodeAction() { Title = "Implement abstract class" } }; // Act var results = await provider.ProvideAsync(context, csharpCodeActions, default); // Assert Assert.Empty(results); }
public async Task Handle_EmptyCodeActions_ReturnsEmpty() { // Arrange var documentPath = "c:/Test.razor"; var contents = ""; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(), Context = new CodeActionContext() { Diagnostics = new Container <Diagnostic>( new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0534") } ) } }; 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 ImplementInterfaceAbstractClassCodeActionProvider(); var csharpCodeActions = Array.Empty <RazorCodeAction>(); // Act var results = await provider.ProvideAsync(context, csharpCodeActions, default); // Assert Assert.Empty(results); }
public async Task Handle_SupportsCodeActionResolveFalse_ValidDiagnostic_ValidCodeAction_ReturnsEmpty() { // Arrange var documentPath = "c:/Test.razor"; var contents = "@code { Path; }"; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(), Context = new CodeActionContext() { Diagnostics = new Container <Diagnostic>( new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0132") }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0534"), Range = new Range( new Position(0, 8), new Position(0, 12) ) }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0535"), Range = new Range( new Position(0, 8), new Position(0, 12) ) }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0183") } ) } }; var location = new SourceLocation(0, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4), supportsCodeActionResolve: false); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new ImplementInterfaceAbstractClassCodeActionProvider(); var csharpCodeActions = new[] { new RazorCodeAction() { Title = "Implement abstract class" }, new RazorCodeAction() { Title = "Implement interface" } }; // Act var results = await provider.ProvideAsync(context, csharpCodeActions, default); // Assert Assert.Empty(results); }
public async Task Handle_ValidDiagnostic_ValidCodeAction_CodeBlock_ReturnsCodeActions() { // Arrange var documentPath = "c:/Test.razor"; var contents = "@code { Path; }"; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(), Context = new CodeActionContext() { Diagnostics = new Container <Diagnostic>( new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0132") }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0534"), Range = new Range( new Position(0, 8), new Position(0, 12) ) }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0535"), Range = new Range( new Position(0, 8), new Position(0, 12) ) }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0183") } ) } }; var location = new SourceLocation(8, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new ImplementInterfaceAbstractClassCodeActionProvider(); var csharpCodeActions = new[] { new RazorCodeAction() { Title = "Implement abstract class" }, new RazorCodeAction() { Title = "Implement interface" } }; // Act var results = await provider.ProvideAsync(context, csharpCodeActions, default); // Assert Assert.Collection(results, r => { Assert.Equal("Implement abstract class", r.Title); Assert.Null(r.Edit); Assert.NotNull(r.Data); var resolutionParams = Assert.IsType <RazorCodeActionResolutionParams>(r.Data); Assert.Equal(LanguageServerConstants.CodeActions.Languages.CSharp, resolutionParams.Language); Assert.Equal(LanguageServerConstants.CodeActions.Default, resolutionParams.Action); Assert.IsType <CSharpCodeActionParams>(resolutionParams.Data); }, r => { Assert.Equal("Implement interface", r.Title); Assert.Null(r.Edit); Assert.NotNull(r.Data); var resolutionParams = Assert.IsType <RazorCodeActionResolutionParams>(r.Data); Assert.Equal(LanguageServerConstants.CodeActions.Languages.CSharp, resolutionParams.Language); Assert.Equal(LanguageServerConstants.CodeActions.Default, resolutionParams.Action); Assert.IsType <CSharpCodeActionParams>(resolutionParams.Data); } ); }
public async Task Handle_ValidDiagnostic_InvalidCodeAction_ReturnsEmpty() { // Arrange var documentPath = "c:/Test.razor"; var contents = "@code { Path; }"; var request = new CodeActionParams() { TextDocument = new TextDocumentIdentifier(new Uri(documentPath)), Range = new Range(), Context = new CodeActionContext() { Diagnostics = new Container <Diagnostic>( new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0132") }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0534"), Range = new Range( new Position(0, 8), new Position(0, 12) ) }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0535"), Range = new Range( new Position(0, 8), new Position(0, 12) ) }, new Diagnostic() { Severity = DiagnosticSeverity.Error, Code = new DiagnosticCode("CS0183") } ) } }; var location = new SourceLocation(0, -1, -1); var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4)); context.CodeDocument.SetFileKind(FileKinds.Legacy); var provider = new ImplementInterfaceAbstractClassCodeActionProvider(); // A valid code actions is expected to end with `Path` as that's the `associatedText` // indicated in the `Diagnostic.Range` for `CS0246` above. var csharpCodeActions = new[] { new RazorCodeAction() { Title = "Implement non-abstract class" }, new RazorCodeAction() { Title = "Implement interface that doesn't exist" } }; // Act var results = await provider.ProvideAsync(context, csharpCodeActions, default); // Assert Assert.Empty(results); }