Repository navigation
Expand file tree
/
Copy pathEditorWorkspaceTests.cs
More file actions
153 lines (119 loc) · 5.37 KB
/
Copy pathEditorWorkspaceTests.cs
File metadata and controls
153 lines (119 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Xunit;
namespace PowerShellEditorServices.Test.Extensions
{
[Trait("Category", "Extensions")]
public class EditorWorkspaceTests
{
private static readonly string WorkspacePath = Path.Combine("test");
[Fact]
public void DocumentsReturnsOpenWorkspaceDocuments()
{
string firstPath = Path.Combine(WorkspacePath, "one.ps1");
string secondPath = Path.Combine(WorkspacePath, "two.ps1");
TestEditorOperations editorOperations = new()
{
OpenDocuments =
[
new WorkspaceOpenDocument(firstPath, saved: true),
new WorkspaceOpenDocument(secondPath, saved: true)
]
};
EditorWorkspace workspace = new(editorOperations);
WorkspaceOpenDocument[] documents = workspace.Documents;
Assert.Collection(
documents,
document =>
{
Assert.Equal(firstPath, document.Path);
Assert.True(document.Saved);
},
document =>
{
Assert.Equal(secondPath, document.Path);
Assert.True(document.Saved);
});
}
[Fact]
public void DocumentToStringReturnsFileNameAndSavedStatus()
{
string savedFilePath = Path.Combine(WorkspacePath, "file.ps1");
string unsavedFilePath = Path.Combine(WorkspacePath, "other.ps1");
TestEditorOperations editorOperations = new()
{
OpenDocuments = [
new WorkspaceOpenDocument(savedFilePath, saved: true),
new WorkspaceOpenDocument(unsavedFilePath, saved: false)
]
};
EditorWorkspace workspace = new(editorOperations);
IEnumerable<WorkspaceOpenDocument> documents = workspace.Documents;
Assert.Collection(
documents,
document => Assert.Equal("file.ps1", document.ToString()),
document => Assert.Equal("other.ps1 [Unsaved]", document.ToString()));
}
[Fact]
public void DocumentSavedReturnsWorkspaceSavedState()
{
TestEditorOperations editorOperations = new()
{
OpenDocuments = [
new WorkspaceOpenDocument(Path.Combine(WorkspacePath, "saved.ps1"), saved: true),
new WorkspaceOpenDocument(Path.Combine(WorkspacePath, "unsaved.ps1"), saved: false)
]
};
EditorWorkspace workspace = new(editorOperations);
IEnumerable<WorkspaceOpenDocument> documents = workspace.Documents;
Assert.Collection(
documents,
document => Assert.True(document.Saved),
document => Assert.False(document.Saved));
}
private sealed class TestEditorOperations : IEditorOperations
{
public WorkspaceOpenDocument[] OpenDocuments { get; set; } = Array.Empty<WorkspaceOpenDocument>();
public List<string> Calls { get; } = new();
public Task<EditorContext> GetEditorContextAsync() => Task.FromResult(default(EditorContext));
public string GetWorkspacePath() => WorkspacePath;
public string[] GetWorkspacePaths() => [WorkspacePath];
public WorkspaceOpenDocument[] GetWorkspaceOpenDocuments() => OpenDocuments;
public string GetWorkspaceRelativePath(ScriptFile scriptFile) => scriptFile.FilePath;
public Task NewFileAsync() => Task.CompletedTask;
public Task NewFileAsync(string content) => Task.CompletedTask;
public Task OpenFileAsync(string filePath)
{
Calls.Add("OpenFile:" + filePath);
return Task.CompletedTask;
}
public Task OpenFileAsync(string filePath, bool preview) => Task.CompletedTask;
public Task CloseFileAsync(string filePath)
{
Calls.Add("CloseFile:" + filePath);
return Task.CompletedTask;
}
public Task SaveFileAsync(string filePath)
{
Calls.Add("SaveFile:" + filePath);
return Task.CompletedTask;
}
public Task SaveFileAsync(string oldFilePath, string newFilePath) => Task.CompletedTask;
public Task InsertTextAsync(string filePath, string insertText, BufferRange insertRange) => Task.CompletedTask;
public Task SetSelectionAsync(BufferRange selectionRange) => Task.CompletedTask;
public Task ShowInformationMessageAsync(string message) => Task.CompletedTask;
public Task ShowErrorMessageAsync(string message) => Task.CompletedTask;
public Task ShowWarningMessageAsync(string message) => Task.CompletedTask;
public Task SetStatusBarMessageAsync(string message, int? timeout) => Task.CompletedTask;
public void ClearTerminal()
{
}
}
}
}