Skip to content

Commit dd0f79f

Browse files
committed
Make EditorWorkspaceTests OS Independent
1 parent b82b81e commit dd0f79f

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

test/PowerShellEditorServices.Test/Extensions/EditorWorkspaceTests.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Threading.Tasks;
78
using Microsoft.PowerShell.EditorServices.Extensions;
89
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
@@ -13,15 +14,20 @@ namespace PowerShellEditorServices.Test.Extensions
1314
[Trait("Category", "Extensions")]
1415
public class EditorWorkspaceTests
1516
{
17+
private static readonly string WorkspacePath = Path.Combine("test");
18+
1619
[Fact]
1720
public void DocumentsReturnsOpenWorkspaceDocuments()
1821
{
22+
string firstPath = Path.Combine(WorkspacePath, "one.ps1");
23+
string secondPath = Path.Combine(WorkspacePath, "two.ps1");
24+
1925
TestEditorOperations editorOperations = new()
2026
{
2127
OpenDocuments =
2228
[
23-
new WorkspaceOpenDocument(@"C:\test\one.ps1", saved: true),
24-
new WorkspaceOpenDocument(@"C:\test\two.ps1", saved: true)
29+
new WorkspaceOpenDocument(firstPath, saved: true),
30+
new WorkspaceOpenDocument(secondPath, saved: true)
2531
]
2632
};
2733

@@ -33,20 +39,20 @@ public void DocumentsReturnsOpenWorkspaceDocuments()
3339
documents,
3440
document =>
3541
{
36-
Assert.Equal(@"C:\test\one.ps1", document.Path);
42+
Assert.Equal(firstPath, document.Path);
3743
Assert.True(document.Saved);
3844
},
3945
document =>
4046
{
41-
Assert.Equal(@"C:\test\two.ps1", document.Path);
47+
Assert.Equal(secondPath, document.Path);
4248
Assert.True(document.Saved);
4349
});
4450
}
4551

4652
[Fact]
4753
public void DocumentOpenSaveAndCloseUseWorkspaceOperations()
4854
{
49-
const string filePath = @"C:\test\file.ps1";
55+
string filePath = Path.Combine(WorkspacePath, "file.ps1");
5056
TestEditorOperations editorOperations = new()
5157
{
5258
OpenDocuments = [new WorkspaceOpenDocument(filePath, saved: true)]
@@ -69,15 +75,14 @@ public void DocumentOpenSaveAndCloseUseWorkspaceOperations()
6975
[Fact]
7076
public void DocumentToStringReturnsFileNameAndSavedStatus()
7177
{
72-
const string savedFilePath = @"C:\test\file.ps1";
73-
const string unsavedFilePath = @"C:\test\other.ps1";
78+
string savedFilePath = Path.Combine(WorkspacePath, "file.ps1");
79+
string unsavedFilePath = Path.Combine(WorkspacePath, "other.ps1");
7480
TestEditorOperations editorOperations = new()
7581
{
76-
OpenDocuments = new[]
77-
{
82+
OpenDocuments = [
7883
new WorkspaceOpenDocument(savedFilePath, saved: true),
7984
new WorkspaceOpenDocument(unsavedFilePath, saved: false)
80-
}
85+
]
8186
};
8287

8388
EditorWorkspace workspace = new(editorOperations);
@@ -94,11 +99,10 @@ public void DocumentSavedReturnsWorkspaceSavedState()
9499
{
95100
TestEditorOperations editorOperations = new()
96101
{
97-
OpenDocuments = new[]
98-
{
99-
new WorkspaceOpenDocument(@"C:\test\saved.ps1", saved: true),
100-
new WorkspaceOpenDocument(@"C:\test\unsaved.ps1", saved: false)
101-
}
102+
OpenDocuments = [
103+
new WorkspaceOpenDocument(Path.Combine(WorkspacePath, "saved.ps1"), saved: true),
104+
new WorkspaceOpenDocument(Path.Combine(WorkspacePath, "unsaved.ps1"), saved: false)
105+
]
102106
};
103107

104108
EditorWorkspace workspace = new(editorOperations);
@@ -118,9 +122,9 @@ private sealed class TestEditorOperations : IEditorOperations
118122

119123
public Task<EditorContext> GetEditorContextAsync() => Task.FromResult(default(EditorContext));
120124

121-
public string GetWorkspacePath() => @"C:\test";
125+
public string GetWorkspacePath() => WorkspacePath;
122126

123-
public string[] GetWorkspacePaths() => new[] { @"C:\test" };
127+
public string[] GetWorkspacePaths() => [WorkspacePath];
124128

125129
public WorkspaceOpenDocument[] GetWorkspaceOpenDocuments() => OpenDocuments;
126130

0 commit comments

Comments
 (0)