-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuntimeExplorerTests.cs
54 lines (42 loc) · 1.67 KB
/
RuntimeExplorerTests.cs
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
namespace CSharpInteractive.Tests;
using System.Diagnostics.CodeAnalysis;
[SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")]
public class RuntimeExplorerTests
{
private readonly Mock<IFileSystem> _fileSystem = new();
[Fact]
public void ShouldFindRuntime()
{
// Given
var explorer = CreateInstance();
_fileSystem.Setup(i => i.EnumerateFileSystemEntries("Runtime", "Abc.dll", SearchOption.TopDirectoryOnly)).Returns(["Xyz.dll", "Hjk"]);
// When
explorer.TryFindRuntimeAssembly(Path.Combine("Bin", "Abc.dll"), out var runtimePath).ShouldBeTrue();
// Then
runtimePath.ShouldBe("Xyz.dll");
}
[Fact]
public void ShouldReturnFalseWhenCannotFindRuntime()
{
// Given
var explorer = CreateInstance();
_fileSystem.Setup(i => i.EnumerateFileSystemEntries("Runtime", "Abc.dll", SearchOption.TopDirectoryOnly)).Returns(Array.Empty<string>());
// When
explorer.TryFindRuntimeAssembly(Path.Combine("Bin", "Abc.dll"), out _).ShouldBeFalse();
// Then
}
[Theory]
[InlineData("")]
[InlineData(" ")]
public void ShouldReturnFalseWhenRuntimePathIsEmpty(string runtime)
{
// Given
var explorer = CreateInstance(runtime);
// When
explorer.TryFindRuntimeAssembly(Path.Combine("Bin", "Abc.dll"), out _).ShouldBeFalse();
// Then
_fileSystem.Verify(i => i.EnumerateFileSystemEntries(It.IsAny<string>(), It.IsAny<string>(), SearchOption.TopDirectoryOnly), Times.Never);
}
private RuntimeExplorer CreateInstance(string runtime = "Runtime") =>
new(runtime, _fileSystem.Object);
}