Skip to content

Commit

Permalink
Rename and seal test handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Apr 10, 2024
1 parent 1030887 commit 3412a49
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions src/Features/LanguageServer/ProtocolUnitTests/HandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public HandlerTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
}

protected override TestComposition Composition => base.Composition.AddParts(
typeof(DocumentHandler),
typeof(RequestHandlerWithNoParams),
typeof(NotificationHandlerFactory),
typeof(NotificationWithoutParamsHandlerFactory),
typeof(LanguageSpecificHandler),
typeof(LanguageSpecificHandlerWithDifferentParams));
typeof(TestDocumentHandler),
typeof(TestRequestHandlerWithNoParams),
typeof(TestNotificationHandlerFactory),
typeof(TestNotificationWithoutParamsHandlerFactory),
typeof(TestLanguageSpecificHandler),
typeof(TestLanguageSpecificHandlerWithDifferentParams));

[Theory, CombinatorialData]
public async Task CanExecuteRequestHandler(bool mutatingLspWorkspace)
Expand All @@ -44,17 +44,17 @@ public async Task CanExecuteRequestHandler(bool mutatingLspWorkspace)
{
Uri = ProtocolConversions.CreateAbsoluteUri(@"C:\test.cs")
});
var response = await server.ExecuteRequestAsync<TestRequestTypeOne, string>(DocumentHandler.MethodName, request, CancellationToken.None);
Assert.Equal(typeof(DocumentHandler).Name, response);
var response = await server.ExecuteRequestAsync<TestRequestTypeOne, string>(TestDocumentHandler.MethodName, request, CancellationToken.None);
Assert.Equal(typeof(TestDocumentHandler).Name, response);
}

[Theory, CombinatorialData]
public async Task CanExecuteRequestHandlerWithNoParams(bool mutatingLspWorkspace)
{
await using var server = await CreateTestLspServerAsync("", mutatingLspWorkspace);

var response = await server.ExecuteRequest0Async<string>(RequestHandlerWithNoParams.MethodName, CancellationToken.None);
Assert.Equal(typeof(RequestHandlerWithNoParams).Name, response);
var response = await server.ExecuteRequest0Async<string>(TestRequestHandlerWithNoParams.MethodName, CancellationToken.None);
Assert.Equal(typeof(TestRequestHandlerWithNoParams).Name, response);
}

[Theory, CombinatorialData]
Expand All @@ -67,19 +67,19 @@ public async Task CanExecuteNotificationHandler(bool mutatingLspWorkspace)
Uri = ProtocolConversions.CreateAbsoluteUri(@"C:\test.cs")
});

await server.ExecuteNotificationAsync(NotificationHandler.MethodName, request);
var response = await server.GetRequiredLspService<NotificationHandler>().ResultSource.Task;
Assert.Equal(typeof(NotificationHandler).Name, response);
await server.ExecuteNotificationAsync(TestNotificationHandler.MethodName, request);
var response = await server.GetRequiredLspService<TestNotificationHandler>().ResultSource.Task;
Assert.Equal(typeof(TestNotificationHandler).Name, response);
}

[Theory, CombinatorialData]
public async Task CanExecuteNotificationHandlerWithNoParams(bool mutatingLspWorkspace)
{
await using var server = await CreateTestLspServerAsync("", mutatingLspWorkspace);

await server.ExecuteNotification0Async(NotificationWithoutParamsHandler.MethodName);
var response = await server.GetRequiredLspService<NotificationWithoutParamsHandler>().ResultSource.Task;
Assert.Equal(typeof(NotificationWithoutParamsHandler).Name, response);
await server.ExecuteNotification0Async(TestNotificationWithoutParamsHandler.MethodName);
var response = await server.GetRequiredLspService<TestNotificationWithoutParamsHandler>().ResultSource.Task;
Assert.Equal(typeof(TestNotificationWithoutParamsHandler).Name, response);
}

[Theory, CombinatorialData]
Expand All @@ -91,8 +91,8 @@ public async Task CanExecuteLanguageSpecificHandler(bool mutatingLspWorkspace)
{
Uri = ProtocolConversions.CreateAbsoluteUri(@"C:\test.fs")
});
var response = await server.ExecuteRequestAsync<TestRequestTypeOne, string>(DocumentHandler.MethodName, request, CancellationToken.None);
Assert.Equal(typeof(LanguageSpecificHandler).Name, response);
var response = await server.ExecuteRequestAsync<TestRequestTypeOne, string>(TestDocumentHandler.MethodName, request, CancellationToken.None);
Assert.Equal(typeof(TestLanguageSpecificHandler).Name, response);
}

