1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-11 08:22:53 +00:00

Updated some test logic

This commit is contained in:
Jkorf
2026-06-01 16:05:50 +02:00
parent 3a9382ca0f
commit f0ece589f7
2 changed files with 19 additions and 9 deletions
@@ -395,9 +395,9 @@ namespace CryptoExchange.Net.Testing.Comparers
}
else if (objectValue is bool bl)
{
if (bl && (stringValue != "1" && stringValue != "true" && stringValue != "True"))
if (bl && (stringValue != "1" && stringValue != "true" && stringValue != "True" && stringValue != "yes" && stringValue != "YES"))
throw new Exception($"{method}: {property} not equal: {stringValue} vs {bl}");
if (!bl && (stringValue != "0" && stringValue != "-1" && stringValue != "false" && stringValue != "False"))
if (!bl && (stringValue != "0" && stringValue != "-1" && stringValue != "false" && stringValue != "False" && stringValue != "no" && stringValue != "NO"))
throw new Exception($"{method}: {property} not equal: {stringValue} vs {bl}");
}
else if (propertyType.IsEnum || Nullable.GetUnderlyingType(propertyType)?.IsEnum == true)
@@ -57,6 +57,7 @@ namespace CryptoExchange.Net.Testing
/// <param name="name">Method name for looking up json test values</param>
/// <param name="nestedJsonProperty">Use nested json property for compare</param>
/// <param name="ignoreProperties">Ignore certain properties</param>
/// <param name="ignoreParamValidation">Ignore certain parameter validation</param>
/// <param name="useSingleArrayItem">Use the first item of an json array response</param>
/// <param name="skipResponseValidation">Whether to skip the response model validation</param>
/// <returns></returns>
@@ -66,9 +67,10 @@ namespace CryptoExchange.Net.Testing
string name,
string? nestedJsonProperty = null,
List<string>? ignoreProperties = null,
List<string>? ignoreParamValidation = null,
bool useSingleArrayItem = false,
bool skipResponseValidation = false)
=> ValidateAsync<TResponse, TResponse>(methodInvoke, name, nestedJsonProperty, ignoreProperties, useSingleArrayItem, skipResponseValidation);
=> ValidateAsync<TResponse, TResponse>(methodInvoke, name, nestedJsonProperty, ignoreProperties, ignoreParamValidation, useSingleArrayItem, skipResponseValidation);
/// <summary>
/// Validate a request
@@ -79,6 +81,7 @@ namespace CryptoExchange.Net.Testing
/// <param name="name">Method name for looking up json test values</param>
/// <param name="nestedJsonProperty">Use nested json property for compare</param>
/// <param name="ignoreProperties">Ignore certain properties</param>
/// <param name="ignoreParamValidation">Ignore certain parameter validation</param>
/// <param name="useSingleArrayItem">Use the first item of an json array response</param>
/// <param name="skipResponseValidation">Whether to skip the response model validation</param>
/// <returns></returns>
@@ -88,6 +91,7 @@ namespace CryptoExchange.Net.Testing
string name,
string? nestedJsonProperty = null,
List<string>? ignoreProperties = null,
List<string>? ignoreParamValidation = null,
bool useSingleArrayItem = false,
bool skipResponseValidation = false) where TActualResponse : TResponse
{
@@ -156,7 +160,7 @@ namespace CryptoExchange.Net.Testing
? urlParametersString.Split('&').ToDictionary(x => x.Split('=')[0], x => (object)x.Split('=')[1])
: new());
CompareParameters(expectedUriParams, urlParameters);
CompareParameters(expectedUriParams, urlParameters, ignoreParamValidation);
}
if (expectedBodyParams != null)
@@ -173,7 +177,7 @@ namespace CryptoExchange.Net.Testing
bodyParameters = splitKvp.Select(x => x.Split('=')).ToDictionary(x => x[0], x => (object)x[1]);
}
CompareParameters(expectedBodyParams, bodyParameters);
CompareParameters(expectedBodyParams, bodyParameters, ignoreParamValidation);
}
if (!skipResponseValidation)
@@ -186,13 +190,16 @@ namespace CryptoExchange.Net.Testing
Trace.Listeners.Remove(listener);
}
private void CompareParameters(Dictionary<string, object> expectedUrlParameters, Dictionary<string, object> parameters)
private void CompareParameters(Dictionary<string, object> expectedUrlParameters, Dictionary<string, object> parameters, List<string>? ignoreParamValidation)
{
if (expectedUrlParameters.Count > parameters.Count)
throw new Exception($"Url parameters count not matched. Expected: {expectedUrlParameters.Count}, Actual: {parameters.Count}");
foreach (var kvp in expectedUrlParameters)
{
if (ignoreParamValidation != null && ignoreParamValidation.Contains(kvp.Key))
continue;
if (!parameters.TryGetValue(kvp.Key, out var value))
throw new Exception($"Url parameter {kvp.Key} not found in actual parameters");
@@ -206,11 +213,14 @@ namespace CryptoExchange.Net.Testing
/// </summary>
/// <param name="methodInvoke">Method invocation</param>
/// <param name="name">Method name for looking up json test values</param>
/// <param name="ignoreParamValidation">Ignore certain parameter validation</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public async Task ValidateAsync(
Func<TClient, Task<WebCallResult>> methodInvoke,
string name)
string name,
List<string>? ignoreParamValidation = null
)
{
var listener = new EnumValueTraceListener();
Trace.Listeners.Add(listener);
@@ -278,7 +288,7 @@ namespace CryptoExchange.Net.Testing
? urlParametersString.Split('&').ToDictionary(x => x.Split('=')[0], x => (object)x.Split('=')[1])
: new());
CompareParameters(expectedUriParams, urlParameters);
CompareParameters(expectedUriParams, urlParameters, ignoreParamValidation);
}
if (expectedBodyParams != null)
@@ -295,7 +305,7 @@ namespace CryptoExchange.Net.Testing
bodyParameters = splitKvp.Select(x => x.Split('=')).ToDictionary(x => x[0], x => (object)x[1]);
}
CompareParameters(expectedBodyParams, bodyParameters);
CompareParameters(expectedBodyParams, bodyParameters, ignoreParamValidation);
}
Trace.Listeners.Remove(listener);