diff --git a/CryptoExchange.Net.UnitTests/BaseClientTests.cs b/CryptoExchange.Net.UnitTests/BaseClientTests.cs index aae4a95..e7dfe45 100644 --- a/CryptoExchange.Net.UnitTests/BaseClientTests.cs +++ b/CryptoExchange.Net.UnitTests/BaseClientTests.cs @@ -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("{\"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")] diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs index 9a3c5cc..e4bd7b3 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs @@ -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 Deserialize(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(new ServerError(ErrorInfo.Unknown with { Message = data })); - - var deserializeResult = accessor.Deserialize(); - return deserializeResult; + return new CallResult(JsonSerializer.Deserialize(data)); } /// 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> GetServerTimestampAsync() => throw new NotImplementedException(); diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs index c3a3818..7c7d6f7 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs @@ -142,7 +142,6 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations /// 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> Request(CancellationToken ct = default) where T : class @@ -178,7 +177,6 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations RequestFactory = new Mock().Object; } - protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions()); protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions()); /// diff --git a/CryptoExchange.Net/Testing/Implementations/TestSocket.cs b/CryptoExchange.Net/Testing/Implementations/TestSocket.cs index 34934e6..584e275 100644 --- a/CryptoExchange.Net/Testing/Implementations/TestSocket.cs +++ b/CryptoExchange.Net/Testing/Implementations/TestSocket.cs @@ -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? 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(); diff --git a/CryptoExchange.Net/Testing/TestHelpers.cs b/CryptoExchange.Net/Testing/TestHelpers.cs index 169d186..3733566 100644 --- a/CryptoExchange.Net/Testing/TestHelpers.cs +++ b/CryptoExchange.Net/Testing/TestHelpers.cs @@ -27,8 +27,11 @@ namespace CryptoExchange.Net.Testing /// public class TestHelpers { + /// + /// Deep compare the values of two objects + /// [ExcludeFromCodeCoverage] - internal static bool AreEqual(T? self, T? to, params string[] ignore) where T : class + public static bool AreEqual(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 client, string address) where T : BaseSocketClient + /// + /// Configure a socket client + /// + public static TestSocket ConfigureSocketClient(T client, string address) where T : BaseSocketClient { var socket = new TestSocket(address); foreach (var apiClient in client.ApiClients.OfType())