mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-11 08:22:53 +00:00
Updated RestIntegrationTest to output missing properties in a list so the running test can output them as warning instead of error
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using CryptoExchange.Net.Converters;
|
||||
using CryptoExchange.Net.Converters.SystemTextJson;
|
||||
using CryptoExchange.Net.Testing.Exceptions;
|
||||
|
||||
#pragma warning disable IL2026
|
||||
#pragma warning disable IL2070
|
||||
@@ -191,7 +192,7 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
|
||||
if (property is null)
|
||||
// Property not found
|
||||
throw new Exception($"{method}: Missing property `{prop.Name}` on `{obj.GetType().Name}`");
|
||||
throw new MissingPropertyException(method, obj.GetType().Name, prop.Name, prop.Value.ValueKind == JsonValueKind.Null ? "[null]" : prop.Value.ToString());
|
||||
|
||||
var getMethod = property.GetGetMethod();
|
||||
if (getMethod is null)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.Testing.Exceptions
|
||||
{
|
||||
internal class MissingPropertyException : Exception
|
||||
{
|
||||
public MissingPropertyException(string method, string objName, string propName, string value)
|
||||
: base($"{method}: Missing property `{propName}` on `{objName}`, value: {value.Substring(0, Math.Min(50, value.Length))}")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.Testing.Comparers;
|
||||
using CryptoExchange.Net.Testing.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -55,6 +56,26 @@ namespace CryptoExchange.Net.Testing
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute a REST endpoint call and check for any errors or warnings. Also checks for missing fields in the response mapping
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="warningExceptionsHolder">List for outputting warnings</param>
|
||||
/// <param name="expression">The call expression</param>
|
||||
/// <param name="authRequest">Whether this is an authenticated request</param>
|
||||
/// <param name="compareNestedProperty">Nested property to use for comparing when checking for missing fields</param>
|
||||
/// <param name="ignoreProperties">Properties to ignore when checking for missing fields</param>
|
||||
/// <param name="useSingleArrayItem">Whether to use the single array item as compare when checking for missing fields</param>
|
||||
/// <returns></returns>
|
||||
public Task RunAndCheckResult<T>(
|
||||
List<Exception> warningExceptionsHolder,
|
||||
Expression<Func<TClient, Task<HttpResult<T>>>> expression,
|
||||
bool authRequest,
|
||||
string? compareNestedProperty = null,
|
||||
List<string>? ignoreProperties = null,
|
||||
bool? useSingleArrayItem = null)
|
||||
=> RunAndCheckResult(expression, authRequest, true, compareNestedProperty, ignoreProperties, useSingleArrayItem, warningExceptionsHolder);
|
||||
|
||||
/// <summary>
|
||||
/// Execute a REST endpoint call and check for any errors or warnings.
|
||||
/// </summary>
|
||||
@@ -65,13 +86,15 @@ namespace CryptoExchange.Net.Testing
|
||||
/// <param name="compareNestedProperty">Nested property to use for comparing when checking for missing fields</param>
|
||||
/// <param name="ignoreProperties">Properties to ignore when checking for missing fields</param>
|
||||
/// <param name="useSingleArrayItem">Whether to use the single array item as compare when checking for missing fields</param>
|
||||
/// <param name="warningExceptionsHolder">List for outputting warnings</param>
|
||||
public async Task RunAndCheckResult<T>(
|
||||
Expression<Func<TClient, Task<HttpResult<T>>>> expression,
|
||||
bool authRequest,
|
||||
bool checkMissingFields = false,
|
||||
string? compareNestedProperty = null,
|
||||
List<string>? ignoreProperties = null,
|
||||
bool? useSingleArrayItem = null)
|
||||
bool? useSingleArrayItem = null,
|
||||
List<Exception>? warningExceptionsHolder = null)
|
||||
{
|
||||
if (!ShouldRun())
|
||||
return;
|
||||
@@ -112,9 +135,14 @@ namespace CryptoExchange.Net.Testing
|
||||
if (originalData == null)
|
||||
throw new Exception($"Original data needs to be enabled in the client options to check for missing fields");
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
SystemTextJsonComparer.CompareData(expressionBody.Method.Name, data, originalData, compareNestedProperty, ignoreProperties, useSingleArrayItem ?? false);
|
||||
}
|
||||
catch (MissingPropertyException mpe)
|
||||
{
|
||||
warningExceptionsHolder?.Add(mpe);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Compare failed: {ex.Message}; original data: {originalData}", ex);
|
||||
|
||||
Reference in New Issue
Block a user