mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-18 03:43:00 +00:00
Refactor clients/options
This commit is contained in:
@@ -8,11 +8,11 @@ namespace CryptoExchange.Net.UnitTests
|
||||
{
|
||||
public class TestBaseClient: BaseClient
|
||||
{
|
||||
public TestBaseClient(): base("Test", new RestClientOptions())
|
||||
public TestBaseClient(): base("Test", new BaseClientOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public TestBaseClient(RestClientOptions exchangeOptions) : base("Test", exchangeOptions)
|
||||
public TestBaseClient(BaseRestClientOptions exchangeOptions) : base("Test", exchangeOptions)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -15,17 +15,19 @@ using System.Collections.Generic;
|
||||
|
||||
namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
public class TestRestClient: RestClient
|
||||
public class TestRestClient: BaseRestClient
|
||||
{
|
||||
public TestRestSubClient SubClient { get; }
|
||||
public TestRestApi1Client Api1 { get; }
|
||||
public TestRestApi2Client Api2 { get; }
|
||||
|
||||
public TestRestClient() : this(new TestRestClientOptions())
|
||||
public TestRestClient() : this(new TestClientOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public TestRestClient(TestRestClientOptions exchangeOptions) : base("Test", exchangeOptions)
|
||||
public TestRestClient(TestClientOptions exchangeOptions) : base("Test", exchangeOptions)
|
||||
{
|
||||
SubClient = new TestRestSubClient(exchangeOptions);
|
||||
Api1 = new TestRestApi1Client(exchangeOptions);
|
||||
Api2 = new TestRestApi2Client(exchangeOptions);
|
||||
RequestFactory = new Mock<IRequestFactory>().Object;
|
||||
}
|
||||
|
||||
@@ -103,26 +105,35 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
|
||||
public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T:class
|
||||
{
|
||||
return await SendRequestAsync<T>(SubClient, new Uri("http://www.test.com"), HttpMethod.Get, ct);
|
||||
return await SendRequestAsync<T>(Api1, new Uri("http://www.test.com"), HttpMethod.Get, ct);
|
||||
}
|
||||
|
||||
public async Task<CallResult<T>> RequestWithParams<T>(HttpMethod method, Dictionary<string, object> parameters, Dictionary<string, string> headers) where T : class
|
||||
{
|
||||
return await SendRequestAsync<T>(SubClient, new Uri("http://www.test.com"), method, default, parameters, additionalHeaders: headers);
|
||||
return await SendRequestAsync<T>(Api1, new Uri("http://www.test.com"), method, default, parameters, additionalHeaders: headers);
|
||||
}
|
||||
}
|
||||
|
||||
public class TestRestSubClient: RestSubClient
|
||||
public class TestRestApi1Client : RestApiClient
|
||||
{
|
||||
public TestRestSubClient(TestRestClientOptions options): base(options.SubOptions, null)
|
||||
public TestRestApi1Client(TestClientOptions options): base(options, options.Api1Options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
|
||||
=> new TestAuthProvider(credentials);
|
||||
}
|
||||
|
||||
public class TestRestClientOptions: RestClientOptions
|
||||
public class TestRestApi2Client : RestApiClient
|
||||
{
|
||||
public RestSubClientOptions SubOptions { get; set; } = new RestSubClientOptions();
|
||||
public TestRestApi2Client(TestClientOptions options) : base(options, options.Api2Options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
|
||||
=> new TestAuthProvider(credentials);
|
||||
}
|
||||
|
||||
public class TestAuthProvider : AuthenticationProvider
|
||||
@@ -135,7 +146,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
public class ParseErrorTestRestClient: TestRestClient
|
||||
{
|
||||
public ParseErrorTestRestClient() { }
|
||||
public ParseErrorTestRestClient(TestRestClientOptions exchangeOptions) : base(exchangeOptions) { }
|
||||
public ParseErrorTestRestClient(TestClientOptions exchangeOptions) : base(exchangeOptions) { }
|
||||
|
||||
protected override Error ParseErrorResponse(JToken error)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Logging;
|
||||
using CryptoExchange.Net.Objects;
|
||||
@@ -9,7 +10,7 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
public class TestSocketClient: SocketClient
|
||||
public class TestSocketClient: BaseSocketClient
|
||||
{
|
||||
public TestSubSocketClient SubClient { get; }
|
||||
|
||||
@@ -19,7 +20,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
|
||||
public TestSocketClient(TestOptions exchangeOptions) : base("test", exchangeOptions)
|
||||
{
|
||||
SubClient = new TestSubSocketClient(exchangeOptions.SubOptions);
|
||||
SubClient = new TestSubSocketClient(exchangeOptions, exchangeOptions.SubOptions);
|
||||
SocketFactory = new Mock<IWebsocketFactory>().Object;
|
||||
Mock.Get(SocketFactory).Setup(f => f.CreateWebsocket(It.IsAny<Log>(), It.IsAny<string>())).Returns(new TestSocket());
|
||||
}
|
||||
@@ -67,17 +68,20 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
}
|
||||
}
|
||||
|
||||
public class TestOptions: SocketClientOptions
|
||||
public class TestOptions: BaseSocketClientOptions
|
||||
{
|
||||
public SubClientOptions SubOptions { get; set; } = new SubClientOptions();
|
||||
public ApiClientOptions SubOptions { get; set; } = new ApiClientOptions();
|
||||
}
|
||||
|
||||
public class TestSubSocketClient : SocketSubClient
|
||||
public class TestSubSocketClient : SocketApiClient
|
||||
{
|
||||
|
||||
public TestSubSocketClient(SubClientOptions options): base(options, options.ApiCredentials == null ? null: new TestAuthProvider(options.ApiCredentials))
|
||||
public TestSubSocketClient(BaseClientOptions options, ApiClientOptions apiOptions): base(options, apiOptions)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
|
||||
=> new TestAuthProvider(credentials);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user