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
@@ -16,8 +16,17 @@ public class AddTicketCommentCommandHandlerTests
private readonly IRealtimeNotifier _notifier = Substitute.For<IRealtimeNotifier>();
private static CurrentUserProfile Profile(Guid userId, string role) =>
new(userId, "user", Guid.NewGuid(), role, IsActivated: true, IsBlocked: false, MaxConfigs: 3,
MaxIpLimit: RoleQuota.Unlimited, SubscriptionToken: "token");
new(
userId,
"user",
Guid.NewGuid(),
role,
IsActivated: true,
IsBlocked: false,
MaxConfigs: 3,
MaxIpLimit: RoleQuota.Unlimited,
SubscriptionToken: "token"
);
[Fact]
public async Task Handle_WhenOwnerComments_AddsCommentAndDoesNotNotifySelf()
@@ -28,16 +37,33 @@ public class AddTicketCommentCommandHandlerTests
dbContext.SupportTickets.Add(ticket);
await dbContext.SaveChangesAsync(CancellationToken.None);
_identityService.GetProfileAsync(userId, Arg.Any<CancellationToken>()).Returns(Profile(userId, "user"));
_identityService
.GetProfileAsync(userId, Arg.Any<CancellationToken>())
.Returns(Profile(userId, "user"));
var currentUser = FakeCurrentUser.Authenticated(userId, "alice");
var handler = new AddTicketCommentCommandHandler(dbContext, _identityService, _fileStorage, _notifier, currentUser);
var handler = new AddTicketCommentCommandHandler(
dbContext,
_identityService,
_fileStorage,
_notifier,
currentUser
);
var result = await handler.Handle(new AddTicketCommentCommand(ticket.Id, "апдейт", []), CancellationToken.None);
var result = await handler.Handle(
new AddTicketCommentCommand(ticket.Id, "апдейт", []),
CancellationToken.None
);
Assert.True(result.IsSuccess);
Assert.Equal("апдейт", result.Value.Body);
await _notifier.DidNotReceive().NotifyTicketUpdatedAsync(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _notifier
.DidNotReceive()
.NotifyTicketUpdatedAsync(
Arg.Any<Guid>(),
Arg.Any<Guid>(),
Arg.Any<CancellationToken>()
);
}
[Fact]
@@ -50,15 +76,28 @@ public class AddTicketCommentCommandHandlerTests
dbContext.SupportTickets.Add(ticket);
await dbContext.SaveChangesAsync(CancellationToken.None);
_identityService.GetProfileAsync(adminId, Arg.Any<CancellationToken>()).Returns(Profile(adminId, "admin"));
_identityService
.GetProfileAsync(adminId, Arg.Any<CancellationToken>())
.Returns(Profile(adminId, "admin"));
var currentUser = FakeCurrentUser.Authenticated(adminId, "admin");
var handler = new AddTicketCommentCommandHandler(dbContext, _identityService, _fileStorage, _notifier, currentUser);
var handler = new AddTicketCommentCommandHandler(
dbContext,
_identityService,
_fileStorage,
_notifier,
currentUser
);
var result = await handler.Handle(new AddTicketCommentCommand(ticket.Id, "ответ админа", []), CancellationToken.None);
var result = await handler.Handle(
new AddTicketCommentCommand(ticket.Id, "ответ админа", []),
CancellationToken.None
);
Assert.True(result.IsSuccess);
await _notifier.Received(1).NotifyTicketUpdatedAsync(ticket.Id, ownerId, Arg.Any<CancellationToken>());
await _notifier
.Received(1)
.NotifyTicketUpdatedAsync(ticket.Id, ownerId, Arg.Any<CancellationToken>());
}
[Fact]
@@ -71,12 +110,23 @@ public class AddTicketCommentCommandHandlerTests
dbContext.SupportTickets.Add(ticket);
await dbContext.SaveChangesAsync(CancellationToken.None);
_identityService.GetProfileAsync(strangerId, Arg.Any<CancellationToken>()).Returns(Profile(strangerId, "user"));
_identityService
.GetProfileAsync(strangerId, Arg.Any<CancellationToken>())
.Returns(Profile(strangerId, "user"));
var currentUser = FakeCurrentUser.Authenticated(strangerId);
var handler = new AddTicketCommentCommandHandler(dbContext, _identityService, _fileStorage, _notifier, currentUser);
var handler = new AddTicketCommentCommandHandler(
dbContext,
_identityService,
_fileStorage,
_notifier,
currentUser
);
var result = await handler.Handle(new AddTicketCommentCommand(ticket.Id, "текст", []), CancellationToken.None);
var result = await handler.Handle(
new AddTicketCommentCommand(ticket.Id, "текст", []),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.NotFound, result.Error);
@@ -92,12 +142,23 @@ public class AddTicketCommentCommandHandlerTests
dbContext.SupportTickets.Add(ticket);
await dbContext.SaveChangesAsync(CancellationToken.None);
_identityService.GetProfileAsync(userId, Arg.Any<CancellationToken>()).Returns(Profile(userId, "user"));
_identityService
.GetProfileAsync(userId, Arg.Any<CancellationToken>())
.Returns(Profile(userId, "user"));
var currentUser = FakeCurrentUser.Authenticated(userId);
var handler = new AddTicketCommentCommandHandler(dbContext, _identityService, _fileStorage, _notifier, currentUser);
var handler = new AddTicketCommentCommandHandler(
dbContext,
_identityService,
_fileStorage,
_notifier,
currentUser
);
var result = await handler.Handle(new AddTicketCommentCommand(ticket.Id, "текст", []), CancellationToken.None);
var result = await handler.Handle(
new AddTicketCommentCommand(ticket.Id, "текст", []),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.TicketClosed, result.Error);
@@ -21,9 +21,18 @@ public class CreateBugReportTicketCommandHandlerTests
var userId = Guid.NewGuid();
var currentUser = FakeCurrentUser.Authenticated(userId, "alice");
var handler = new CreateBugReportTicketCommandHandler(dbContext, _fileStorage, _notifier, _telegramNotifier, currentUser);
var handler = new CreateBugReportTicketCommandHandler(
dbContext,
_fileStorage,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(new CreateBugReportTicketCommand("Что-то сломалось", []), CancellationToken.None);
var result = await handler.Handle(
new CreateBugReportTicketCommand("Что-то сломалось", []),
CancellationToken.None
);
await dbContext.SaveChangesAsync(CancellationToken.None);
Assert.True(result.IsSuccess);
@@ -33,8 +42,14 @@ public class CreateBugReportTicketCommandHandlerTests
Assert.Equal("Что-то сломалось", result.Value.Comments[0].Body);
Assert.Single(dbContext.SupportTickets);
Assert.Single(dbContext.TicketComments);
await _telegramNotifier.Received(1).NotifyAdminsBugReportCreatedAsync(
Arg.Any<Guid>(), "alice", "Что-то сломалось", Arg.Any<CancellationToken>());
await _telegramNotifier
.Received(1)
.NotifyAdminsBugReportCreatedAsync(
Arg.Any<Guid>(),
"alice",
"Что-то сломалось",
Arg.Any<CancellationToken>()
);
}
[Fact]
@@ -42,13 +57,23 @@ public class CreateBugReportTicketCommandHandlerTests
{
using var dbContext = InMemoryDbContextFactory.Create();
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid());
var attachments = Enumerable.Range(0, 6)
var attachments = Enumerable
.Range(0, 6)
.Select(_ => new TicketAttachmentUpload(new MemoryStream(), "a.png", "image/png", 10))
.ToList();
var handler = new CreateBugReportTicketCommandHandler(dbContext, _fileStorage, _notifier, _telegramNotifier, currentUser);
var handler = new CreateBugReportTicketCommandHandler(
dbContext,
_fileStorage,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(new CreateBugReportTicketCommand("текст", attachments), CancellationToken.None);
var result = await handler.Handle(
new CreateBugReportTicketCommand("текст", attachments),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.TooManyAttachments, result.Error);
@@ -59,11 +84,23 @@ public class CreateBugReportTicketCommandHandlerTests
{
using var dbContext = InMemoryDbContextFactory.Create();
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid());
var attachments = new[] { new TicketAttachmentUpload(new MemoryStream(), "a.exe", "application/x-msdownload", 10) };
var attachments = new[]
{
new TicketAttachmentUpload(new MemoryStream(), "a.exe", "application/x-msdownload", 10),
};
var handler = new CreateBugReportTicketCommandHandler(dbContext, _fileStorage, _notifier, _telegramNotifier, currentUser);
var handler = new CreateBugReportTicketCommandHandler(
dbContext,
_fileStorage,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(new CreateBugReportTicketCommand("текст", attachments), CancellationToken.None);
var result = await handler.Handle(
new CreateBugReportTicketCommand("текст", attachments),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.UnsupportedAttachmentType, result.Error);
@@ -21,20 +21,36 @@ public class CreateRoleRequestTicketCommandHandlerTests
var userId = Guid.NewGuid();
var roleId = Guid.NewGuid();
var currentUser = FakeCurrentUser.Authenticated(userId, "alice");
_roleService.ListRolesAsync(Arg.Any<CancellationToken>())
_roleService
.ListRolesAsync(Arg.Any<CancellationToken>())
.Returns(new List<RoleDto> { new(roleId, "premium", 5, 2, false) });
var handler = new CreateRoleRequestTicketCommandHandler(dbContext, _roleService, _notifier, _telegramNotifier, currentUser);
var handler = new CreateRoleRequestTicketCommandHandler(
dbContext,
_roleService,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(
new CreateRoleRequestTicketCommand(roleId, null, null, null, "нужно больше конфигов"), CancellationToken.None);
new CreateRoleRequestTicketCommand(roleId, null, null, null, "нужно больше конфигов"),
CancellationToken.None
);
await dbContext.SaveChangesAsync(CancellationToken.None);
Assert.True(result.IsSuccess);
Assert.Equal(roleId, result.Value.RequestedRoleId);
Assert.Equal("premium", result.Value.RequestedRoleName);
await _telegramNotifier.Received(1).NotifyAdminsRoleRequestCreatedAsync(
Arg.Any<Guid>(), "alice", "premium", "нужно больше конфигов", Arg.Any<CancellationToken>());
await _telegramNotifier
.Received(1)
.NotifyAdminsRoleRequestCreatedAsync(
Arg.Any<Guid>(),
"alice",
"premium",
"нужно больше конфигов",
Arg.Any<CancellationToken>()
);
}
[Fact]
@@ -43,13 +59,22 @@ public class CreateRoleRequestTicketCommandHandlerTests
using var dbContext = InMemoryDbContextFactory.Create();
var roleId = Guid.NewGuid();
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid());
_roleService.ListRolesAsync(Arg.Any<CancellationToken>())
_roleService
.ListRolesAsync(Arg.Any<CancellationToken>())
.Returns(new List<RoleDto> { new(roleId, "admin", -1, -1, true) });
var handler = new CreateRoleRequestTicketCommandHandler(dbContext, _roleService, _notifier, _telegramNotifier, currentUser);
var handler = new CreateRoleRequestTicketCommandHandler(
dbContext,
_roleService,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(
new CreateRoleRequestTicketCommand(roleId, null, null, null, "хочу быть админом"), CancellationToken.None);
new CreateRoleRequestTicketCommand(roleId, null, null, null, "хочу быть админом"),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.CannotRequestAdminRole, result.Error);
@@ -61,10 +86,18 @@ public class CreateRoleRequestTicketCommandHandlerTests
using var dbContext = InMemoryDbContextFactory.Create();
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid(), "bob");
var handler = new CreateRoleRequestTicketCommandHandler(dbContext, _roleService, _notifier, _telegramNotifier, currentUser);
var handler = new CreateRoleRequestTicketCommandHandler(
dbContext,
_roleService,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(
new CreateRoleRequestTicketCommand(null, "custom", 10, 4, "нужна кастомная роль"), CancellationToken.None);
new CreateRoleRequestTicketCommand(null, "custom", 10, 4, "нужна кастомная роль"),
CancellationToken.None
);
Assert.True(result.IsSuccess);
Assert.Equal("custom", result.Value.ProposedRoleName);
@@ -81,10 +114,18 @@ public class CreateRoleRequestTicketCommandHandlerTests
await dbContext.SaveChangesAsync(CancellationToken.None);
var currentUser = FakeCurrentUser.Authenticated(userId);
var handler = new CreateRoleRequestTicketCommandHandler(dbContext, _roleService, _notifier, _telegramNotifier, currentUser);
var handler = new CreateRoleRequestTicketCommandHandler(
dbContext,
_roleService,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(
new CreateRoleRequestTicketCommand(null, "y", 2, 2, "ещё заявка"), CancellationToken.None);
new CreateRoleRequestTicketCommand(null, "y", 2, 2, "ещё заявка"),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.RoleRequestAlreadyPending, result.Error);
@@ -25,12 +25,21 @@ public class ReopenTicketCommandHandlerTests
var currentUser = FakeCurrentUser.Authenticated(userId);
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
var result = await handler.Handle(
new ReopenTicketCommand(ticket.Id),
CancellationToken.None
);
Assert.True(result.IsSuccess);
Assert.Equal(TicketStatus.Open, ticket.Status);
await _telegramNotifier.Received(1).NotifyAdminsTicketReopenedAsync(
ticket.Id, Arg.Any<string>(), TicketType.BugReport, Arg.Any<CancellationToken>());
await _telegramNotifier
.Received(1)
.NotifyAdminsTicketReopenedAsync(
ticket.Id,
Arg.Any<string>(),
TicketType.BugReport,
Arg.Any<CancellationToken>()
);
}
[Fact]
@@ -45,7 +54,10 @@ public class ReopenTicketCommandHandlerTests
var currentUser = FakeCurrentUser.Authenticated(userId);
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
var result = await handler.Handle(
new ReopenTicketCommand(ticket.Id),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.NotResolved, result.Error);
@@ -63,7 +75,10 @@ public class ReopenTicketCommandHandlerTests
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid());
var handler = new ReopenTicketCommandHandler(dbContext, _telegramNotifier, currentUser);
var result = await handler.Handle(new ReopenTicketCommand(ticket.Id), CancellationToken.None);
var result = await handler.Handle(
new ReopenTicketCommand(ticket.Id),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.NotFound, result.Error);