mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-02-16 14:13:46 +00:00
Updated some testing
This commit is contained in:
parent
cff33bb5ac
commit
fff70a9c65
@ -19,20 +19,6 @@ namespace CryptoExchange.Net.UnitTests
|
|||||||
Assert.That(result.Success);
|
Assert.That(result.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase]
|
|
||||||
public void DeserializingInvalidJson_Should_GiveErrorResult()
|
|
||||||
{
|
|
||||||
// arrange
|
|
||||||
var client = new TestBaseClient();
|
|
||||||
|
|
||||||
// act
|
|
||||||
var result = client.SubClient.Deserialize<object>("{\"testProperty\": 123");
|
|
||||||
|
|
||||||
// assert
|
|
||||||
ClassicAssert.IsFalse(result.Success);
|
|
||||||
Assert.That(result.Error != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestCase("https://api.test.com/api", new[] { "path1", "path2" }, "https://api.test.com/api/path1/path2")]
|
[TestCase("https://api.test.com/api", new[] { "path1", "path2" }, "https://api.test.com/api/path1/path2")]
|
||||||
[TestCase("https://api.test.com/api", new[] { "path1", "/path2" }, "https://api.test.com/api/path1/path2")]
|
[TestCase("https://api.test.com/api", new[] { "path1", "/path2" }, "https://api.test.com/api/path1/path2")]
|
||||||
[TestCase("https://api.test.com/api", new[] { "path1/", "path2" }, "https://api.test.com/api/path1/path2")]
|
[TestCase("https://api.test.com/api", new[] { "path1/", "path2" }, "https://api.test.com/api/path1/path2")]
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CryptoExchange.Net.Authentication;
|
using CryptoExchange.Net.Authentication;
|
||||||
using CryptoExchange.Net.Clients;
|
using CryptoExchange.Net.Clients;
|
||||||
@ -51,19 +52,11 @@ namespace CryptoExchange.Net.UnitTests
|
|||||||
|
|
||||||
public CallResult<T> Deserialize<T>(string data)
|
public CallResult<T> Deserialize<T>(string data)
|
||||||
{
|
{
|
||||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
|
return new CallResult<T>(JsonSerializer.Deserialize<T>(data));
|
||||||
var accessor = CreateAccessor();
|
|
||||||
var valid = accessor.Read(stream, true).Result;
|
|
||||||
if (!valid)
|
|
||||||
return new CallResult<T>(new ServerError(ErrorInfo.Unknown with { Message = data }));
|
|
||||||
|
|
||||||
var deserializeResult = accessor.Deserialize<T>();
|
|
||||||
return deserializeResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||||
protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions());
|
|
||||||
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
||||||
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException();
|
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException();
|
||||||
protected override Task<WebCallResult<DateTime>> GetServerTimestampAsync() => throw new NotImplementedException();
|
protected override Task<WebCallResult<DateTime>> GetServerTimestampAsync() => throw new NotImplementedException();
|
||||||
|
|||||||
@ -142,7 +142,6 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||||
|
|
||||||
protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions() { TypeInfoResolver = new TestSerializerContext() });
|
|
||||||
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
||||||
|
|
||||||
public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T : class
|
public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T : class
|
||||||
@ -178,7 +177,6 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
|||||||
RequestFactory = new Mock<IRequestFactory>().Object;
|
RequestFactory = new Mock<IRequestFactory>().Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions());
|
|
||||||
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -12,7 +12,8 @@ using CryptoExchange.Net.Sockets.Default.Interfaces;
|
|||||||
|
|
||||||
namespace CryptoExchange.Net.Testing.Implementations
|
namespace CryptoExchange.Net.Testing.Implementations
|
||||||
{
|
{
|
||||||
internal class TestSocket : IWebsocket
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||||
|
public class TestSocket : IWebsocket
|
||||||
{
|
{
|
||||||
public event Action<string>? OnMessageSend;
|
public event Action<string>? OnMessageSend;
|
||||||
|
|
||||||
@ -108,7 +109,17 @@ namespace CryptoExchange.Net.Testing.Implementations
|
|||||||
Connection.HandleStreamMessage2(WebSocketMessageType.Text, Encoding.UTF8.GetBytes(data));
|
Connection.HandleStreamMessage2(WebSocketMessageType.Text, Encoding.UTF8.GetBytes(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task ReconnectAsync() => Task.CompletedTask;
|
public async Task ReconnectAsync()
|
||||||
|
{
|
||||||
|
if (OnReconnecting != null)
|
||||||
|
await OnReconnecting().ConfigureAwait(false);
|
||||||
|
|
||||||
|
await Task.Delay(10).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (OnReconnected != null)
|
||||||
|
await OnReconnected().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
|
|
||||||
public void UpdateProxy(ApiProxy? proxy) => throw new NotImplementedException();
|
public void UpdateProxy(ApiProxy? proxy) => throw new NotImplementedException();
|
||||||
|
|||||||
@ -27,8 +27,11 @@ namespace CryptoExchange.Net.Testing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TestHelpers
|
public class TestHelpers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deep compare the values of two objects
|
||||||
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
internal static bool AreEqual<T>(T? self, T? to, params string[] ignore) where T : class
|
public static bool AreEqual<T>(T? self, T? to, params string[] ignore) where T : class
|
||||||
{
|
{
|
||||||
if (self != null && to != null)
|
if (self != null && to != null)
|
||||||
{
|
{
|
||||||
@ -61,7 +64,10 @@ namespace CryptoExchange.Net.Testing
|
|||||||
return self == to;
|
return self == to;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static TestSocket ConfigureSocketClient<T>(T client, string address) where T : BaseSocketClient
|
/// <summary>
|
||||||
|
/// Configure a socket client
|
||||||
|
/// </summary>
|
||||||
|
public static TestSocket ConfigureSocketClient<T>(T client, string address) where T : BaseSocketClient
|
||||||
{
|
{
|
||||||
var socket = new TestSocket(address);
|
var socket = new TestSocket(address);
|
||||||
foreach (var apiClient in client.ApiClients.OfType<SocketApiClient>())
|
foreach (var apiClient in client.ApiClients.OfType<SocketApiClient>())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user