mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-14 01:42:55 +00:00
Disposable changes, fixed tests
This commit is contained in:
@@ -8,11 +8,11 @@ namespace CryptoExchange.Net.UnitTests
|
||||
{
|
||||
public class TestBaseClient: BaseClient
|
||||
{
|
||||
public TestBaseClient(): base("Test", new RestClientOptions(), null)
|
||||
public TestBaseClient(): base("Test", new RestClientOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public TestBaseClient(RestClientOptions exchangeOptions) : base("Test", exchangeOptions, exchangeOptions.ApiCredentials == null ? null : new TestAuthProvider(exchangeOptions.ApiCredentials))
|
||||
public TestBaseClient(RestClientOptions exchangeOptions) : base("Test", exchangeOptions)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,11 +25,6 @@ namespace CryptoExchange.Net.UnitTests
|
||||
{
|
||||
return Deserialize<T>(data, null, null);
|
||||
}
|
||||
|
||||
public string FillParameters(string path, params string[] values)
|
||||
{
|
||||
return FillPathParameter(path, values);
|
||||
}
|
||||
}
|
||||
|
||||
public class TestAuthProvider : AuthenticationProvider
|
||||
|
||||
@@ -17,13 +17,15 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
public class TestRestClient: RestClient
|
||||
{
|
||||
public TestRestClient() : base("Test", new RestClientOptions(), null)
|
||||
public TestRestSubClient SubClient { get; }
|
||||
|
||||
public TestRestClient() : this(new TestRestClientOptions())
|
||||
{
|
||||
RequestFactory = new Mock<IRequestFactory>().Object;
|
||||
}
|
||||
|
||||
public TestRestClient(RestClientOptions exchangeOptions) : base("Test", exchangeOptions, exchangeOptions.ApiCredentials == null ? null : new TestAuthProvider(exchangeOptions.ApiCredentials))
|
||||
public TestRestClient(TestRestClientOptions exchangeOptions) : base("Test", exchangeOptions)
|
||||
{
|
||||
SubClient = new TestRestSubClient(exchangeOptions);
|
||||
RequestFactory = new Mock<IRequestFactory>().Object;
|
||||
}
|
||||
|
||||
@@ -32,11 +34,6 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
ParameterPositions[method] = position;
|
||||
}
|
||||
|
||||
public void SetKey(string key, string secret)
|
||||
{
|
||||
SetAuthenticationProvider(new UnitTests.TestAuthProvider(new ApiCredentials(key, secret)));
|
||||
}
|
||||
|
||||
public void SetResponse(string responseData, out IRequest requestObj)
|
||||
{
|
||||
var expectedBytes = Encoding.UTF8.GetBytes(responseData);
|
||||
@@ -106,15 +103,28 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
|
||||
public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T:class
|
||||
{
|
||||
return await SendRequestAsync<T>(new Uri("http://www.test.com"), HttpMethod.Get, ct);
|
||||
return await SendRequestAsync<T>(SubClient, 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>(new Uri("http://www.test.com"), method, default, parameters, additionalHeaders: headers);
|
||||
return await SendRequestAsync<T>(SubClient, new Uri("http://www.test.com"), method, default, parameters, additionalHeaders: headers);
|
||||
}
|
||||
}
|
||||
|
||||
public class TestRestSubClient: RestSubClient
|
||||
{
|
||||
public TestRestSubClient(TestRestClientOptions options): base(options.SubOptions, null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class TestRestClientOptions: RestClientOptions
|
||||
{
|
||||
public RestSubClientOptions SubOptions { get; set; } = new RestSubClientOptions();
|
||||
}
|
||||
|
||||
public class TestAuthProvider : AuthenticationProvider
|
||||
{
|
||||
public TestAuthProvider(ApiCredentials credentials) : base(credentials)
|
||||
@@ -125,7 +135,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
public class ParseErrorTestRestClient: TestRestClient
|
||||
{
|
||||
public ParseErrorTestRestClient() { }
|
||||
public ParseErrorTestRestClient(RestClientOptions exchangeOptions) : base(exchangeOptions) { }
|
||||
public ParseErrorTestRestClient(TestRestClientOptions exchangeOptions) : base(exchangeOptions) { }
|
||||
|
||||
protected override Error ParseErrorResponse(JToken error)
|
||||
{
|
||||
|
||||
@@ -11,12 +11,15 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
public class TestSocketClient: SocketClient
|
||||
{
|
||||
public TestSocketClient() : this(new SocketClientOptions())
|
||||
public TestSubSocketClient SubClient { get; }
|
||||
|
||||
public TestSocketClient() : this(new TestOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public TestSocketClient(SocketClientOptions exchangeOptions) : base("test", exchangeOptions, exchangeOptions.ApiCredentials == null ? null : new TestAuthProvider(exchangeOptions.ApiCredentials))
|
||||
public TestSocketClient(TestOptions exchangeOptions) : base("test", exchangeOptions)
|
||||
{
|
||||
SubClient = new TestSubSocketClient(exchangeOptions.SubOptions);
|
||||
SocketFactory = new Mock<IWebsocketFactory>().Object;
|
||||
Mock.Get(SocketFactory).Setup(f => f.CreateWebsocket(It.IsAny<Log>(), It.IsAny<string>())).Returns(new TestSocket());
|
||||
}
|
||||
@@ -24,7 +27,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
public TestSocket CreateSocket()
|
||||
{
|
||||
Mock.Get(SocketFactory).Setup(f => f.CreateWebsocket(It.IsAny<Log>(), It.IsAny<string>())).Returns(new TestSocket());
|
||||
return (TestSocket)CreateSocket(ClientOptions.BaseAddress);
|
||||
return (TestSocket)CreateSocket("123");
|
||||
}
|
||||
|
||||
public CallResult<bool> ConnectSocketSub(SocketConnection sub)
|
||||
@@ -63,4 +66,18 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class TestOptions: SocketClientOptions
|
||||
{
|
||||
public SubClientOptions SubOptions { get; set; } = new SubClientOptions();
|
||||
}
|
||||
|
||||
public class TestSubSocketClient : SocketSubClient
|
||||
{
|
||||
|
||||
public TestSubSocketClient(SubClientOptions options): base(options, options.ApiCredentials == null ? null: new TestAuthProvider(options.ApiCredentials))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user