Skip to content

Commit 6dacdbf

Browse files
authored
Fix string overloads of EditorExtensionServiceProvider.GetService() on .NET
1 parent d50975a commit 6dacdbf

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public object GetServiceByAssemblyQualifiedName(string asmQualifiedTypeName)
116116
{
117117
using (EnterPsesAlcReflectionContext())
118118
{
119-
serviceType = s_psesAsm.GetType(asmQualifiedTypeName);
119+
serviceType = Type.GetType(asmQualifiedTypeName);
120120
}
121121
}
122122
else
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading.Tasks;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging.Abstractions;
7+
using Microsoft.PowerShell.EditorServices.Extensions.Services;
8+
using Microsoft.PowerShell.EditorServices.Services.Extension;
9+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
10+
using Microsoft.PowerShell.EditorServices.Test;
11+
using Xunit;
12+
using WorkspaceService = Microsoft.PowerShell.EditorServices.Services.WorkspaceService;
13+
14+
namespace PowerShellEditorServices.Test.Extensions
15+
{
16+
[Trait("Category", "Extensions")]
17+
public class EditorExtensionServiceProviderTests : IAsyncLifetime
18+
{
19+
private PsesInternalHost psesHost;
20+
21+
private WorkspaceService workspaceService;
22+
23+
private EditorExtensionServiceProvider serviceProvider;
24+
25+
public async Task InitializeAsync()
26+
{
27+
psesHost = await PsesHostFactory.Create(NullLoggerFactory.Instance);
28+
29+
ExtensionService extensionService = new(
30+
languageServer: null,
31+
serviceProvider: null,
32+
editorOperations: null,
33+
executionService: psesHost);
34+
await extensionService.InitializeAsync();
35+
36+
workspaceService = new WorkspaceService(NullLoggerFactory.Instance);
37+
38+
ServiceCollection services = new();
39+
services.AddSingleton(extensionService);
40+
services.AddSingleton(workspaceService);
41+
42+
serviceProvider = new EditorExtensionServiceProvider(services.BuildServiceProvider());
43+
}
44+
45+
public async Task DisposeAsync() => await psesHost.StopAsync();
46+
47+
[Fact]
48+
public void GetServiceByFullTypeNameReturnsService() =>
49+
Assert.Same(
50+
workspaceService,
51+
serviceProvider.GetService("Microsoft.PowerShell.EditorServices.Services.WorkspaceService"));
52+
53+
[Fact]
54+
public void GetServiceByTypeNameAndAssemblyNameReturnsService() =>
55+
Assert.Same(
56+
workspaceService,
57+
serviceProvider.GetService(
58+
"Microsoft.PowerShell.EditorServices.Services.WorkspaceService",
59+
"Microsoft.PowerShell.EditorServices"));
60+
61+
[Fact]
62+
public void GetServiceByAssemblyQualifiedNameReturnsService() =>
63+
Assert.Same(
64+
workspaceService,
65+
serviceProvider.GetServiceByAssemblyQualifiedName(
66+
"Microsoft.PowerShell.EditorServices.Services.WorkspaceService, Microsoft.PowerShell.EditorServices"));
67+
}
68+
}

0 commit comments

Comments
 (0)