mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
6d1c53beeb
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
using AutoFixture;
|
|
using Govor.Application.Interfaces.UserSession;
|
|
using Govor.Application.Services.UserSessions;
|
|
using Govor.Domain.Models;
|
|
using Govor.Domain.Models.Users;
|
|
using Govor.Domain.Repositories.UserSessionsRepository;
|
|
using Govor.Data.Repositories.Exceptions;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
|
|
namespace Govor.Application.Tests.Services.UserSessions;
|
|
|
|
[TestFixture]
|
|
[TestOf(typeof(UserSessionReader))]
|
|
public class UserSessionReaderTests
|
|
{
|
|
private Mock<IUserSessionsRepository> _mockUserSessionsRepository;
|
|
private Mock<ILogger<UserSessionReader>> _mockLogger;
|
|
private Fixture _fixture;
|
|
private IUserSessionReader _userSessionReader;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_fixture = new Fixture();
|
|
_fixture.Behaviors.OfType<ThrowingRecursionBehavior>()
|
|
.ToList()
|
|
.ForEach(b => _fixture.Behaviors.Remove(b));
|
|
|
|
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
|
|
|
|
_mockUserSessionsRepository = new Mock<IUserSessionsRepository>();
|
|
_mockLogger = new Mock<ILogger<UserSessionReader>>();
|
|
|
|
_userSessionReader = new UserSessionReader(_mockUserSessionsRepository.Object,
|
|
_mockLogger.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetAllUserSessionsAsync_ShouldReturnAllUserSessions()
|
|
{
|
|
// Arrange
|
|
var sessios = _fixture.Build<UserSession>()
|
|
.With(f => f.IsRevoked, false)
|
|
.CreateMany().ToList();
|
|
|
|
var userId = Guid.NewGuid();
|
|
|
|
_mockUserSessionsRepository.Setup(f => f.GetByUserIdAsync(userId))
|
|
.ReturnsAsync(sessios);
|
|
// Act
|
|
var result = await _userSessionReader.GetAllSessionsAsync(userId);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Is.EquivalentTo(sessios));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetAllUserSessionsAsync_ThrowsNotFoundByKeyException_ReturnsEmptyList()
|
|
{
|
|
// Arrange
|
|
var userId = Guid.NewGuid();
|
|
|
|
_mockUserSessionsRepository.Setup(f => f.GetByUserIdAsync(userId))
|
|
.ThrowsAsync(new NotFoundByKeyException<Guid>(userId));
|
|
|
|
// Act
|
|
var result = await _userSessionReader.GetAllSessionsAsync(userId);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
} |