1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-10 09:26:22 +00:00

Unit tests, fixed error response parsing

This commit is contained in:
JKorf 2018-12-04 10:15:43 +01:00
parent 8a4e8403d2
commit 0f594bf8f4
4 changed files with 64 additions and 5 deletions

View File

@ -78,7 +78,8 @@ namespace CryptoExchange.Net.UnitTests
Assert.IsFalse(result.Success);
Assert.IsTrue(result.Error != null);
Assert.IsTrue(result.Error is ServerError);
Assert.IsTrue(result.Error.Message.Contains("{\"errorMessage\": \"Invalid request\", \"errorCode\": 123}"));
Assert.IsTrue(result.Error.Message.Contains("Invalid request"));
Assert.IsTrue(result.Error.Message.Contains("123"));
}
[TestCase]

View File

@ -173,5 +173,61 @@ namespace CryptoExchange.Net.UnitTests
// assert
Assert.IsTrue(reconnected);
}
[TestCase()]
public void UnsubscribingStream_Should_CloseTheSocket()
{
// arrange
var client = new TestSocketClient(new SocketClientOptions() { ReconnectInterval = TimeSpan.Zero, LogVerbosity = LogVerbosity.Debug });
var socket = client.CreateSocket();
socket.CanConnect = true;
var sub = new SocketSubscription(socket);
client.ConnectSocketSub(sub);
var ups = new UpdateSubscription(sub);
// act
client.Unsubscribe(ups).Wait();
// assert
Assert.IsTrue(socket.Connected == false);
}
[TestCase()]
public void UnsubscribingAll_Should_CloseAllSockets()
{
// arrange
var client = new TestSocketClient(new SocketClientOptions() { ReconnectInterval = TimeSpan.Zero, LogVerbosity = LogVerbosity.Debug });
var socket1 = client.CreateSocket();
var socket2 = client.CreateSocket();
socket1.CanConnect = true;
socket2.CanConnect = true;
var sub1 = new SocketSubscription(socket1);
var sub2 = new SocketSubscription(socket2);
client.ConnectSocketSub(sub1);
client.ConnectSocketSub(sub2);
// act
client.UnsubscribeAll().Wait();
// assert
Assert.IsTrue(socket1.Connected == false);
Assert.IsTrue(socket2.Connected == false);
}
[TestCase()]
public void FailingToConnectSocket_Should_ReturnError()
{
// arrange
var client = new TestSocketClient(new SocketClientOptions() { ReconnectInterval = TimeSpan.Zero, LogVerbosity = LogVerbosity.Debug });
var socket = client.CreateSocket();
socket.CanConnect = false;
var sub = new SocketSubscription(socket);
// act
var connectResult = client.ConnectSocketSub(sub);
// assert
Assert.IsFalse(connectResult.Success);
}
}
}

View File

@ -295,7 +295,12 @@ namespace CryptoExchange.Net
}
response.Close();
return new CallResult<string>(null, ParseErrorResponse(returnedData));
var jsonResult = ValidateJson(returnedData);
if (!jsonResult.Success)
return new CallResult<string>(null, jsonResult.Error);
return new CallResult<string>(null, ParseErrorResponse(jsonResult.Data));
}
catch (Exception)
{

View File

@ -1,3 +0,0 @@
Documentation
Data interpreter for string data
Unit testing most socket stuff