-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathResolverContextTests.cs
75 lines (60 loc) · 2.1 KB
/
PathResolverContextTests.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace CSharpInteractive.Tests;
using HostApi.Internal.Cmd;
public class PathResolverContextTests
{
private readonly Mock<IHost> _host = new();
[Fact]
public void ShouldUseDefaultContext()
{
// Given
var context = CreateInstance();
// When
var resolvedPath = context.Resolve("Abc");
// Then
resolvedPath.ShouldBe("Abc");
}
[Fact]
public void ShouldUseRegisteredResolver()
{
// Given
var context = CreateInstance();
var pathResolver = new Mock<IPathResolver>();
pathResolver.Setup(i => i.Resolve(_host.Object, "Abc", It.IsAny<IPathResolver>())).Returns<IHost, string, IPathResolver>((host, path, next) => "Xyz" + next.Resolve(host, path, Mock.Of<IPathResolver>()));
// When
using var token = context.Register(pathResolver.Object);
var resolvedPath = context.Resolve("Abc");
// Then
resolvedPath.ShouldBe("XyzAbc");
}
[Fact]
public void ShouldReleaseRegisteredResolver()
{
// Given
var context = CreateInstance();
var pathResolver = new Mock<IPathResolver>();
pathResolver.Setup(i => i.Resolve(_host.Object, "Abc", It.IsAny<IPathResolver>())).Returns("Xyz");
var token = context.Register(pathResolver.Object);
// When
token.Dispose();
var resolvedPath = context.Resolve("Abc");
// Then
resolvedPath.ShouldBe("Abc");
}
[Fact]
public void ShouldPassNextResolver()
{
// Given
var context = CreateInstance();
var pathResolver1 = new Mock<IPathResolver>();
var pathResolver2 = new Mock<IPathResolver>();
pathResolver2.Setup(i => i.Resolve(_host.Object, "Abc", pathResolver1.Object)).Returns("Xyz");
// When
using var token1 = context.Register(pathResolver1.Object);
using var token2 = context.Register(pathResolver2.Object);
var resolvedPath = context.Resolve("Abc");
// Then
resolvedPath.ShouldBe("Xyz");
}
private PathResolverContext CreateInstance() =>
new(_host.Object);
}