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);
}
}
|