1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-07-23 01:45:31 +00:00

Some small fixes

This commit is contained in:
Jkorf 2025-03-06 16:13:03 +01:00
parent bf103ce9d1
commit 54aa6907f9
5 changed files with 24 additions and 20 deletions

View File

@ -35,20 +35,9 @@ namespace CryptoExchange.Net.Authentication
/// </summary>
/// <param name="key">The api key / label used for identification</param>
/// <param name="secret">The api secret or private key used for signing</param>
/// <param name="credentialType">The type of credentials</param>
public ApiCredentials(string key, string secret, ApiCredentialsType credentialType = ApiCredentialsType.Hmac)
: this(key, secret, null, credentialType)
{
}
/// <summary>
/// Create Api credentials providing an api key, secret and pass for authentication
/// </summary>
/// <param name="key">The api key / label used for identification</param>
/// <param name="secret">The api secret or private key used for signing</param>
/// <param name="pass">The api pass for the key. Not always needed</param>
/// <param name="credentialType">The type of credentials</param>
public ApiCredentials(string key, string secret, string? pass, ApiCredentialsType credentialType = ApiCredentialsType.Hmac)
public ApiCredentials(string key, string secret, string? pass = null, ApiCredentialsType credentialType = ApiCredentialsType.Hmac)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(secret))
throw new ArgumentException("Key and secret can't be null/empty");

View File

@ -29,7 +29,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
/// </summary>
/// <param name="enumValue"></param>
/// <returns></returns>
public static string? GetString<T>(T enumValue) where T : struct, Enum
public static string GetString<T>(T enumValue) where T : struct, Enum
=> EnumConverter<T>.GetString(enumValue);
/// <summary>

View File

@ -7,7 +7,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
/// <summary>
/// Attribute to mark a model as json serializable. Used for AOT compilation.
/// </summary>
[AttributeUsage(System.AttributeTargets.Class | AttributeTargets.Enum)]
[AttributeUsage(System.AttributeTargets.Class | AttributeTargets.Enum | System.AttributeTargets.Interface)]
public class SerializationModelAttribute : Attribute
{
}

View File

@ -131,7 +131,7 @@ namespace CryptoExchange.Net.Testing.Comparers
}
}
}
else
else if (jsonObject.ValueKind == JsonValueKind.Object)
{
foreach (var item in jsonObject.EnumerateObject())
{
@ -144,6 +144,10 @@ namespace CryptoExchange.Net.Testing.Comparers
//}
}
}
else
{
//?
}
Debug.WriteLine($"Successfully validated {method}");
}
@ -366,8 +370,8 @@ namespace CryptoExchange.Net.Testing.Comparers
var stringValue = jsonValue.GetString();
if (objectValue is decimal dec)
{
if (decimal.Parse(stringValue!) != dec)
throw new Exception($"{method}: {property} not equal: {jsonValue.GetDecimal()} vs {dec}");
if (decimal.Parse(stringValue!, CultureInfo.InvariantCulture) != dec)
throw new Exception($"{method}: {property} not equal: {stringValue} vs {dec}");
}
else if (objectValue is DateTime time)
{
@ -402,7 +406,12 @@ namespace CryptoExchange.Net.Testing.Comparers
{
// TODO enum comparing
}
else if (value != Convert.ToInt64(objectValue))
else if(objectValue is decimal dec)
{
if (dec != value)
throw new Exception($"{method}: {property} not equal: {dec} vs {value}");
}
else if (value != Convert.ToInt64(objectValue, CultureInfo.InvariantCulture))
{
throw new Exception($"{method}: {property} not equal: {value} vs {Convert.ToInt64(objectValue)}");
}

View File

@ -120,7 +120,8 @@ namespace CryptoExchange.Net.Testing
{
// |x| values are used to replace parts or response messages
overrideKey = item.Value.ToString();
overrideValue = lastMessageJson.GetProperty(item.Name).GetString();
var prop = lastMessageJson.GetProperty(item.Name);
overrideValue = prop.ValueKind == JsonValueKind.String ? prop.GetString() : prop.GetInt64().ToString();
}
else if (item.Value.ToString() == "-999")
{
@ -128,10 +129,15 @@ namespace CryptoExchange.Net.Testing
overrideKey = item.Value.ToString();
overrideValue = lastMessageJson.GetProperty(item.Name).GetDecimal().ToString();
}
else if (lastMessageJson.GetProperty(item.Name).GetString() != item.Value.ToString() && ignoreProperties?.Contains(item.Name) != true)
else if (lastMessageJson.GetProperty(item.Name).ValueKind == JsonValueKind.String && lastMessageJson.GetProperty(item.Name).GetString() != item.Value.ToString() && ignoreProperties?.Contains(item.Name) != true)
{
throw new Exception($"{name} Expected {item.Name} to be {item.Value}, but was {lastMessageJson.GetProperty(item.Name).GetString()}");
}
else
{
// TODO check arrays and sub-objects
}
}
// TODO check arrays and sub-objects