2021-03-11 09:32:22 -08:00
|
|
|
#if !NETSTANDARD2_1 || NET5_0
|
2017-12-11 05:21:09 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Net.WebSockets;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2020-04-14 20:08:03 -04:00
|
|
|
namespace k8s.Tests.Mock
|
2017-12-11 05:21:09 +01:00
|
|
|
{
|
|
|
|
|
public class MockWebSocketBuilder : WebSocketBuilder
|
|
|
|
|
{
|
2020-04-23 11:40:06 -07:00
|
|
|
public Dictionary<string, string> RequestHeaders { get; }
|
|
|
|
|
= new Dictionary<string, string>();
|
2017-12-11 05:21:09 +01:00
|
|
|
|
2020-04-23 11:40:06 -07:00
|
|
|
public Collection<X509Certificate2> Certificates { get; }
|
|
|
|
|
= new Collection<X509Certificate2>();
|
2017-12-11 05:21:09 +01:00
|
|
|
|
|
|
|
|
public Uri Uri { get; private set; }
|
|
|
|
|
|
|
|
|
|
public WebSocket PublicWebSocket => this.WebSocket;
|
|
|
|
|
|
2018-03-20 16:03:28 +11:00
|
|
|
public override WebSocketBuilder AddClientCertificate(X509Certificate2 certificate)
|
2017-12-11 05:21:09 +01:00
|
|
|
{
|
|
|
|
|
this.Certificates.Add(certificate);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task<WebSocket> BuildAndConnectAsync(Uri uri, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2020-04-23 11:40:06 -07:00
|
|
|
this.Uri
|
|
|
|
|
= uri;
|
2018-03-20 16:03:28 +11:00
|
|
|
|
|
|
|
|
return Task.FromResult(this.PublicWebSocket);
|
2017-12-11 05:21:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override WebSocketBuilder SetRequestHeader(string headerName, string headerValue)
|
|
|
|
|
{
|
|
|
|
|
this.RequestHeaders.Add(headerName, headerValue);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-20 16:03:28 +11:00
|
|
|
|
2021-03-11 09:32:22 -08:00
|
|
|
#endif // !NETSTANDARD2_1 || NET5_0
|