-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More cohost code actions tests! (#11179)
I couldn't originally test some code actions because they used the file system, so I intended this PR to fix that by abstracting the file system away. It is that, but I also found some more tests that we lacked coverage for in cohosting, and since I find the cohosting tests to be just so wonderful (not biased at all, obviously) I thought I'd be a bit extra. I deliberately didn't try to fix any of the code actions, but I think they could probably all do with some nicer whitespace handling. Managed to avoid the self-nerd-snipe this time though.
- Loading branch information
Showing
14 changed files
with
534 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/FileSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Microsoft.CodeAnalysis.Razor.Workspaces; | ||
|
||
internal sealed class FileSystem : IFileSystem | ||
{ | ||
public IEnumerable<string> GetFiles(string workspaceDirectory, string searchPattern, SearchOption searchOption) | ||
=> Directory.GetFiles(workspaceDirectory, searchPattern, searchOption); | ||
|
||
public IEnumerable<string> GetDirectories(string workspaceDirectory) | ||
=> Directory.GetDirectories(workspaceDirectory); | ||
|
||
public bool FileExists(string filePath) | ||
=> File.Exists(filePath); | ||
|
||
public string ReadFile(string filePath) | ||
=> File.ReadAllText(filePath); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IFileSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Microsoft.CodeAnalysis.Razor.Workspaces; | ||
|
||
internal interface IFileSystem | ||
{ | ||
public IEnumerable<string> GetFiles(string workspaceDirectory, string searchPattern, SearchOption searchOption); | ||
|
||
public IEnumerable<string> GetDirectories(string workspaceDirectory); | ||
|
||
bool FileExists(string filePath); | ||
|
||
string ReadFile(string filePath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteFileSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.IO; | ||
using Microsoft.CodeAnalysis.Razor.Workspaces; | ||
|
||
namespace Microsoft.CodeAnalysis.Remote.Razor; | ||
|
||
[Export(typeof(IFileSystem)), Shared] | ||
internal class RemoteFileSystem : IFileSystem | ||
{ | ||
private IFileSystem _fileSystem = new FileSystem(); | ||
|
||
public bool FileExists(string filePath) | ||
=> _fileSystem.FileExists(filePath); | ||
|
||
public string ReadFile(string filePath) | ||
=> _fileSystem.ReadFile(filePath); | ||
|
||
public IEnumerable<string> GetDirectories(string workspaceDirectory) | ||
=> _fileSystem.GetDirectories(workspaceDirectory); | ||
|
||
public IEnumerable<string> GetFiles(string workspaceDirectory, string searchPattern, SearchOption searchOption) | ||
=> _fileSystem.GetFiles(workspaceDirectory, searchPattern, searchOption); | ||
|
||
internal TestAccessor GetTestAccessor() => new(this); | ||
|
||
internal readonly struct TestAccessor(RemoteFileSystem instance) | ||
{ | ||
public void SetFileSystem(IFileSystem fileSystem) | ||
{ | ||
instance._fileSystem = fileSystem; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.