1
0
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:
JKorf 2018-07-02 09:22:17 +02:00
parent e3d58c2d25
commit c41b330f0f
3 changed files with 81 additions and 1 deletions

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Interfaces;

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

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