Skip to content

Commit ac3f64c

Browse files
committed
Adjusted refactoring Tests to use IAsyncLifetime instead of IDisposable
1 parent effbbbc commit ac3f64c

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

test/PowerShellEditorServices.Test/Refactoring/RefactorFunctionTests.cs

+10-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Threading.Tasks;
67
using Microsoft.Extensions.Logging.Abstractions;
78
using Microsoft.PowerShell.EditorServices.Services;
89
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
@@ -18,18 +19,18 @@
1819
namespace PowerShellEditorServices.Test.Refactoring
1920
{
2021
[Trait("Category", "RefactorFunction")]
21-
public class RefactorFunctionTests : IDisposable
22+
public class RefactorFunctionTests : IAsyncLifetime
2223

2324
{
24-
private readonly PsesInternalHost psesHost;
25-
private readonly WorkspaceService workspace;
26-
public void Dispose()
25+
private PsesInternalHost psesHost;
26+
private WorkspaceService workspace;
27+
public async Task InitializeAsync()
2728
{
28-
#pragma warning disable VSTHRD002
29-
psesHost.StopAsync().Wait();
30-
#pragma warning restore VSTHRD002
31-
GC.SuppressFinalize(this);
29+
psesHost = await PsesHostFactory.Create(NullLoggerFactory.Instance);
30+
workspace = new WorkspaceService(NullLoggerFactory.Instance);
3231
}
32+
33+
public async Task DisposeAsync() => await Task.Run(psesHost.StopAsync);
3334
private ScriptFile GetTestScript(string fileName) => workspace.GetFile(TestUtilities.GetSharedPath(Path.Combine("Refactoring\\Functions", fileName)));
3435

3536
internal static string GetModifiedScript(string OriginalScript, ModifiedFileResponse Modification)
@@ -72,11 +73,7 @@ internal static string TestRenaming(ScriptFile scriptFile, RenameSymbolParams re
7273
};
7374
return GetModifiedScript(scriptFile.Contents, changes);
7475
}
75-
public RefactorFunctionTests()
76-
{
77-
psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance);
78-
workspace = new WorkspaceService(NullLoggerFactory.Instance);
79-
}
76+
8077
[Fact]
8178
public void RefactorFunctionSingle()
8279
{

test/PowerShellEditorServices.Test/Refactoring/RefactorUtilitiesTests.cs

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System;
54
using System.IO;
5+
using System.Threading.Tasks;
66
using Microsoft.Extensions.Logging.Abstractions;
77
using Microsoft.PowerShell.EditorServices.Services;
88
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
@@ -17,24 +17,18 @@
1717
namespace PowerShellEditorServices.Test.Refactoring
1818
{
1919
[Trait("Category", "RefactorUtilities")]
20-
public class RefactorUtilitiesTests : IDisposable
20+
public class RefactorUtilitiesTests : IAsyncLifetime
2121
{
22-
private readonly PsesInternalHost psesHost;
23-
private readonly WorkspaceService workspace;
22+
private PsesInternalHost psesHost;
23+
private WorkspaceService workspace;
2424

25-
public RefactorUtilitiesTests()
25+
public async Task InitializeAsync()
2626
{
27-
psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance);
27+
psesHost = await PsesHostFactory.Create(NullLoggerFactory.Instance);
2828
workspace = new WorkspaceService(NullLoggerFactory.Instance);
2929
}
3030

31-
public void Dispose()
32-
{
33-
#pragma warning disable VSTHRD002
34-
psesHost.StopAsync().Wait();
35-
#pragma warning restore VSTHRD002
36-
GC.SuppressFinalize(this);
37-
}
31+
public async Task DisposeAsync() => await Task.Run(psesHost.StopAsync);
3832
private ScriptFile GetTestScript(string fileName) => workspace.GetFile(TestUtilities.GetSharedPath(Path.Combine("Refactoring\\Utilities", fileName)));
3933

4034
[Fact]

test/PowerShellEditorServices.Test/Refactoring/RefactorVariableTests.cs

+9-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Threading.Tasks;
67
using Microsoft.Extensions.Logging.Abstractions;
78
using Microsoft.PowerShell.EditorServices.Services;
89
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
@@ -17,18 +18,17 @@
1718
namespace PowerShellEditorServices.Test.Refactoring
1819
{
1920
[Trait("Category", "RenameVariables")]
20-
public class RefactorVariableTests : IDisposable
21+
public class RefactorVariableTests : IAsyncLifetime
2122

2223
{
23-
private readonly PsesInternalHost psesHost;
24-
private readonly WorkspaceService workspace;
25-
public void Dispose()
24+
private PsesInternalHost psesHost;
25+
private WorkspaceService workspace;
26+
public async Task InitializeAsync()
2627
{
27-
#pragma warning disable VSTHRD002
28-
psesHost.StopAsync().Wait();
29-
#pragma warning restore VSTHRD002
30-
GC.SuppressFinalize(this);
28+
psesHost = await PsesHostFactory.Create(NullLoggerFactory.Instance);
29+
workspace = new WorkspaceService(NullLoggerFactory.Instance);
3130
}
31+
public async Task DisposeAsync() => await Task.Run(psesHost.StopAsync);
3232
private ScriptFile GetTestScript(string fileName) => workspace.GetFile(TestUtilities.GetSharedPath(Path.Combine("Refactoring\\Variables", fileName)));
3333

3434
internal static string GetModifiedScript(string OriginalScript, ModifiedFileResponse Modification)
@@ -71,11 +71,7 @@ internal static string TestRenaming(ScriptFile scriptFile, RenameSymbolParams re
7171
};
7272
return GetModifiedScript(scriptFile.Contents, changes);
7373
}
74-
public RefactorVariableTests()
75-
{
76-
psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance);
77-
workspace = new WorkspaceService(NullLoggerFactory.Instance);
78-
}
74+
7975
[Fact]
8076
public void RefactorVariableSingle()
8177
{

0 commit comments

Comments
 (0)