mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
commit 0571ed17a0e502f689af6e8a5dbd0f05fd229496 Author: JKorf <jankorf91@gmail.com> Date: Sun Jul 10 19:56:27 2022 +0200 Fixed tests commit 99c331b389b58f09db3960adc7293d9b45d05caa Author: JKorf <jankorf91@gmail.com> Date: Sun Jul 10 16:41:14 2022 +0200 Updated version commit 70f8bd203a00fbdef2b13526133a3b556cfc897f Author: JKorf <jankorf91@gmail.com> Date: Sun Jul 10 16:36:00 2022 +0200 Finished up websocket refactoring commit 89b517c93684dc9c1e8a99bc600caaf6f9a4459e Author: JKorf <jankorf91@gmail.com> Date: Fri Jul 8 20:24:58 2022 +0200 wip commit 91e33cc42c5725aece765b6c8f6a7f35ab87a80e Author: JKorf <jankorf91@gmail.com> Date: Thu Jul 7 22:17:55 2022 +0200 wip
124 lines
3.3 KiB
C#
124 lines
3.3 KiB
C#
using System;
|
|
using System.Security.Authentication;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CryptoExchange.Net.Interfaces;
|
|
using CryptoExchange.Net.Objects;
|
|
|
|
namespace CryptoExchange.Net.UnitTests.TestImplementations
|
|
{
|
|
public class TestSocket: IWebsocket
|
|
{
|
|
public bool CanConnect { get; set; }
|
|
public bool Connected { get; set; }
|
|
|
|
public event Action OnClose;
|
|
public event Action OnReconnected;
|
|
public event Action OnReconnecting;
|
|
public event Action<string> OnMessage;
|
|
public event Action<Exception> OnError;
|
|
public event Action OnOpen;
|
|
|
|
public int Id { get; }
|
|
public bool ShouldReconnect { get; set; }
|
|
public TimeSpan Timeout { get; set; }
|
|
public Func<string, string> DataInterpreterString { get; set; }
|
|
public Func<byte[], string> DataInterpreterBytes { get; set; }
|
|
public DateTime? DisconnectTime { get; set; }
|
|
public string Url { get; }
|
|
public bool IsClosed => !Connected;
|
|
public bool IsOpen => Connected;
|
|
public bool PingConnection { get; set; }
|
|
public TimeSpan PingInterval { get; set; }
|
|
public SslProtocols SSLProtocols { get; set; }
|
|
public Encoding Encoding { get; set; }
|
|
|
|
public int ConnectCalls { get; private set; }
|
|
public bool Reconnecting { get; set; }
|
|
public string Origin { get; set; }
|
|
public int? RatelimitPerSecond { get; set; }
|
|
|
|
public double IncomingKbps => throw new NotImplementedException();
|
|
|
|
public Uri Uri => new Uri("");
|
|
|
|
public TimeSpan KeepAliveInterval { get; set; }
|
|
|
|
public static int lastId = 0;
|
|
public static object lastIdLock = new object();
|
|
|
|
public TestSocket()
|
|
{
|
|
lock (lastIdLock)
|
|
{
|
|
Id = lastId + 1;
|
|
lastId++;
|
|
}
|
|
}
|
|
|
|
public Task<bool> ConnectAsync()
|
|
{
|
|
Connected = CanConnect;
|
|
ConnectCalls++;
|
|
if (CanConnect)
|
|
InvokeOpen();
|
|
return Task.FromResult(CanConnect);
|
|
}
|
|
|
|
public void Send(string data)
|
|
{
|
|
if(!Connected)
|
|
throw new Exception("Socket not connected");
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
}
|
|
|
|
public Task CloseAsync()
|
|
{
|
|
Connected = false;
|
|
DisconnectTime = DateTime.UtcNow;
|
|
OnClose?.Invoke();
|
|
return Task.FromResult(0);
|
|
}
|
|
|
|
public void SetProxy(string host, int port)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public void InvokeClose()
|
|
{
|
|
Connected = false;
|
|
DisconnectTime = DateTime.UtcNow;
|
|
Reconnecting = true;
|
|
OnClose?.Invoke();
|
|
}
|
|
|
|
public void InvokeOpen()
|
|
{
|
|
OnOpen?.Invoke();
|
|
}
|
|
|
|
public void InvokeMessage(string data)
|
|
{
|
|
OnMessage?.Invoke(data);
|
|
}
|
|
|
|
public void SetProxy(ApiProxy proxy)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void InvokeError(Exception error)
|
|
{
|
|
OnError?.Invoke(error);
|
|
}
|
|
public Task ReconnectAsync() => Task.CompletedTask;
|
|
}
|
|
}
|