mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Fix tests
This commit is contained in:
@@ -40,7 +40,7 @@ namespace BTCPayServer.Client
|
|||||||
protected async Task<T> HandleResponse<T>(HttpResponseMessage message)
|
protected async Task<T> HandleResponse<T>(HttpResponseMessage message)
|
||||||
{
|
{
|
||||||
HandleResponse(message);
|
HandleResponse(message);
|
||||||
return JsonConvert.DeserializeObject<T>(await message.Content.ReadAsStringAsync(), Serializer.GlobalSerializerSettings);
|
return JsonConvert.DeserializeObject<T>(await message.Content.ReadAsStringAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual HttpRequestMessage CreateHttpRequest(string path,
|
protected virtual HttpRequestMessage CreateHttpRequest(string path,
|
||||||
@@ -68,7 +68,7 @@ namespace BTCPayServer.Client
|
|||||||
var request = CreateHttpRequest(path, queryPayload, method);
|
var request = CreateHttpRequest(path, queryPayload, method);
|
||||||
if (typeof(T).IsPrimitive || !EqualityComparer<T>.Default.Equals(bodyPayload, default(T)))
|
if (typeof(T).IsPrimitive || !EqualityComparer<T>.Default.Equals(bodyPayload, default(T)))
|
||||||
{
|
{
|
||||||
request.Content = new StringContent(JsonConvert.SerializeObject(bodyPayload, Serializer.GlobalSerializerSettings), Encoding.UTF8, "application/json");
|
request.Content = new StringContent(JsonConvert.SerializeObject(bodyPayload), Encoding.UTF8, "application/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
using BTCPayServer.Client.JsonConverters;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BTCPayServer.Client.Models
|
namespace BTCPayServer.Client.Models
|
||||||
{
|
{
|
||||||
public class ApiKeyData
|
public class ApiKeyData
|
||||||
@@ -5,6 +8,7 @@ namespace BTCPayServer.Client.Models
|
|||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
public string Label { get; set; }
|
public string Label { get; set; }
|
||||||
public string UserId { get; set; }
|
public string UserId { get; set; }
|
||||||
|
[JsonProperty(ItemConverterType = typeof(PermissionJsonConverter))]
|
||||||
public Permission[] Permissions { get; set; }
|
public Permission[] Permissions { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using BTCPayServer.Client.JsonConverters;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
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)
|
|
||||||
throw new ArgumentNullException(nameof(settings));
|
|
||||||
settings.Converters.Add(new PermissionJsonConverter());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -311,7 +311,7 @@ namespace BTCPayServer.Tests
|
|||||||
return (T)Convert.ChangeType(rawJson, typeof(T));
|
return (T)Convert.ChangeType(rawJson, typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonConvert.DeserializeObject<T>(rawJson, BTCPayServer.Client.Serializer.GlobalSerializerSettings);
|
return JsonConvert.DeserializeObject<T>(rawJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ namespace BTCPayServer.Tests
|
|||||||
user.GrantAccess();
|
user.GrantAccess();
|
||||||
await user.MakeAdmin();
|
await user.MakeAdmin();
|
||||||
var clientProfile = await user.CreateClient(Policies.CanModifyProfile);
|
var clientProfile = await user.CreateClient(Policies.CanModifyProfile);
|
||||||
var clientServer = await user.CreateClient(Policies.CanModifyServerSettings, Policies.CanViewProfile);
|
var clientServer = await user.CreateClient(Policies.CanCreateUser, Policies.CanViewProfile);
|
||||||
var clientInsufficient = await user.CreateClient(Policies.CanModifyStoreSettings);
|
var clientInsufficient = await user.CreateClient(Policies.CanModifyStoreSettings);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user