File: MockTunnelRelayStreamFactory.cs

package info (click to toggle)
golang-github-microsoft-dev-tunnels 0.0.25-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,988 kB
  • sloc: cs: 9,969; java: 2,767; javascript: 328; xml: 186; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download
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
using Microsoft.DevTunnels.Connections;
using Xunit;

namespace Microsoft.DevTunnels.Test.Mocks;

public class MockTunnelRelayStreamFactory : ITunnelRelayStreamFactory
{
    private readonly string connectionType;
    private readonly Stream stream;

    public MockTunnelRelayStreamFactory(string connectionType, Stream stream = null)
    {
        this.connectionType = connectionType;
        this.stream = stream;
        StreamFactory = (string accessToken) => Task.FromResult(this.stream);
    }

    public Func<string, Task<Stream>> StreamFactory { get; set; }

    public async Task<(Stream, string)> CreateRelayStreamAsync(
        Uri relayUri,
        string accessToken,
        string[] subprotocols,
        CancellationToken cancellation)
    {
        Assert.NotNull(relayUri);
        Assert.NotNull(accessToken);
        Assert.Contains(this.connectionType, subprotocols);

        var stream = await StreamFactory(accessToken);
        return (stream, this.connectionType);
    }
}