Skip to content

Commit 3380e61

Browse files
committed
Fixes tests for Code Actions
1 parent cb98e4e commit 3380e61

4 files changed

+72
-4
lines changed

test/Lsp.Tests/LspRequestRouterTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public async Task ShouldRouteToCorrect_Request()
9494
textDocumentSyncHandler.Handle(Arg.Any<DidSaveTextDocumentParams>(), Arg.Any<CancellationToken>()).Returns(Unit.Value);
9595

9696
var codeActionHandler = Substitute.For<ICodeActionHandler>();
97-
codeActionHandler.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
97+
codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
9898
codeActionHandler
9999
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
100100
.Returns(new CommandOrCodeActionContainer());
@@ -126,13 +126,13 @@ public async Task ShouldRouteToCorrect_Request_WithManyHandlers()
126126
textDocumentSyncHandler2.Handle(Arg.Any<DidSaveTextDocumentParams>(), Arg.Any<CancellationToken>()).Returns(Unit.Value);
127127

128128
var codeActionHandler = Substitute.For<ICodeActionHandler>();
129-
codeActionHandler.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
129+
codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
130130
codeActionHandler
131131
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
132132
.Returns(new CommandOrCodeActionContainer());
133133

134134
var codeActionHandler2 = Substitute.For<ICodeActionHandler>();
135-
codeActionHandler2.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") });
135+
codeActionHandler2.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") });
136136
codeActionHandler2
137137
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
138138
.Returns(new CommandOrCodeActionContainer());

test/Lsp.Tests/MediatorTestsRequestHandlerOfTRequestTResponse.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task RequestsCancellation()
4646
textDocumentSyncHandler.Handle(Arg.Any<DidSaveTextDocumentParams>(), Arg.Any<CancellationToken>()).Returns(Unit.Value);
4747

4848
var codeActionHandler = Substitute.For<ICodeActionHandler>();
49-
codeActionHandler.GetRegistrationOptions().Returns(new TextDocumentRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
49+
codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") });
5050
codeActionHandler
5151
.Handle(Arg.Any<CodeActionParams>(), Arg.Any<CancellationToken>())
5252
.Returns(async (c) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using FluentAssertions;
3+
using Newtonsoft.Json;
4+
using OmniSharp.Extensions.LanguageServer.Protocol;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
6+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
7+
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
8+
using Xunit;
9+
10+
namespace Lsp.Tests.Models
11+
{
12+
public class CodeActionRegistrationOptionsTests
13+
{
14+
[Theory, JsonFixture]
15+
public void SimpleTest(string expected)
16+
{
17+
var model = new CodeActionRegistrationOptions() {
18+
DocumentSelector = new DocumentSelector(new[] { new DocumentFilter(){
19+
Language = "csharp",
20+
Pattern = "pattern",
21+
Scheme = "scheme"
22+
}, new DocumentFilter(){
23+
Language = "vb",
24+
Pattern = "pattern",
25+
Scheme = "scheme"
26+
} }),
27+
CodeActionKinds = new[] {
28+
CodeActionKind.QuickFix,
29+
CodeActionKind.Refactor,
30+
CodeActionKind.RefactorExtract,
31+
CodeActionKind.RefactorInline,
32+
CodeActionKind.RefactorRewrite,
33+
CodeActionKind.Source,
34+
CodeActionKind.SourceOrganizeImports
35+
}
36+
};
37+
var result = Fixture.SerializeObject(model);
38+
39+
result.Should().Be(expected);
40+
41+
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<CodeActionRegistrationOptions>(expected);
42+
deresult.Should().BeEquivalentTo(model);
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"codeActionKinds": [
3+
"quickfix",
4+
"refactor",
5+
"refactor.extract",
6+
"refactor.inline",
7+
"refactor.rewrite",
8+
"source",
9+
"source.organizeImports"
10+
],
11+
"documentSelector": [
12+
{
13+
"language": "csharp",
14+
"scheme": "scheme",
15+
"pattern": "pattern"
16+
},
17+
{
18+
"language": "vb",
19+
"scheme": "scheme",
20+
"pattern": "pattern"
21+
}
22+
]
23+
}

0 commit comments

Comments
 (0)