[Theory, CombinatorialData]
Expand All @@ -104,15 +104,15 @@ public async Task CanExecuteLanguageSpecificHandlerWithDifferentRequestTypes(boo
{
Uri = ProtocolConversions.CreateAbsoluteUri(@"C:\test.vb")
});
var response = await server.ExecuteRequestAsync<TestRequestTypeTwo, string>(DocumentHandler.MethodName, request, CancellationToken.None);
Assert.Equal(typeof(LanguageSpecificHandlerWithDifferentParams).Name, response);
var response = await server.ExecuteRequestAsync<TestRequestTypeTwo, string>(TestDocumentHandler.MethodName, request, CancellationToken.None);
Assert.Equal(typeof(TestLanguageSpecificHandlerWithDifferentParams).Name, response);
}

[Theory, CombinatorialData]
public async Task ThrowsOnInvalidLanguageSpecificHandler(bool mutatingLspWorkspace)
{
// Arrange
await Assert.ThrowsAsync<InvalidOperationException>(async () => await CreateTestLspServerAsync("", mutatingLspWorkspace, extraExportedTypes: [typeof(DuplicateLanguageSpecificHandler)]));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await CreateTestLspServerAsync("", mutatingLspWorkspace, extraExportedTypes: [typeof(TestDuplicateLanguageSpecificHandler)]));
}

[Theory, CombinatorialData]
Expand All @@ -121,7 +121,7 @@ public async Task ThrowsIfDeserializationFails(bool mutatingLspWorkspace)
await using var server = await CreateTestLspServerAsync("", mutatingLspWorkspace);

var request = new TestRequestTypeThree("value");
await Assert.ThrowsAsync<StreamJsonRpc.RemoteInvocationException>(async () => await server.ExecuteRequestAsync<TestRequestTypeThree, string>(DocumentHandler.MethodName, request, CancellationToken.None));
await Assert.ThrowsAsync<StreamJsonRpc.RemoteInvocationException>(async () => await server.ExecuteRequestAsync<TestRequestTypeThree, string>(TestDocumentHandler.MethodName, request, CancellationToken.None));
}

