- Introduced Telegram.Bot package for bot functionality. - Updated user management to include Telegram linking and blocking features. - Enhanced activation request handling with notifications via Telegram. - Added new database entities for Telegram link tokens and login requests. - Implemented traffic synchronization for client stats in the XuiPanelGateway. - Updated application structure to support new test projects and improved dependency injection for Telegram services.
67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using PnvPanel.Application.Admin.Inbounds;
|
|
using PnvPanel.Application.Tests.TestSupport;
|
|
using PnvPanel.Domain.Inbounds;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Application.Tests.Admin.Inbounds;
|
|
|
|
public class PublishInboundCommandHandlerTests
|
|
{
|
|
[Fact]
|
|
public async Task Handle_WhenPublishingExistingInbound_UpdatesPublishState()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var inbound = Inbound.FromRemote(Guid.NewGuid(), "1", VpnProtocol.Vless, "remark", 443);
|
|
dbContext.Inbounds.Add(inbound);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var roleId = Guid.NewGuid();
|
|
var handler = new PublishInboundCommandHandler(dbContext);
|
|
|
|
var command = new PublishInboundCommand(inbound.Id, true, "EU Fast", [roleId], 100);
|
|
|
|
var result = await handler.Handle(command, CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.True(inbound.IsPublished);
|
|
Assert.Equal("EU Fast", inbound.DisplayName);
|
|
Assert.Equal(100, inbound.MaxClients);
|
|
Assert.Contains(roleId, inbound.AllowedRoleIds);
|
|
Assert.Equal("EU Fast", result.Value.DisplayName);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenUnpublishing_ClearsPublishedFlag()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var inbound = Inbound.FromRemote(Guid.NewGuid(), "1", VpnProtocol.Vless, "remark", 443);
|
|
inbound.Publish("EU Fast", [Guid.NewGuid()], 100);
|
|
dbContext.Inbounds.Add(inbound);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new PublishInboundCommandHandler(dbContext);
|
|
|
|
var command = new PublishInboundCommand(inbound.Id, false, null, [], null);
|
|
|
|
var result = await handler.Handle(command, CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.False(inbound.IsPublished);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenInboundNotFound_ReturnsNotFound()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
|
|
var handler = new PublishInboundCommandHandler(dbContext);
|
|
|
|
var command = new PublishInboundCommand(Guid.NewGuid(), true, "EU Fast", [], null);
|
|
|
|
var result = await handler.Handle(command, CancellationToken.None);
|
|
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(InboundErrors.NotFound, result.Error);
|
|
}
|
|
}
|