Skip to content

Commit 6009456

Browse files
Razmo99JustinGrote
authored andcommitted
Adjusted refactoring Tests to use IAsyncLifetime instead of IDisposable
1 parent d3d5738 commit 6009456

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

test/PowerShellEditorServices.Test/Refactoring/RefactorFunctionTests.cs

Lines changed: 10 additions & 13 deletions
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

Lines changed: 7 additions & 13 deletions
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;
@@ -20,24 +20,18 @@
2020
namespace PowerShellEditorServices.Test.Refactoring
2121
{
2222
[Trait("Category", "RefactorUtilities")]
23-
public class RefactorUtilitiesTests : IDisposable
23+
public class RefactorUtilitiesTests : IAsyncLifetime
2424
{
25-
private readonly PsesInternalHost psesHost;
26-
private readonly WorkspaceService workspace;
25+
private PsesInternalHost psesHost;
26+
private WorkspaceService workspace;
2727

28-
public RefactorUtilitiesTests()
28+
public async Task InitializeAsync()
2929
{
30-
psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance);
30+
psesHost = await PsesHostFactory.Create(NullLoggerFactory.Instance);
3131
workspace = new WorkspaceService(NullLoggerFactory.Instance);
3232
}
3333

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

4337
[Fact]

test/PowerShellEditorServices.Test/Refactoring/RefactorVariableTests.cs

Lines changed: 9 additions & 13 deletions
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)