Refactor project files for improved readability and structure
CI / Backend (build + test) (push) Successful in 1m18s
CI / Frontend (lint + typecheck + build) (push) Successful in 31s

- Cleaned up whitespace in Directory.Build.props and Directory.Packages.props for consistency.
- Reformatted project file references in PnvPanel.Api.csproj for better clarity.
- Enhanced code readability in various endpoint files by adjusting line breaks and indentation.
- Standardized method signatures and improved formatting in ResultExtensions and multiple endpoint classes for better maintainability.
This commit is contained in:
Leonid Pershin
2026-07-14 07:24:13 +03:00
parent 9d5424bb9c
commit df137ca5a7
285 changed files with 6911 additions and 2063 deletions
@@ -8,7 +8,11 @@ namespace PnvPanel.IntegrationTests.Activation;
[Collection(IntegrationTestCollection.Name)]
public class ActivationFlowTests(PnvPanelWebApplicationFactory factory)
{
private sealed record ActivationRequestResponse(Guid Id, string? Comment, DateTimeOffset CreatedAt);
private sealed record ActivationRequestResponse(
Guid Id,
string? Comment,
DateTimeOffset CreatedAt
);
[Fact]
public async Task RequestThenAdminApprove_ActivatesUser()
@@ -18,7 +22,10 @@ public class ActivationFlowTests(PnvPanelWebApplicationFactory factory)
var (userId, userToken) = await RegisterAndLoginAsync(userClient, userName, "P@ssw0rd123");
userClient.UseBearerToken(userToken);
var requestResponse = await userClient.PostJsonAsync("/api/activation/request", new { comment = "Please activate me" });
var requestResponse = await userClient.PostJsonAsync(
"/api/activation/request",
new { comment = "Please activate me" }
);
Assert.Equal(HttpStatusCode.OK, requestResponse.StatusCode);
var request = await requestResponse.ReadAsAsync<ActivationRequestResponse>();
Assert.NotNull(request);
@@ -27,7 +34,10 @@ public class ActivationFlowTests(PnvPanelWebApplicationFactory factory)
var adminToken = await LoginAsAdminAsync(adminClient);
adminClient.UseBearerToken(adminToken);
var approveResponse = await adminClient.PostAsync($"/api/admin/activation-requests/{request!.Id}/approve", content: null);
var approveResponse = await adminClient.PostAsync(
$"/api/admin/activation-requests/{request!.Id}/approve",
content: null
);
Assert.Equal(HttpStatusCode.NoContent, approveResponse.StatusCode);
var meResponse = await userClient.GetAsync("/api/auth/me");
@@ -44,14 +54,20 @@ public class ActivationFlowTests(PnvPanelWebApplicationFactory factory)
var (_, userToken) = await RegisterAndLoginAsync(userClient, userName, "P@ssw0rd123");
userClient.UseBearerToken(userToken);
var requestResponse = await userClient.PostJsonAsync("/api/activation/request", new { comment = (string?)null });
var requestResponse = await userClient.PostJsonAsync(
"/api/activation/request",
new { comment = (string?)null }
);
var request = await requestResponse.ReadAsAsync<ActivationRequestResponse>();
using var adminClient = factory.CreateClient();
var adminToken = await LoginAsAdminAsync(adminClient);
adminClient.UseBearerToken(adminToken);
var rejectResponse = await adminClient.PostJsonAsync($"/api/admin/activation-requests/{request!.Id}/reject", new { reason = "not enough info" });
var rejectResponse = await adminClient.PostJsonAsync(
$"/api/admin/activation-requests/{request!.Id}/reject",
new { reason = "not enough info" }
);
Assert.Equal(HttpStatusCode.NoContent, rejectResponse.StatusCode);
var meResponse = await userClient.GetAsync("/api/auth/me");
@@ -67,10 +83,16 @@ public class ActivationFlowTests(PnvPanelWebApplicationFactory factory)
var (_, userToken) = await RegisterAndLoginAsync(userClient, userName, "P@ssw0rd123");
userClient.UseBearerToken(userToken);
var first = await userClient.PostJsonAsync("/api/activation/request", new { comment = (string?)null });
var first = await userClient.PostJsonAsync(
"/api/activation/request",
new { comment = (string?)null }
);
Assert.Equal(HttpStatusCode.OK, first.StatusCode);
var second = await userClient.PostJsonAsync("/api/activation/request", new { comment = (string?)null });
var second = await userClient.PostJsonAsync(
"/api/activation/request",
new { comment = (string?)null }
);
Assert.Equal(HttpStatusCode.Conflict, second.StatusCode);
}
}
@@ -8,11 +8,28 @@ namespace PnvPanel.IntegrationTests.Admin;
[Collection(IntegrationTestCollection.Name)]
public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
{
private sealed record NodeResponse(Guid Id, string Name, string BaseAddress, string Username, string? Location, string Status, bool IsEnabled);
private sealed record NodeResponse(
Guid Id,
string Name,
string BaseAddress,
string Username,
string? Location,
string Status,
bool IsEnabled
);
private sealed record InboundResponse(
Guid Id, Guid NodeId, string RemoteInboundId, string Protocol, string Remark, int Port,
bool IsPublished, string? DisplayName, int? MaxClients, IReadOnlyList<Guid> AllowedRoleIds);
Guid Id,
Guid NodeId,
string RemoteInboundId,
string Protocol,
string Remark,
int Port,
bool IsPublished,
string? DisplayName,
int? MaxClients,
IReadOnlyList<Guid> AllowedRoleIds
);
private sealed record SyncNodeResponse(int InboundsSynced, string Status);
@@ -23,14 +40,17 @@ public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
var adminToken = await LoginAsAdminAsync(adminClient);
adminClient.UseBearerToken(adminToken);
var registerResponse = await adminClient.PostJsonAsync("/api/admin/nodes", new
{
name = $"Node-{Guid.NewGuid():N}"[..20],
baseAddress = "https://node.example.com:2053",
username = "admin",
password = "node-panel-password",
location = "Germany",
});
var registerResponse = await adminClient.PostJsonAsync(
"/api/admin/nodes",
new
{
name = $"Node-{Guid.NewGuid():N}"[..20],
baseAddress = "https://node.example.com:2053",
username = "admin",
password = "node-panel-password",
location = "Germany",
}
);
Assert.Equal(HttpStatusCode.OK, registerResponse.StatusCode);
var node = await registerResponse.ReadAsAsync<NodeResponse>();
Assert.NotNull(node);
@@ -40,24 +60,32 @@ public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
var nodes = await listNodesResponse.ReadAsAsync<List<NodeResponse>>();
Assert.Contains(nodes!, n => n.Id == node!.Id);
var syncResponse = await adminClient.PostAsync($"/api/admin/nodes/{node!.Id}/sync", content: null);
var syncResponse = await adminClient.PostAsync(
$"/api/admin/nodes/{node!.Id}/sync",
content: null
);
Assert.Equal(HttpStatusCode.OK, syncResponse.StatusCode);
var sync = await syncResponse.ReadAsAsync<SyncNodeResponse>();
Assert.Equal(1, sync!.InboundsSynced);
var listInboundsResponse = await adminClient.GetAsync($"/api/admin/inbounds?nodeId={node.Id}");
var listInboundsResponse = await adminClient.GetAsync(
$"/api/admin/inbounds?nodeId={node.Id}"
);
Assert.Equal(HttpStatusCode.OK, listInboundsResponse.StatusCode);
var inbounds = await listInboundsResponse.ReadAsAsync<List<InboundResponse>>();
var inbound = Assert.Single(inbounds!);
Assert.False(inbound.IsPublished);
var publishResponse = await adminClient.SendPutJsonAsync($"/api/admin/inbounds/{inbound.Id}/publish", new
{
isPublished = true,
displayName = "Germany (VLESS)",
allowedRoleIds = Array.Empty<Guid>(),
maxClients = (int?)null,
});
var publishResponse = await adminClient.SendPutJsonAsync(
$"/api/admin/inbounds/{inbound.Id}/publish",
new
{
isPublished = true,
displayName = "Germany (VLESS)",
allowedRoleIds = Array.Empty<Guid>(),
maxClients = (int?)null,
}
);
Assert.Equal(HttpStatusCode.OK, publishResponse.StatusCode);
var published = await publishResponse.ReadAsAsync<InboundResponse>();
Assert.True(published!.IsPublished);
@@ -72,10 +100,17 @@ public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
var (_, userToken) = await RegisterAndLoginAsync(userClient, userName, "P@ssw0rd123");
userClient.UseBearerToken(userToken);
var response = await userClient.PostJsonAsync("/api/admin/nodes", new
{
name = "Node", baseAddress = "https://node.example.com", username = "admin", password = "pw", location = (string?)null,
});
var response = await userClient.PostJsonAsync(
"/api/admin/nodes",
new
{
name = "Node",
baseAddress = "https://node.example.com",
username = "admin",
password = "pw",
location = (string?)null,
}
);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
}
@@ -10,9 +10,19 @@ public class AuthFlowTests(PnvPanelWebApplicationFactory factory)
{
private sealed record RegisterResponse(Guid Id, string UserName);
private sealed record CurrentUserResponse(Guid Id, string UserName, string Role, bool IsActivated, bool TelegramLinked);
private sealed record CurrentUserResponse(
Guid Id,
string UserName,
string Role,
bool IsActivated,
bool TelegramLinked
);
private sealed record LoginResponse(string AccessToken, DateTimeOffset ExpiresAt, CurrentUserResponse User);
private sealed record LoginResponse(
string AccessToken,
DateTimeOffset ExpiresAt,
CurrentUserResponse User
);
[Fact]
public async Task RegisterLoginMeRefreshLogout_FullFlow_Succeeds()
@@ -21,13 +31,19 @@ public class AuthFlowTests(PnvPanelWebApplicationFactory factory)
var userName = $"alice_{Guid.NewGuid():N}"[..20];
const string password = "P@ssw0rd123";
var registerResponse = await client.PostJsonAsync("/api/auth/register", new { userName, password });
var registerResponse = await client.PostJsonAsync(
"/api/auth/register",
new { userName, password }
);
Assert.Equal(HttpStatusCode.OK, registerResponse.StatusCode);
var registered = await registerResponse.ReadAsAsync<RegisterResponse>();
Assert.NotNull(registered);
Assert.Equal(userName, registered!.UserName);
var loginResponse = await client.PostJsonAsync("/api/auth/login", new { userName, password });
var loginResponse = await client.PostJsonAsync(
"/api/auth/login",
new { userName, password }
);
Assert.Equal(HttpStatusCode.OK, loginResponse.StatusCode);
var login = await loginResponse.ReadAsAsync<LoginResponse>();
Assert.NotNull(login);
@@ -61,9 +77,15 @@ public class AuthFlowTests(PnvPanelWebApplicationFactory factory)
using var client = factory.CreateClient();
var userName = $"bob_{Guid.NewGuid():N}"[..20];
await client.PostJsonAsync("/api/auth/register", new { userName, password = "CorrectPassword123" });
await client.PostJsonAsync(
"/api/auth/register",
new { userName, password = "CorrectPassword123" }
);
var loginResponse = await client.PostJsonAsync("/api/auth/login", new { userName, password = "WrongPassword123" });
var loginResponse = await client.PostJsonAsync(
"/api/auth/login",
new { userName, password = "WrongPassword123" }
);
Assert.Equal(HttpStatusCode.Unauthorized, loginResponse.StatusCode);
}
@@ -74,10 +96,16 @@ public class AuthFlowTests(PnvPanelWebApplicationFactory factory)
using var client = factory.CreateClient();
var userName = $"carol_{Guid.NewGuid():N}"[..20];
var first = await client.PostJsonAsync("/api/auth/register", new { userName, password = "P@ssw0rd123" });
var first = await client.PostJsonAsync(
"/api/auth/register",
new { userName, password = "P@ssw0rd123" }
);
Assert.Equal(HttpStatusCode.OK, first.StatusCode);
var second = await client.PostJsonAsync("/api/auth/register", new { userName, password = "AnotherPass123!" });
var second = await client.PostJsonAsync(
"/api/auth/register",
new { userName, password = "AnotherPass123!" }
);
Assert.Equal(HttpStatusCode.Conflict, second.StatusCode);
}
@@ -17,9 +17,21 @@ public class ConfigQuotaTests(PnvPanelWebApplicationFactory factory)
private sealed record SyncNodeResponse(int InboundsSynced, string Status);
private sealed record InboundResponse(Guid Id, Guid NodeId, string RemoteInboundId, string Protocol, string Remark, int Port, bool IsPublished);
private sealed record InboundResponse(
Guid Id,
Guid NodeId,
string RemoteInboundId,
string Protocol,
string Remark,
int Port,
bool IsPublished
);
private sealed record ActivationRequestResponse(Guid Id, string? Comment, DateTimeOffset CreatedAt);
private sealed record ActivationRequestResponse(
Guid Id,
string? Comment,
DateTimeOffset CreatedAt
);
private sealed record MyConfigsResponse(List<object> Configs, int MaxConfigs);
@@ -41,33 +53,44 @@ public class ConfigQuotaTests(PnvPanelWebApplicationFactory factory)
var userRole = roles!.Single(r => r.Name == "user");
var updateRoleResponse = await adminClient.SendPutJsonAsync(
$"/api/admin/roles/{userRole.Id}", new { maxConfigs = Quota, maxIpLimit = -1 });
$"/api/admin/roles/{userRole.Id}",
new { maxConfigs = Quota, maxIpLimit = -1 }
);
Assert.Equal(HttpStatusCode.OK, updateRoleResponse.StatusCode);
var registerNodeResponse = await adminClient.PostJsonAsync("/api/admin/nodes", new
{
name = $"QuotaNode-{Guid.NewGuid():N}"[..24],
baseAddress = "https://quota-node.example.com",
username = "admin",
password = "node-panel-password",
location = (string?)null,
});
var registerNodeResponse = await adminClient.PostJsonAsync(
"/api/admin/nodes",
new
{
name = $"QuotaNode-{Guid.NewGuid():N}"[..24],
baseAddress = "https://quota-node.example.com",
username = "admin",
password = "node-panel-password",
location = (string?)null,
}
);
var node = await registerNodeResponse.ReadAsAsync<NodeResponse>();
var syncResponse = await adminClient.PostAsync($"/api/admin/nodes/{node!.Id}/sync", content: null);
var syncResponse = await adminClient.PostAsync(
$"/api/admin/nodes/{node!.Id}/sync",
content: null
);
var sync = await syncResponse.ReadAsAsync<SyncNodeResponse>();
Assert.Equal(1, sync!.InboundsSynced);
var inboundsResponse = await adminClient.GetAsync($"/api/admin/inbounds?nodeId={node.Id}");
var inbound = (await inboundsResponse.ReadAsAsync<List<InboundResponse>>())!.Single();
var publishResponse = await adminClient.SendPutJsonAsync($"/api/admin/inbounds/{inbound.Id}/publish", new
{
isPublished = true,
displayName = "Quota inbound",
allowedRoleIds = new[] { userRole.Id },
maxClients = (int?)null,
});
var publishResponse = await adminClient.SendPutJsonAsync(
$"/api/admin/inbounds/{inbound.Id}/publish",
new
{
isPublished = true,
displayName = "Quota inbound",
allowedRoleIds = new[] { userRole.Id },
maxClients = (int?)null,
}
);
Assert.Equal(HttpStatusCode.OK, publishResponse.StatusCode);
using var userClient = factory.CreateClient();
@@ -75,21 +98,29 @@ public class ConfigQuotaTests(PnvPanelWebApplicationFactory factory)
var (_, userToken) = await RegisterAndLoginAsync(userClient, userName, "P@ssw0rd123");
userClient.UseBearerToken(userToken);
var activationRequestResponse = await userClient.PostJsonAsync("/api/activation/request", new { comment = (string?)null });
var activationRequest = await activationRequestResponse.ReadAsAsync<ActivationRequestResponse>();
var approveResponse = await adminClient.PostAsync($"/api/admin/activation-requests/{activationRequest!.Id}/approve", content: null);
var activationRequestResponse = await userClient.PostJsonAsync(
"/api/activation/request",
new { comment = (string?)null }
);
var activationRequest =
await activationRequestResponse.ReadAsAsync<ActivationRequestResponse>();
var approveResponse = await adminClient.PostAsync(
$"/api/admin/activation-requests/{activationRequest!.Id}/approve",
content: null
);
Assert.Equal(HttpStatusCode.NoContent, approveResponse.StatusCode);
var tasks = Enumerable.Range(0, ConcurrentAttempts).Select(async i =>
{
using var attemptClient = factory.CreateClient();
attemptClient.UseBearerToken(userToken);
return await attemptClient.PostJsonAsync("/api/configs", new
var tasks = Enumerable
.Range(0, ConcurrentAttempts)
.Select(async i =>
{
inboundId = inbound.Id,
label = $"device-{i}",
using var attemptClient = factory.CreateClient();
attemptClient.UseBearerToken(userToken);
return await attemptClient.PostJsonAsync(
"/api/configs",
new { inboundId = inbound.Id, label = $"device-{i}" }
);
});
});
var responses = await Task.WhenAll(tasks);
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
@@ -24,5 +23,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\PnvPanel.Api\PnvPanel.Api.csproj" />
</ItemGroup>
</Project>
@@ -4,22 +4,46 @@ namespace PnvPanel.IntegrationTests.TestSupport;
public static class AuthTestHelper
{
public sealed record CurrentUserResponse(Guid Id, string UserName, string Role, bool IsActivated, bool TelegramLinked);
public sealed record CurrentUserResponse(
Guid Id,
string UserName,
string Role,
bool IsActivated,
bool TelegramLinked
);
public sealed record LoginResponse(string AccessToken, DateTimeOffset ExpiresAt, CurrentUserResponse User);
public sealed record LoginResponse(
string AccessToken,
DateTimeOffset ExpiresAt,
CurrentUserResponse User
);
public static async Task<(Guid Id, string AccessToken)> RegisterAndLoginAsync(HttpClient client, string userName, string password)
public static async Task<(Guid Id, string AccessToken)> RegisterAndLoginAsync(
HttpClient client,
string userName,
string password
)
{
var registerResponse = await client.PostJsonAsync("/api/auth/register", new { userName, password });
var registerResponse = await client.PostJsonAsync(
"/api/auth/register",
new { userName, password }
);
registerResponse.EnsureSuccessStatusCode();
var (id, accessToken) = await LoginAsync(client, userName, password);
return (id, accessToken);
}
public static async Task<(Guid Id, string AccessToken)> LoginAsync(HttpClient client, string userName, string password)
public static async Task<(Guid Id, string AccessToken)> LoginAsync(
HttpClient client,
string userName,
string password
)
{
var loginResponse = await client.PostJsonAsync("/api/auth/login", new { userName, password });
var loginResponse = await client.PostJsonAsync(
"/api/auth/login",
new { userName, password }
);
loginResponse.EnsureSuccessStatusCode();
var login = await loginResponse.ReadAsAsync<LoginResponse>();
return (login!.User.Id, login.AccessToken);
@@ -27,7 +51,11 @@ public static class AuthTestHelper
public static async Task<string> LoginAsAdminAsync(HttpClient client)
{
var (_, accessToken) = await LoginAsync(client, PnvPanelWebApplicationFactory.AdminUserName, PnvPanelWebApplicationFactory.AdminPassword);
var (_, accessToken) = await LoginAsync(
client,
PnvPanelWebApplicationFactory.AdminUserName,
PnvPanelWebApplicationFactory.AdminPassword
);
return accessToken;
}
}
@@ -13,10 +13,13 @@ public sealed class FakeXuiPanelGateway : IXuiPanelGateway
{
public Result ValidateBaseAddress(Uri baseAddress) => Result.Success();
public Task<NodeProbeResult> ProbeAsync(Node node, CancellationToken cancellationToken)
=> Task.FromResult(new NodeProbeResult(true, null));
public Task<NodeProbeResult> ProbeAsync(Node node, CancellationToken cancellationToken) =>
Task.FromResult(new NodeProbeResult(true, null));
public Task<Result<IReadOnlyList<RemoteInboundInfo>>> ListInboundsAsync(Node node, CancellationToken cancellationToken)
public Task<Result<IReadOnlyList<RemoteInboundInfo>>> ListInboundsAsync(
Node node,
CancellationToken cancellationToken
)
{
IReadOnlyList<RemoteInboundInfo> inbounds =
[
@@ -26,32 +29,53 @@ public sealed class FakeXuiPanelGateway : IXuiPanelGateway
return Task.FromResult(Result.Success(inbounds));
}
public void InvalidateClient(Guid nodeId)
{
}
public void InvalidateClient(Guid nodeId) { }
public Task<Result<string>> AddClientAsync(
Node node, string inboundRemoteId, VpnProtocol protocol, string clientEmail, string clientName, int limitIp,
CancellationToken cancellationToken)
=> Task.FromResult(Result.Success(Guid.NewGuid().ToString()));
Node node,
string inboundRemoteId,
VpnProtocol protocol,
string clientEmail,
string clientName,
int limitIp,
CancellationToken cancellationToken
) => Task.FromResult(Result.Success(Guid.NewGuid().ToString()));
public Task<Result> RemoveClientAsync(
Node node, string inboundRemoteId, string clientExternalId, VpnProtocol protocol, CancellationToken cancellationToken)
=> Task.FromResult(Result.Success());
Node node,
string inboundRemoteId,
string clientExternalId,
VpnProtocol protocol,
CancellationToken cancellationToken
) => Task.FromResult(Result.Success());
public Task<Result> UpdateClientAsync(
Node node, string inboundRemoteId, string clientExternalId, VpnProtocol protocol,
string name, bool enable, CancellationToken cancellationToken)
=> Task.FromResult(Result.Success());
Node node,
string inboundRemoteId,
string clientExternalId,
VpnProtocol protocol,
string name,
bool enable,
CancellationToken cancellationToken
) => Task.FromResult(Result.Success());
public Task<Result<string>> BuildConnectionStringAsync(
Node node, Inbound inbound, string clientExternalId, string clientName, string publicHost, CancellationToken cancellationToken)
=> Task.FromResult(Result.Success("vless://fake-connection-string"));
Node node,
Inbound inbound,
string clientExternalId,
string clientName,
string publicHost,
CancellationToken cancellationToken
) => Task.FromResult(Result.Success("vless://fake-connection-string"));
public Task<Result<IReadOnlyDictionary<string, ClientTrafficInfo>>> GetClientTrafficAsync(
Node node, string inboundRemoteId, CancellationToken cancellationToken)
Node node,
string inboundRemoteId,
CancellationToken cancellationToken
)
{
IReadOnlyDictionary<string, ClientTrafficInfo> traffic = new Dictionary<string, ClientTrafficInfo>();
IReadOnlyDictionary<string, ClientTrafficInfo> traffic =
new Dictionary<string, ClientTrafficInfo>();
return Task.FromResult(Result.Success(traffic));
}
}
@@ -8,15 +8,24 @@ public static class HttpClientJsonExtensions
{
public static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
public static void UseBearerToken(this HttpClient client, string accessToken)
=> client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
public static void UseBearerToken(this HttpClient client, string accessToken) =>
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Bearer",
accessToken
);
public static async Task<T?> ReadAsAsync<T>(this HttpResponseMessage response)
=> await response.Content.ReadFromJsonAsync<T>(JsonOptions);
public static async Task<T?> ReadAsAsync<T>(this HttpResponseMessage response) =>
await response.Content.ReadFromJsonAsync<T>(JsonOptions);
public static Task<HttpResponseMessage> PostJsonAsync(this HttpClient client, string url, object body)
=> client.PostAsJsonAsync(url, body, JsonOptions);
public static Task<HttpResponseMessage> PostJsonAsync(
this HttpClient client,
string url,
object body
) => client.PostAsJsonAsync(url, body, JsonOptions);
public static Task<HttpResponseMessage> SendPutJsonAsync(this HttpClient client, string url, object body)
=> client.PutAsJsonAsync(url, body, JsonOptions);
public static Task<HttpResponseMessage> SendPutJsonAsync(
this HttpClient client,
string url,
object body
) => client.PutAsJsonAsync(url, body, JsonOptions);
}
@@ -42,20 +42,24 @@ public sealed class PnvPanelWebApplicationFactory : WebApplicationFactory<Progra
{
builder.UseEnvironment("Development");
builder.ConfigureAppConfiguration((_, config) =>
{
config.AddInMemoryCollection(new Dictionary<string, string?>
builder.ConfigureAppConfiguration(
(_, config) =>
{
["ConnectionStrings:Default"] = _postgres.GetConnectionString(),
["AdminSeed:Username"] = AdminUserName,
["AdminSeed:Password"] = AdminPassword,
// Пусто — TelegramBotHostedService при пустом токене не стартует (см. Api/Telegram/TelegramBotHostedService.cs).
["Telegram:BotToken"] = "",
// Весь collection делит один TestServer/host — все запросы идут от одного "клиента",
// дефолтный лимит 20/мин быстро исчерпывается. Поднимаем для тестового окружения.
["RateLimiting:AuthPermitLimit"] = "10000",
});
});
config.AddInMemoryCollection(
new Dictionary<string, string?>
{
["ConnectionStrings:Default"] = _postgres.GetConnectionString(),
["AdminSeed:Username"] = AdminUserName,
["AdminSeed:Password"] = AdminPassword,
// Пусто — TelegramBotHostedService при пустом токене не стартует (см. Api/Telegram/TelegramBotHostedService.cs).
["Telegram:BotToken"] = "",
// Весь collection делит один TestServer/host — все запросы идут от одного "клиента",
// дефолтный лимит 20/мин быстро исчерпывается. Поднимаем для тестового окружения.
["RateLimiting:AuthPermitLimit"] = "10000",
}
);
}
);
builder.ConfigureServices(services =>
{