|
| 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