[DataContract]
Expand All @@ -133,15 +133,15 @@ internal record TestRequestTypeTwo([property: DataMember(Name = "textDocument"),
[DataContract]
internal record TestRequestTypeThree([property: DataMember(Name = "someValue")] string SomeValue);

[ExportCSharpVisualBasicStatelessLspService(typeof(DocumentHandler)), PartNotDiscoverable, Shared]
[ExportCSharpVisualBasicStatelessLspService(typeof(TestDocumentHandler)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(MethodName, LanguageServerConstants.DefaultLanguageName)]
internal class DocumentHandler : ILspServiceDocumentRequestHandler<TestRequestTypeOne, string>
internal sealed class TestDocumentHandler : ILspServiceDocumentRequestHandler<TestRequestTypeOne, string>
{
public const string MethodName = nameof(DocumentHandler);
public const string MethodName = nameof(TestDocumentHandler);

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public DocumentHandler()
public TestDocumentHandler()
{
}

Expand All @@ -159,15 +159,15 @@ public Task<string> HandleRequestAsync(TestRequestTypeOne request, RequestContex
}
}

[ExportCSharpVisualBasicStatelessLspService(typeof(RequestHandlerWithNoParams)), PartNotDiscoverable, Shared]
[ExportCSharpVisualBasicStatelessLspService(typeof(TestRequestHandlerWithNoParams)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(MethodName, LanguageServerConstants.DefaultLanguageName)]
internal class RequestHandlerWithNoParams : ILspServiceRequestHandler<string>
internal sealed class TestRequestHandlerWithNoParams : ILspServiceRequestHandler<string>
{
public const string MethodName = nameof(RequestHandlerWithNoParams);
public const string MethodName = nameof(TestRequestHandlerWithNoParams);

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public RequestHandlerWithNoParams()
public TestRequestHandlerWithNoParams()
{
}

Expand All @@ -181,12 +181,12 @@ public Task<string> HandleRequestAsync(RequestContext context, CancellationToken
}

[LanguageServerEndpoint(MethodName, LanguageServerConstants.DefaultLanguageName)]
internal class NotificationHandler : ILspServiceNotificationHandler<TestRequestTypeOne>
internal sealed class TestNotificationHandler : ILspServiceNotificationHandler<TestRequestTypeOne>
{
public const string MethodName = nameof(NotificationHandler);
public const string MethodName = nameof(TestNotificationHandler);
public readonly TaskCompletionSource<string> ResultSource;

public NotificationHandler()
public TestNotificationHandler()
{
ResultSource = new TaskCompletionSource<string>();
}
Expand All @@ -204,28 +204,28 @@ public Task HandleNotificationAsync(TestRequestTypeOne request, RequestContext c
/// <summary>
/// Exported via a factory as we need a new instance for each server (the task completion result should be unique per server).
/// </summary>
[ExportCSharpVisualBasicLspServiceFactory(typeof(NotificationHandler)), PartNotDiscoverable, Shared]
internal class NotificationHandlerFactory : ILspServiceFactory
[ExportCSharpVisualBasicLspServiceFactory(typeof(TestNotificationHandler)), PartNotDiscoverable, Shared]
internal sealed class TestNotificationHandlerFactory : ILspServiceFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public NotificationHandlerFactory()
public TestNotificationHandlerFactory()
{
}

public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
{
return new NotificationHandler();
return new TestNotificationHandler();
}
}

[LanguageServerEndpoint(MethodName, LanguageServerConstants.DefaultLanguageName)]
internal class NotificationWithoutParamsHandler : ILspServiceNotificationHandler
internal sealed class TestNotificationWithoutParamsHandler : ILspServiceNotificationHandler
{
public const string MethodName = nameof(NotificationWithoutParamsHandler);
public const string MethodName = nameof(TestNotificationWithoutParamsHandler);
public readonly TaskCompletionSource<string> ResultSource;

public NotificationWithoutParamsHandler()
public TestNotificationWithoutParamsHandler()
{
ResultSource = new TaskCompletionSource<string>();
}
Expand All @@ -243,31 +243,31 @@ public Task HandleNotificationAsync(RequestContext context, CancellationToken ca
/// <summary>
/// Exported via a factory as we need a new instance for each server (the task completion result should be unique per server).
/// </summary>
[ExportCSharpVisualBasicLspServiceFactory(typeof(NotificationWithoutParamsHandler)), PartNotDiscoverable, Shared]
internal class NotificationWithoutParamsHandlerFactory : ILspServiceFactory
[ExportCSharpVisualBasicLspServiceFactory(typeof(TestNotificationWithoutParamsHandler)), PartNotDiscoverable, Shared]
internal sealed class TestNotificationWithoutParamsHandlerFactory : ILspServiceFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public NotificationWithoutParamsHandlerFactory()
public TestNotificationWithoutParamsHandlerFactory()
{
}

public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind)
{
return new NotificationWithoutParamsHandler();
return new TestNotificationWithoutParamsHandler();
}
}

/// <summary>
/// Defines a language specific handler with the same method as <see cref="DocumentHandler"/>
/// Defines a language specific handler with the same method as <see cref="TestDocumentHandler"/>
/// </summary>
[ExportCSharpVisualBasicStatelessLspService(typeof(LanguageSpecificHandler)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(DocumentHandler.MethodName, LanguageNames.FSharp)]
internal class LanguageSpecificHandler : ILspServiceDocumentRequestHandler<TestRequestTypeOne, string>
[ExportCSharpVisualBasicStatelessLspService(typeof(TestLanguageSpecificHandler)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(TestDocumentHandler.MethodName, LanguageNames.FSharp)]
internal sealed class TestLanguageSpecificHandler : ILspServiceDocumentRequestHandler<TestRequestTypeOne, string>
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public LanguageSpecificHandler()
public TestLanguageSpecificHandler()
{
}

Expand All @@ -286,16 +286,16 @@ public Task<string> HandleRequestAsync(TestRequestTypeOne request, RequestContex
}

/// <summary>
/// Defines a language specific handler with the same method as <see cref="DocumentHandler"/>
/// Defines a language specific handler with the same method as <see cref="TestDocumentHandler"/>
/// but using different request and response types.
/// </summary>
[ExportCSharpVisualBasicStatelessLspService(typeof(LanguageSpecificHandlerWithDifferentParams)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(DocumentHandler.MethodName, LanguageNames.VisualBasic)]
internal class LanguageSpecificHandlerWithDifferentParams : ILspServiceDocumentRequestHandler<TestRequestTypeTwo, string>
[ExportCSharpVisualBasicStatelessLspService(typeof(TestLanguageSpecificHandlerWithDifferentParams)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(TestDocumentHandler.MethodName, LanguageNames.VisualBasic)]
internal sealed class TestLanguageSpecificHandlerWithDifferentParams : ILspServiceDocumentRequestHandler<TestRequestTypeTwo, string>
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public LanguageSpecificHandlerWithDifferentParams()
public TestLanguageSpecificHandlerWithDifferentParams()
{
}

Expand All @@ -314,16 +314,16 @@ public Task<string> HandleRequestAsync(TestRequestTypeTwo request, RequestContex
}

/// <summary>
/// Defines a language specific handler with the same method and language as <see cref="LanguageSpecificHandler"/>
/// Defines a language specific handler with the same method and language as <see cref="TestLanguageSpecificHandler"/>
/// but with different params (an error)
/// </summary>
[ExportCSharpVisualBasicStatelessLspService(typeof(DuplicateLanguageSpecificHandler)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(DocumentHandler.MethodName, LanguageNames.FSharp)]
internal class DuplicateLanguageSpecificHandler : ILspServiceRequestHandler<string>
[ExportCSharpVisualBasicStatelessLspService(typeof(TestDuplicateLanguageSpecificHandler)), PartNotDiscoverable, Shared]
[LanguageServerEndpoint(TestDocumentHandler.MethodName, LanguageNames.FSharp)]
internal sealed class TestDuplicateLanguageSpecificHandler : ILspServiceRequestHandler<string>
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public DuplicateLanguageSpecificHandler()
public TestDuplicateLanguageSpecificHandler()
{
}

Expand Down

0 comments on commit 3412a49

Please sign in to comment.