Skip to content

Commit

Permalink
Feature/system.text.json (#7)
Browse files Browse the repository at this point in the history
CryptoExchange.Net V7.1.0
  • Loading branch information
JKorf authored Mar 16, 2024
1 parent 1807188 commit fdf8d5d
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 25 deletions.
8 changes: 4 additions & 4 deletions CoinGecko.Net.UnitTests/CoinGecko.Net.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CoinGecko.Net\CoinGecko.Net.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion CoinGecko.Net.UnitTests/InterfacesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CoinGecko.Net.Clients;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using System;
using System.Diagnostics;
using System.Linq;
Expand All @@ -24,7 +25,7 @@ public void CheckRestInterfaces()
foreach (var method in implementation.GetMethods().Where(m => m.ReturnType.IsAssignableTo(typeof(Task))))
{
var interfaceMethod = clientInterface.GetMethod(method.Name, method.GetParameters().Select(p => p.ParameterType).ToArray());
Assert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}");
ClassicAssert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}");
methods++;
}
Debug.WriteLine($"{clientInterface.Name} {methods} methods validated");
Expand Down
14 changes: 9 additions & 5 deletions CoinGecko.Net.UnitTests/JsonToObjectComparer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using CoinGecko.Net.UnitTests;
using CryptoExchange.Net.Converters;
using CryptoExchange.Net.Converters.JsonNet;
using CryptoExchange.Net.Objects;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -94,7 +96,7 @@ public async Task ProcessSubject<K>(
var result = (CallResult)await TestHelpers.InvokeAsync(method, getSubject(client), input.ToArray());

// asset
Assert.Null(result.Error, method.Name);
ClassicAssert.Null(result.Error, method.Name);

var resultProp = result.GetType().GetProperty("Data", BindingFlags.Public | BindingFlags.Instance);
if (resultProp == null)
Expand Down Expand Up @@ -245,10 +247,8 @@ private static void CheckObject(string method, JProperty prop, object obj, Dicti

// Property has a value
var property = resultProperties.SingleOrDefault(p => p.Item2?.PropertyName == prop.Name).p;
if (property is null)
property = resultProperties.SingleOrDefault(p => p.p.Name == prop.Name).p;
if (property is null)
property = resultProperties.SingleOrDefault(p => p.p.Name.ToUpperInvariant() == prop.Name.ToUpperInvariant()).p;
property ??= resultProperties.SingleOrDefault(p => p.p.Name == prop.Name).p;
property ??= resultProperties.SingleOrDefault(p => p.p.Name.ToUpperInvariant() == prop.Name.ToUpperInvariant()).p;

if (property is null)
{
Expand Down Expand Up @@ -363,7 +363,9 @@ private static void CheckPropertyValue(string method, JToken propValue, object p
{
if (info.GetCustomAttribute<JsonConverterAttribute>(true) == null
&& info.GetCustomAttribute<JsonPropertyAttribute>(true)?.ItemConverterType == null)
{
CheckValues(method, propertyName, (JValue)propValue, propertyValue);
}
}
}
}
Expand Down Expand Up @@ -408,7 +410,9 @@ private static void CheckValues(string method, string property, JValue jsonValue
// timestamp, hard to check..
}
else if (jsonValue.Value<string>().ToLowerInvariant() != objectValue.ToString().ToLowerInvariant())
{
throw new Exception($"{method}: {property} not equal: {jsonValue.Value<string>()} vs {objectValue.ToString()}");
}
}
else if (jsonValue.Type == JTokenType.Integer)
{
Expand Down
2 changes: 1 addition & 1 deletion CoinGecko.Net/Clients/CoinGeckoRestClient.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using CoinGecko.Net.Interfaces;
using CoinGecko.Net.Objects;
using CryptoExchange.Net;
using Microsoft.Extensions.Logging;
using System.Net.Http;
using System;
using CoinGecko.Net.Objects.Options;
using CryptoExchange.Net.Clients;

namespace CoinGecko.Net.Clients
{
Expand Down
1 change: 1 addition & 0 deletions CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CoinGecko.Net.Objects.Options;
using CryptoExchange.Net;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Clients;
using CryptoExchange.Net.Converters;
using CryptoExchange.Net.Objects;
using Microsoft.Extensions.Logging;
Expand Down
12 changes: 6 additions & 6 deletions CoinGecko.Net/CoinGecko.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<PackageId>CoinGecko.Net</PackageId>
<Authors>JKorf</Authors>
<PackageVersion>2.1.0</PackageVersion>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<PackageVersion>2.2.0</PackageVersion>
<AssemblyVersion>2.2.0</AssemblyVersion>
<FileVersion>2.2.0</FileVersion>
<Description>CoinGecko.Net is a client library for accessing the CoinGecko REST API. All data is mapped to readable models and enum values.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>CoinGecko;CoinGecko.Net;CoinGecko Client;CoinGecko API;CryptoCurrency</PackageTags>
Expand Down Expand Up @@ -44,14 +44,14 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="ConfigureAwaitChecker.Analyzer" Version="5.0.0">
<PackageReference Include="ConfigureAwaitChecker.Analyzer" Version="5.0.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.1.0" />
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions CoinGecko.Net/Objects/Models/CoinGeckoMarket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,32 @@ public class CoinGeckoMarket
/// 24 hour high price
/// </summary>
[JsonProperty("high_24h")]
public decimal High24h { get; set; }
public decimal? High24h { get; set; }
/// <summary>
/// 24 hour low price
/// </summary>
[JsonProperty("low_24h")]
public decimal Low24h { get; set; }
public decimal? Low24h { get; set; }
/// <summary>
/// 24 hour price change
/// </summary>
[JsonProperty("price_change_24h")]
public decimal PriceChange24h { get; set; }
public decimal? PriceChange24h { get; set; }
/// <summary>
/// 24 hour price change percentage
/// </summary>
[JsonProperty("price_change_percentage_24h")]
public decimal PriceChangePercentage24h { get; set; }
public double? PriceChangePercentage24h { get; set; }
/// <summary>
/// 24 hour market cap change
/// </summary>
[JsonProperty("market_cap_change_24h")]
public decimal MarketCapChange24h { get; set; }
public decimal? MarketCapChange24h { get; set; }
/// <summary>
/// 24 hour market cap change percentage
/// </summary>
[JsonProperty("market_cap_change_percentage_24h")]
public decimal MarketCapChangePercentage24h { get; set; }
public double? MarketCapChangePercentage24h { get; set; }
/// <summary>
/// Circulating supply
/// </summary>
Expand All @@ -104,7 +104,7 @@ public class CoinGeckoMarket
/// All time high change percentage
/// </summary>
[JsonProperty("ath_change_percentage")]
public decimal AllTimeHighChangePercentage { get; set; }
public double AllTimeHighChangePercentage { get; set; }
/// <summary>
/// All time high time
/// </summary>
Expand All @@ -120,7 +120,7 @@ public class CoinGeckoMarket
/// All time low change percentage
/// </summary>
[JsonProperty("atl_change_percentage")]
public decimal AllTimeLowChangePercentage { get; set; }
public double AllTimeLowChangePercentage { get; set; }
/// <summary>
/// All time low time
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions CoinGecko.Net/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using CryptoExchange.Net.Converters.JsonNet;
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ Make a one time donation in a crypto currency of your choice. If you prefer to d
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf).

## Release notes
* Version 2.2.0 - 16 Mar 2024
* Updated CryptoExchange.Net to 7.1.0, see https://github.com/JKorf/CryptoExchange.Net?tab=readme-ov-file#release-notes for release notes
* Updated unit test package dependencies and updated tests accordingly
* Fixed deserialization issues

* Version 2.1.0 - 25 Feb 2024
* Updated CryptoExchange.Net
* Fixed issue in DI registration causing http client to not be correctly injected
Expand Down

0 comments on commit fdf8d5d

Please sign in to comment.