mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-31 11:54:24 +01:00
Fix tests
This commit is contained in:
@@ -12,19 +12,12 @@ namespace BTCPayServer.Client
|
||||
{
|
||||
public partial class BTCPayServerClient
|
||||
{
|
||||
static BTCPayServerClient()
|
||||
{
|
||||
_GlobalSerializer = new JsonSerializerSettings();
|
||||
Serializer.RegisterConverters(_GlobalSerializer);
|
||||
}
|
||||
private readonly string _apiKey;
|
||||
private readonly Uri _btcpayHost;
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public string APIKey => _apiKey;
|
||||
|
||||
private static readonly JsonSerializerSettings _GlobalSerializer = new JsonSerializerSettings();
|
||||
|
||||
public BTCPayServerClient(Uri btcpayHost, HttpClient httpClient = null)
|
||||
{
|
||||
if (btcpayHost == null)
|
||||
@@ -47,7 +40,7 @@ namespace BTCPayServer.Client
|
||||
protected async Task<T> HandleResponse<T>(HttpResponseMessage message)
|
||||
{
|
||||
HandleResponse(message);
|
||||
return JsonConvert.DeserializeObject<T>(await message.Content.ReadAsStringAsync(), _GlobalSerializer);
|
||||
return JsonConvert.DeserializeObject<T>(await message.Content.ReadAsStringAsync(), Serializer.GlobalSerializerSettings);
|
||||
}
|
||||
|
||||
protected virtual HttpRequestMessage CreateHttpRequest(string path,
|
||||
@@ -75,7 +68,7 @@ namespace BTCPayServer.Client
|
||||
var request = CreateHttpRequest(path, queryPayload, method);
|
||||
if (typeof(T).IsPrimitive || !EqualityComparer<T>.Default.Equals(bodyPayload, default(T)))
|
||||
{
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(bodyPayload, _GlobalSerializer), Encoding.UTF8, "application/json");
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(bodyPayload, Serializer.GlobalSerializerSettings), Encoding.UTF8, "application/json");
|
||||
}
|
||||
|
||||
return request;
|
||||
|
||||
@@ -8,6 +8,21 @@ namespace BTCPayServer.Client
|
||||
{
|
||||
public class Serializer
|
||||
{
|
||||
|
||||
private static JsonSerializerSettings _GlobalSerializerSettings;
|
||||
public static JsonSerializerSettings GlobalSerializerSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_GlobalSerializerSettings is null)
|
||||
{
|
||||
var serializer = new JsonSerializerSettings();
|
||||
RegisterConverters(serializer);
|
||||
_GlobalSerializerSettings = serializer;
|
||||
}
|
||||
return _GlobalSerializerSettings;
|
||||
}
|
||||
}
|
||||
public static void RegisterConverters(JsonSerializerSettings settings)
|
||||
{
|
||||
if (settings == null)
|
||||
|
||||
@@ -311,7 +311,7 @@ namespace BTCPayServer.Tests
|
||||
return (T)Convert.ChangeType(rawJson, typeof(T));
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<T>(rawJson);
|
||||
return JsonConvert.DeserializeObject<T>(rawJson, BTCPayServer.Client.Serializer.GlobalSerializerSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Threading.Tasks;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Controllers;
|
||||
using BTCPayServer.Controllers.RestApi.Users;
|
||||
using BTCPayServer.Services;
|
||||
using BTCPayServer.Tests.Logging;
|
||||
using Microsoft.AspNet.SignalR.Client;
|
||||
|
||||
Reference in New Issue
Block a user