Refactor project files for improved readability and structure
- 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:
@@ -11,9 +11,11 @@ public class LoginCommandHandlerTests
|
||||
{
|
||||
private readonly IIdentityService _identityService = Substitute.For<IIdentityService>();
|
||||
private readonly IJwtTokenService _jwtTokenService = Substitute.For<IJwtTokenService>();
|
||||
private readonly IRefreshTokenService _refreshTokenService = Substitute.For<IRefreshTokenService>();
|
||||
private readonly IRefreshTokenService _refreshTokenService =
|
||||
Substitute.For<IRefreshTokenService>();
|
||||
|
||||
private LoginCommandHandler CreateHandler() => new(_identityService, _jwtTokenService, _refreshTokenService);
|
||||
private LoginCommandHandler CreateHandler() =>
|
||||
new(_identityService, _jwtTokenService, _refreshTokenService);
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WithValidCredentials_ReturnsAuthResult()
|
||||
@@ -21,20 +23,33 @@ public class LoginCommandHandlerTests
|
||||
var userId = Guid.NewGuid();
|
||||
var authUser = new AuthenticatedUser(userId, "alice", "user");
|
||||
var profile = new CurrentUserProfile(
|
||||
userId, "alice", Guid.NewGuid(), "user", IsActivated: true, IsBlocked: false, MaxConfigs: 3,
|
||||
MaxIpLimit: RoleQuota.Unlimited, SubscriptionToken: "sub-token");
|
||||
userId,
|
||||
"alice",
|
||||
Guid.NewGuid(),
|
||||
"user",
|
||||
IsActivated: true,
|
||||
IsBlocked: false,
|
||||
MaxConfigs: 3,
|
||||
MaxIpLimit: RoleQuota.Unlimited,
|
||||
SubscriptionToken: "sub-token"
|
||||
);
|
||||
|
||||
_identityService.ValidateCredentialsAsync("alice", "P@ssw0rd", Arg.Any<CancellationToken>())
|
||||
_identityService
|
||||
.ValidateCredentialsAsync("alice", "P@ssw0rd", Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success(authUser));
|
||||
_identityService.GetProfileAsync(userId, Arg.Any<CancellationToken>()).Returns(profile);
|
||||
_identityService.GetTelegramLinkInfoAsync(userId, Arg.Any<CancellationToken>())
|
||||
_identityService
|
||||
.GetTelegramLinkInfoAsync(userId, Arg.Any<CancellationToken>())
|
||||
.Returns(new TelegramLinkInfo(true, 123456, "alice_tg"));
|
||||
_jwtTokenService.GenerateAccessToken(Arg.Any<AuthenticatedUser>())
|
||||
_jwtTokenService
|
||||
.GenerateAccessToken(Arg.Any<AuthenticatedUser>())
|
||||
.Returns(("access-token", DateTimeOffset.UtcNow.AddMinutes(15)));
|
||||
_refreshTokenService.IssueAsync(userId, Arg.Any<CancellationToken>())
|
||||
_refreshTokenService
|
||||
.IssueAsync(userId, Arg.Any<CancellationToken>())
|
||||
.Returns(new IssuedRefreshToken("refresh-token", DateTimeOffset.UtcNow.AddDays(30)));
|
||||
|
||||
var result = await CreateHandler().Handle(new LoginCommand("alice", "P@ssw0rd"), CancellationToken.None);
|
||||
var result = await CreateHandler()
|
||||
.Handle(new LoginCommand("alice", "P@ssw0rd"), CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal("access-token", result.Value.AccessToken);
|
||||
@@ -46,14 +61,18 @@ public class LoginCommandHandlerTests
|
||||
[Fact]
|
||||
public async Task Handle_WithInvalidCredentials_ReturnsFailureWithoutIssuingTokens()
|
||||
{
|
||||
_identityService.ValidateCredentialsAsync("alice", "wrong", Arg.Any<CancellationToken>())
|
||||
_identityService
|
||||
.ValidateCredentialsAsync("alice", "wrong", Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Failure<AuthenticatedUser>(AuthErrors.InvalidCredentials));
|
||||
|
||||
var result = await CreateHandler().Handle(new LoginCommand("alice", "wrong"), CancellationToken.None);
|
||||
var result = await CreateHandler()
|
||||
.Handle(new LoginCommand("alice", "wrong"), CancellationToken.None);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(AuthErrors.InvalidCredentials, result.Error);
|
||||
await _refreshTokenService.DidNotReceive().IssueAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _refreshTokenService
|
||||
.DidNotReceive()
|
||||
.IssueAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +81,15 @@ public class LoginCommandHandlerTests
|
||||
var userId = Guid.NewGuid();
|
||||
var authUser = new AuthenticatedUser(userId, "alice", "user");
|
||||
|
||||
_identityService.ValidateCredentialsAsync("alice", "P@ssw0rd", Arg.Any<CancellationToken>())
|
||||
_identityService
|
||||
.ValidateCredentialsAsync("alice", "P@ssw0rd", Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success(authUser));
|
||||
_identityService.GetProfileAsync(userId, Arg.Any<CancellationToken>()).Returns((CurrentUserProfile?)null);
|
||||
_identityService
|
||||
.GetProfileAsync(userId, Arg.Any<CancellationToken>())
|
||||
.Returns((CurrentUserProfile?)null);
|
||||
|
||||
var result = await CreateHandler().Handle(new LoginCommand("alice", "P@ssw0rd"), CancellationToken.None);
|
||||
var result = await CreateHandler()
|
||||
.Handle(new LoginCommand("alice", "P@ssw0rd"), CancellationToken.None);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(AuthErrors.InvalidCredentials, result.Error);
|
||||
|
||||
Reference in New Issue
Block a user