1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-07 07:56:12 +00:00

Fixed System.Text.Json tests not correctly checking capitalization

This commit is contained in:
JKorf 2024-08-07 16:49:12 +02:00
parent 7fde8bf5da
commit 69b2e2045e

View File

@ -161,12 +161,16 @@ namespace CryptoExchange.Net.Testing.Comparers
// Property has a value
var property = resultProperties.SingleOrDefault(p => p.Name == prop.Name).p;
property ??= resultProperties.SingleOrDefault(p => p.p.Name == prop.Name).p;
property ??= resultProperties.SingleOrDefault(p => p.p.Name.Equals(prop.Name, StringComparison.InvariantCultureIgnoreCase)).p;
if (property is null)
// Property not found
throw new Exception($"{method}: Missing property `{prop.Name}` on `{obj.GetType().Name}`");
var getMethod = property.GetGetMethod();
if (getMethod is null)
// There is no getter, so probably just a set for an alternative json name
return;
var propertyValue = property.GetValue(obj);
CheckPropertyValue(method, prop.Value, propertyValue, property.PropertyType, property.Name, prop.Name, ignoreProperties);
}
@ -364,9 +368,10 @@ namespace CryptoExchange.Net.Testing.Comparers
}
else if (objectValue is bool bl)
{
if (bl && jsonValue.Value<string>() != "1")
var jsonStr = jsonValue.Value<string>();
if (bl && (jsonStr != "1" && jsonStr != "true" && jsonStr != "True"))
throw new Exception($"{method}: {property} not equal: {jsonValue.Value<string>()} vs {bl}");
if (!bl && jsonValue.Value<string>() != "0")
if (!bl && (jsonStr != "0" && jsonStr != "-1" && jsonStr != "false" && jsonStr != "False"))
throw new Exception($"{method}: {property} not equal: {jsonValue.Value<string>()} vs {bl}");
}
else if (propertyType.IsEnum || Nullable.GetUnderlyingType(propertyType)?.IsEnum == true)