Repository navigation
Expand file tree
/
Copy pathEditorOperationsServiceTests.cs
More file actions
55 lines (46 loc) · 2.04 KB
/
Copy pathEditorOperationsServiceTests.cs
File metadata and controls
55 lines (46 loc) · 2.04 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.IO;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.Extension;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using OmniSharp.Extensions.LanguageServer.Protocol;
using Xunit;
namespace PowerShellEditorServices.Test.Extensions
{
[Trait("Category", "Extensions")]
public class EditorOperationsServiceTests
{
[Fact]
public void GetWorkspaceOpenDocumentsReturnsOnlyOpenDocumentsAndCurrentInMemoryState()
{
WorkspaceService workspaceService = new(NullLoggerFactory.Instance);
ScriptFile openSaved = CreateFileBuffer(workspaceService, "open-saved.ps1");
openSaved.IsOpen = true;
openSaved.IsInMemory = false;
ScriptFile openUnsaved = CreateFileBuffer(workspaceService, "open-unsaved.ps1");
openUnsaved.IsOpen = true;
openUnsaved.IsInMemory = true;
ScriptFile closed = CreateFileBuffer(workspaceService, "closed.ps1");
closed.IsOpen = false;
closed.IsInMemory = false;
EditorOperationsService editorOperationsService = new(
psesHost: null,
workspaceService,
languageServer: null);
WorkspaceOpenDocument[] documents = editorOperationsService.GetWorkspaceOpenDocuments();
Assert.Equal(2, documents.Length);
Assert.Contains(documents, static document => document.Path.EndsWith("open-saved.ps1") && document.Saved);
Assert.Contains(documents, static document => document.Path.EndsWith("open-unsaved.ps1") && !document.Saved);
Assert.DoesNotContain(documents, static document => document.Path.EndsWith("closed.ps1"));
}
private static ScriptFile CreateFileBuffer(WorkspaceService workspaceService, string fileName)
{
string filePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"), fileName);
return workspaceService.GetFileBuffer(DocumentUri.FromFileSystemPath(filePath), initialBuffer: string.Empty);
}
}
}