-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
6,956 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
language: csharp | ||
mono: none | ||
solution: Kraken.Net.sln | ||
dotnet: 2.0.0 | ||
dist: xenial | ||
script: | ||
- dotnet build Kraken.Net/Kraken.Net.csproj --framework "netstandard2.0" | ||
- dotnet test Kraken.Net.UnitTests/Kraken.Net.UnitTests.csproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="Moq" Version="4.10.1" /> | ||
<PackageReference Include="NUnit" Version="3.11.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.11.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Kraken.Net\Kraken.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Newtonsoft.Json; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using CryptoExchange.Net.Authentication; | ||
using CryptoExchange.Net.Logging; | ||
using CryptoExchange.Net.Objects; | ||
using Kraken.Net.Objects; | ||
using Kraken.Net.UnitTests.TestImplementations; | ||
|
||
namespace Kraken.Net.UnitTests | ||
{ | ||
[TestFixture] | ||
public class KrakenClientTests | ||
{ | ||
[TestCase()] | ||
public void TestConversions() | ||
{ | ||
var ignoreMethods = new string[] | ||
{ | ||
"GetMarkets", | ||
"GetOrderBook", | ||
}; | ||
var defaultParameterValues = new Dictionary<string, object> | ||
{ | ||
{ "assets", new [] { "XBTUSD" } }, | ||
{"clientOrderId", null } | ||
}; | ||
|
||
var methods = typeof(KrakenClient).GetMethods(BindingFlags.Public | BindingFlags.Instance); | ||
var callResultMethods = methods.Where(m => m.ReturnType.IsGenericType && m.ReturnType.GetGenericTypeDefinition() == typeof(WebCallResult<>)); | ||
foreach (var method in callResultMethods) | ||
{ | ||
if (ignoreMethods.Contains(method.Name)) | ||
continue; | ||
|
||
var expectedType = method.ReturnType.GetGenericArguments()[0]; | ||
var expected = typeof(TestHelpers).GetMethod("CreateObjectWithTestParameters").MakeGenericMethod(expectedType).Invoke(null, null); | ||
var parameters = TestHelpers.CreateParametersForMethod(method, defaultParameterValues); | ||
var client = TestHelpers.CreateResponseClient(SerializeExpected(expected), new KrakenClientOptions(){ ApiCredentials = new ApiCredentials("Test", "Test"), LogVerbosity = LogVerbosity.Debug}); | ||
|
||
// act | ||
var result = method.Invoke(client, parameters); | ||
var callResult = result.GetType().GetProperty("Success").GetValue(result); | ||
var data = result.GetType().GetProperty("Data").GetValue(result); | ||
|
||
// assert | ||
Assert.AreEqual(true, callResult); | ||
Assert.IsTrue(TestHelpers.AreEqual(expected, data), method.Name); | ||
} | ||
} | ||
|
||
|
||
[TestCase()] | ||
public void TestErrorResult_Should_ResultInFailedCall() | ||
{ | ||
// arrange | ||
var client = TestHelpers.CreateAuthResponseClient($"{{\"error\": [\"first error\", \"another error\"], \"result\": null}}"); | ||
|
||
// act | ||
var result = client.GetMarkets(); | ||
|
||
// assert | ||
Assert.IsFalse(result.Success); | ||
Assert.IsTrue(result.Error.Message.Contains("first error")); | ||
Assert.IsTrue(result.Error.Message.Contains("another error")); | ||
} | ||
|
||
public string SerializeExpected<T>(T data) | ||
{ | ||
var result = new KrakenResult<T>() | ||
{ | ||
Result = data, | ||
Error = new string[] {} | ||
}; | ||
|
||
return JsonConvert.SerializeObject(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using CryptoExchange.Net; | ||
using CryptoExchange.Net.Objects; | ||
using Kraken.Net.UnitTests.TestImplementations; | ||
using Kucoin.Net.UnitTests.TestImplementations; | ||
using Newtonsoft.Json; | ||
using NUnit.Framework; | ||
|
||
namespace Kraken.Net.UnitTests | ||
{ | ||
[TestFixture] | ||
public class KrakenSocketClientTests | ||
{ | ||
[Test] | ||
public void Subscribe_Should_SucceedIfAckResponse() | ||
{ | ||
// arrange | ||
var socket = new TestSocket(); | ||
socket.CanConnect = true; | ||
var client = TestHelpers.CreateSocketClient(socket); | ||
|
||
// act | ||
var subTask = client.SubscribeToTickerUpdatesAsync("test", test => { }); | ||
socket.InvokeMessage($"{{\"channelID\": 1, \"status\": \"subscribed\", \"reqid\":\"{BaseClient.LastId}\"}}"); | ||
var subResult = subTask.Result; | ||
|
||
// assert | ||
Assert.IsTrue(subResult.Success); | ||
} | ||
|
||
[Test] | ||
public void Subscribe_Should_FailIfNotAckResponse() | ||
{ | ||
// arrange | ||
var socket = new TestSocket(); | ||
socket.CanConnect = true; | ||
var client = TestHelpers.CreateSocketClient(socket); | ||
|
||
// act | ||
var subTask = client.SubscribeToTickerUpdatesAsync("test", test => { }); | ||
socket.InvokeMessage($"{{\"channelID\": 1, \"status\": \"error\", \"errormessage\": \"Failed to sub\", \"reqid\":\"{BaseClient.LastId}\"}}"); | ||
var subResult = subTask.Result; | ||
|
||
// assert | ||
Assert.IsFalse(subResult.Success); | ||
Assert.IsTrue(subResult.Error.Message.Contains("Failed to sub")); | ||
} | ||
} | ||
} |
Oops, something went wrong.