mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 16:36:15 +00:00
Added test websocket for unit testing
This commit is contained in:
parent
e3d58c2d25
commit
c41b330f0f
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
|
||||
|
68
CryptoExchange.Net/Implementation/TestWebsocket.cs
Normal file
68
CryptoExchange.Net/Implementation/TestWebsocket.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Security.Authentication;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
|
||||
namespace CryptoExchange.Net.Implementation
|
||||
{
|
||||
public class TestWebsocket: IWebsocket
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetEnabledSslProtocols(SslProtocols protocols)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetProxy(string host, int port)
|
||||
{
|
||||
}
|
||||
|
||||
public event Action OnClose;
|
||||
public event Action<string> OnMessage;
|
||||
public event Action<Exception> OnError;
|
||||
public event Action OnOpen;
|
||||
|
||||
public bool IsClosed { get; private set; }
|
||||
public bool IsOpen { get; private set; }
|
||||
public bool PingConnection { get; set; }
|
||||
public TimeSpan PingInterval { get; set; }
|
||||
|
||||
public Task<bool> Connect()
|
||||
{
|
||||
IsClosed = false;
|
||||
IsOpen = true;
|
||||
OnOpen?.Invoke();
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public void Send(string data)
|
||||
{
|
||||
}
|
||||
|
||||
public void EnqueueMessage(string data)
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
OnMessage?.Invoke(data);
|
||||
}
|
||||
|
||||
public void InvokeError(Exception ex, bool closeConnection)
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
OnError?.Invoke(ex);
|
||||
if (closeConnection)
|
||||
Close();
|
||||
}
|
||||
|
||||
public Task Close()
|
||||
{
|
||||
IsClosed = true;
|
||||
IsOpen = false;
|
||||
OnClose?.Invoke();
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
13
CryptoExchange.Net/Implementation/TestWebsocketFactory.cs
Normal file
13
CryptoExchange.Net/Implementation/TestWebsocketFactory.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Logging;
|
||||
|
||||
namespace CryptoExchange.Net.Implementation
|
||||
{
|
||||
public class TestWebsocketFactory : IWebsocketFactory
|
||||
{
|
||||
public IWebsocket CreateWebsocket(Log log, string url)
|
||||
{
|
||||
return new TestWebsocket();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user