This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
backend/src/Logitar.Master.Application/Accounts/Commands/SignOutCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Logitar.Portal.Contracts.Sessions; | ||
using Logitar.Portal.Contracts.Users; | ||
using MediatR; | ||
|
||
namespace Logitar.Master.Application.Accounts.Commands; | ||
|
||
public record SignOutCommand : IRequest<Unit> | ||
{ | ||
public Guid? SessionId { get; } | ||
public Guid? UserId { get; } | ||
|
||
public SignOutCommand(Session session) | ||
{ | ||
SessionId = session.Id; | ||
} | ||
public SignOutCommand(User user) | ||
{ | ||
UserId = user.Id; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/src/Logitar.Master.Application/Accounts/Commands/SignOutCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using MediatR; | ||
|
||
namespace Logitar.Master.Application.Accounts.Commands; | ||
|
||
internal class SignOutCommandHandler : IRequestHandler<SignOutCommand, Unit> | ||
{ | ||
private readonly ISessionService _sessionService; | ||
private readonly IUserService _userService; | ||
|
||
public SignOutCommandHandler(ISessionService sessionService, IUserService userService) | ||
{ | ||
_sessionService = sessionService; | ||
_userService = userService; | ||
} | ||
|
||
public async Task<Unit> Handle(SignOutCommand command, CancellationToken cancellationToken) | ||
{ | ||
if (command.SessionId.HasValue) | ||
{ | ||
_ = await _sessionService.SignOutAsync(command.SessionId.Value, cancellationToken); | ||
} | ||
else if (command.UserId.HasValue) | ||
{ | ||
_ = await _userService.SignOutAsync(command.UserId.Value, cancellationToken); | ||
} | ||
|
||
return Unit.Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ests/Logitar.Master.IntegrationTests/Application/Accounts/Commands/SignOutCommandTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Logitar.Portal.Contracts.Sessions; | ||
using Logitar.Portal.Contracts.Users; | ||
using Moq; | ||
|
||
namespace Logitar.Master.Application.Accounts.Commands; | ||
|
||
[Trait(Traits.Category, Categories.Integration)] | ||
public class SignOutCommandTests : IntegrationTests | ||
{ | ||
public SignOutCommandTests() : base() | ||
{ | ||
} | ||
|
||
[Fact(DisplayName = "It should sign out a session when a session ID is provided.")] | ||
public async Task It_should_sign_out_a_session_when_a_session_Id_is_provided() | ||
{ | ||
User user = new(Faker.Person.UserName) | ||
{ | ||
Id = ActorId.ToGuid() | ||
}; | ||
Session session = new(user) | ||
{ | ||
Id = Guid.NewGuid() | ||
}; | ||
|
||
SignOutCommand command = new(session); | ||
await Pipeline.ExecuteAsync(command, CancellationToken); | ||
|
||
SessionService.Verify(x => x.SignOutAsync(session.Id, CancellationToken), Times.Once); | ||
UserService.Verify(x => x.SignOutAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()), Times.Never); | ||
} | ||
|
||
[Fact(DisplayName = "It should sign out an user when an user ID is provided.")] | ||
public async Task It_should_sign_out_an_user_when_an_user_Id_is_provided() | ||
{ | ||
User user = new(Faker.Person.UserName) | ||
{ | ||
Id = ActorId.ToGuid() | ||
}; | ||
|
||
SignOutCommand command = new(user); | ||
await Pipeline.ExecuteAsync(command, CancellationToken); | ||
|
||
SessionService.Verify(x => x.SignOutAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()), Times.Never); | ||
UserService.Verify(x => x.SignOutAsync(user.Id, CancellationToken), Times.Once); | ||
} | ||
} |