1
0
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:
Jkorf 2026-01-21 15:38:22 +01:00
parent cff33bb5ac
commit fff70a9c65
5 changed files with 23 additions and 29 deletions

View File

@ -19,20 +19,6 @@ namespace CryptoExchange.Net.UnitTests
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")]

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Clients;
@ -51,19 +52,11 @@ namespace CryptoExchange.Net.UnitTests
public CallResult<T> Deserialize<T>(string data)
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(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;
return new CallResult<T>(JsonSerializer.Deserialize<T>(data));
}
/// <inheritdoc />
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 AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException();
protected override Task<WebCallResult<DateTime>> GetServerTimestampAsync() => throw new NotImplementedException();

View File

@ -142,7 +142,6 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
/// <inheritdoc />
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());
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;
}
protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions());
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
/// <inheritdoc />

View File

@ -12,7 +12,8 @@ using CryptoExchange.Net.Sockets.Default.Interfaces;
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;
@ -108,7 +109,17 @@ namespace CryptoExchange.Net.Testing.Implementations
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 UpdateProxy(ApiProxy? proxy) => throw new NotImplementedException();

View File

@ -27,8 +27,11 @@ namespace CryptoExchange.Net.Testing
/// </summary>
public class TestHelpers
{
/// <summary>
/// Deep compare the values of two objects
/// </summary>
[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)
{
@ -61,7 +64,10 @@ namespace CryptoExchange.Net.Testing
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);
foreach (var apiClient in client.ApiClients.OfType<SocketApiClient>())