Files
SIG-CM2.0/tests/SIGCM2.Application.Tests/Auth/Logout/LogoutCommandHandlerTests.cs
dmolinari 9bc191c3ae test(udt-011): T400.40 — update tests for TimeProvider injection and explicit now params
Fix all test compilation errors caused by T400.10/T400.20/T400.30:
- Handler constructors: add TimeProvider.System as last argument
- Domain mutator calls: add DateTime.UtcNow as explicit 'now' argument
- AuditLogger/SecurityEventLogger Build() helpers: add TimeProvider.System
- JwtService test constructors: add TimeProvider.System
Cat2 coverage already present in TimeProviderArgentinaExtensionsTests.cs:
FakeTimeProvider proves GetArgentinaToday() returns ART civil date, not UTC.
2026-04-18 10:12:32 -03:00

42 lines
1.4 KiB
C#

using NSubstitute;
using SIGCM2.Application.Abstractions.Persistence;
using SIGCM2.Application.Audit;
using SIGCM2.Application.Auth.Logout;
namespace SIGCM2.Application.Tests.Auth.Logout;
public class LogoutCommandHandlerTests
{
private readonly IRefreshTokenRepository _refreshRepo = Substitute.For<IRefreshTokenRepository>();
private readonly ISecurityEventLogger _security = Substitute.For<ISecurityEventLogger>();
private readonly LogoutCommandHandler _handler;
public LogoutCommandHandlerTests()
{
_handler = new LogoutCommandHandler(_refreshRepo, _security, TimeProvider.System);
}
[Fact]
public async Task Handle_RevokesAllActiveForUser()
{
_refreshRepo.RevokeAllActiveForUserAsync(42, Arg.Any<DateTime>()).Returns(3);
var result = await _handler.Handle(new LogoutCommand(42));
Assert.True(result.Success);
Assert.False(string.IsNullOrWhiteSpace(result.Mensaje));
await _refreshRepo.Received(1).RevokeAllActiveForUserAsync(42, Arg.Any<DateTime>());
}
[Fact]
public async Task Handle_NoActiveTokens_StillReturnsSuccess()
{
// 0 rows affected = idempotent logout
_refreshRepo.RevokeAllActiveForUserAsync(Arg.Any<int>(), Arg.Any<DateTime>()).Returns(0);
var result = await _handler.Handle(new LogoutCommand(99));
Assert.True(result.Success);
}
}