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:
+56
-12
@@ -27,15 +27,28 @@ public class ApproveActivationCommandHandlerTests
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
_currentUser.UserId.Returns(adminId);
|
||||
_identityService.ActivateUserAsync(request.UserId, adminId, Arg.Any<CancellationToken>()).Returns(Result.Success());
|
||||
_identityService
|
||||
.ActivateUserAsync(request.UserId, adminId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success());
|
||||
|
||||
var handler = new ApproveActivationCommandHandler(dbContext, _identityService, _notifier, _telegramNotifier, _currentUser);
|
||||
var handler = new ApproveActivationCommandHandler(
|
||||
dbContext,
|
||||
_identityService,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new ApproveActivationCommand(request.Id), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new ApproveActivationCommand(request.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(ActivationStatus.Approved, request.Status);
|
||||
await _notifier.Received(1).NotifyUserActivatedAsync(request.UserId, Arg.Any<CancellationToken>());
|
||||
await _notifier
|
||||
.Received(1)
|
||||
.NotifyUserActivatedAsync(request.UserId, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -44,9 +57,18 @@ public class ApproveActivationCommandHandlerTests
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
_currentUser.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
var handler = new ApproveActivationCommandHandler(dbContext, _identityService, _notifier, _telegramNotifier, _currentUser);
|
||||
var handler = new ApproveActivationCommandHandler(
|
||||
dbContext,
|
||||
_identityService,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new ApproveActivationCommand(Guid.NewGuid()), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new ApproveActivationCommand(Guid.NewGuid()),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(ActivationErrors.NotFound, result.Error);
|
||||
@@ -63,9 +85,18 @@ public class ApproveActivationCommandHandlerTests
|
||||
|
||||
_currentUser.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
var handler = new ApproveActivationCommandHandler(dbContext, _identityService, _notifier, _telegramNotifier, _currentUser);
|
||||
var handler = new ApproveActivationCommandHandler(
|
||||
dbContext,
|
||||
_identityService,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new ApproveActivationCommand(request.Id), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new ApproveActivationCommand(request.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(ActivationErrors.AlreadyDecided, result.Error);
|
||||
@@ -82,14 +113,27 @@ public class ApproveActivationCommandHandlerTests
|
||||
|
||||
_currentUser.UserId.Returns(adminId);
|
||||
var failure = Error.NotFound("User.NotFound", "Пользователь не найден.");
|
||||
_identityService.ActivateUserAsync(request.UserId, adminId, Arg.Any<CancellationToken>()).Returns(Result.Failure(failure));
|
||||
_identityService
|
||||
.ActivateUserAsync(request.UserId, adminId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Failure(failure));
|
||||
|
||||
var handler = new ApproveActivationCommandHandler(dbContext, _identityService, _notifier, _telegramNotifier, _currentUser);
|
||||
var handler = new ApproveActivationCommandHandler(
|
||||
dbContext,
|
||||
_identityService,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new ApproveActivationCommand(request.Id), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new ApproveActivationCommand(request.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(failure, result.Error);
|
||||
await _notifier.DidNotReceive().NotifyUserActivatedAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _notifier
|
||||
.DidNotReceive()
|
||||
.NotifyUserActivatedAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
|
||||
+12
-3
@@ -25,7 +25,10 @@ public class RejectActivationCommandHandlerTests
|
||||
|
||||
var handler = new RejectActivationCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var result = await handler.Handle(new RejectActivationCommand(request.Id, "недостаточно информации"), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new RejectActivationCommand(request.Id, "недостаточно информации"),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(ActivationStatus.Rejected, request.Status);
|
||||
@@ -40,7 +43,10 @@ public class RejectActivationCommandHandlerTests
|
||||
|
||||
var handler = new RejectActivationCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var result = await handler.Handle(new RejectActivationCommand(Guid.NewGuid(), null), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new RejectActivationCommand(Guid.NewGuid(), null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(ActivationErrors.NotFound, result.Error);
|
||||
@@ -59,7 +65,10 @@ public class RejectActivationCommandHandlerTests
|
||||
|
||||
var handler = new RejectActivationCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var result = await handler.Handle(new RejectActivationCommand(request.Id, null), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new RejectActivationCommand(request.Id, null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(ActivationErrors.AlreadyDecided, result.Error);
|
||||
|
||||
+58
-12
@@ -22,18 +22,40 @@ public class RequestActivationCommandHandlerTests
|
||||
_currentUser.UserId.Returns(userId);
|
||||
_currentUser.UserName.Returns("alice");
|
||||
|
||||
var handler = new RequestActivationCommandHandler(dbContext, _notifier, _telegramNotifier, _currentUser);
|
||||
var handler = new RequestActivationCommandHandler(
|
||||
dbContext,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new RequestActivationCommand("Please activate"), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new RequestActivationCommand("Please activate"),
|
||||
CancellationToken.None
|
||||
);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal("Please activate", result.Value.Comment);
|
||||
Assert.Single(dbContext.ActivationRequests);
|
||||
await _notifier.Received(1).NotifyActivationRequestedAsync(
|
||||
Arg.Any<Guid>(), userId, "alice", "Please activate", Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>());
|
||||
await _telegramNotifier.Received(1).NotifyAdminsActivationRequestedAsync(
|
||||
Arg.Any<Guid>(), "alice", "Please activate", Arg.Any<CancellationToken>());
|
||||
await _notifier
|
||||
.Received(1)
|
||||
.NotifyActivationRequestedAsync(
|
||||
Arg.Any<Guid>(),
|
||||
userId,
|
||||
"alice",
|
||||
"Please activate",
|
||||
Arg.Any<DateTimeOffset>(),
|
||||
Arg.Any<CancellationToken>()
|
||||
);
|
||||
await _telegramNotifier
|
||||
.Received(1)
|
||||
.NotifyAdminsActivationRequestedAsync(
|
||||
Arg.Any<Guid>(),
|
||||
"alice",
|
||||
"Please activate",
|
||||
Arg.Any<CancellationToken>()
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,14 +69,30 @@ public class RequestActivationCommandHandlerTests
|
||||
_currentUser.UserId.Returns(userId);
|
||||
_currentUser.UserName.Returns("alice");
|
||||
|
||||
var handler = new RequestActivationCommandHandler(dbContext, _notifier, _telegramNotifier, _currentUser);
|
||||
var handler = new RequestActivationCommandHandler(
|
||||
dbContext,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new RequestActivationCommand(null), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new RequestActivationCommand(null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(ActivationErrors.AlreadyPending, result.Error);
|
||||
await _notifier.DidNotReceive().NotifyActivationRequestedAsync(
|
||||
Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string?>(), Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>());
|
||||
await _notifier
|
||||
.DidNotReceive()
|
||||
.NotifyActivationRequestedAsync(
|
||||
Arg.Any<Guid>(),
|
||||
Arg.Any<Guid>(),
|
||||
Arg.Any<string>(),
|
||||
Arg.Any<string?>(),
|
||||
Arg.Any<DateTimeOffset>(),
|
||||
Arg.Any<CancellationToken>()
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -63,9 +101,17 @@ public class RequestActivationCommandHandlerTests
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
_currentUser.UserId.Returns((Guid?)null);
|
||||
|
||||
var handler = new RequestActivationCommandHandler(dbContext, _notifier, _telegramNotifier, _currentUser);
|
||||
var handler = new RequestActivationCommandHandler(
|
||||
dbContext,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
_currentUser
|
||||
);
|
||||
|
||||
var result = await handler.Handle(new RequestActivationCommand(null), CancellationToken.None);
|
||||
var result = await handler.Handle(
|
||||
new RequestActivationCommand(null),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(AuthErrors.Unauthorized, result.Error);
|
||||
|
||||
Reference in New Issue
Block a user