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.
70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using AutoFixture;
|
|
using Govor.Application.Groups;
|
|
using Govor.Application.Interfaces;
|
|
using Govor.Domain.Models;
|
|
using Govor.Domain.Repositories.Groups;
|
|
using Govor.Data.Repositories.Exceptions;
|
|
using Moq;
|
|
|
|
namespace Govor.Application.Tests.Services;
|
|
|
|
[TestFixture]
|
|
public class UserGroupsGetterServiceTests
|
|
{
|
|
private Fixture _fixture;
|
|
private Mock<IGroupsRepository> _repositoryMock;
|
|
private IUserGroupsGetterService _getterService;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_fixture = new Fixture();
|
|
|
|
_fixture.Behaviors
|
|
.OfType<ThrowingRecursionBehavior>()
|
|
.ToList()
|
|
.ForEach(b => _fixture.Behaviors.Remove(b));
|
|
|
|
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
|
|
|
|
_repositoryMock = new Mock<IGroupsRepository>();
|
|
|
|
_getterService = new UserGroupsGetterService(_repositoryMock.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetUserGroups_ShouldReturnAllUserGroups()
|
|
{
|
|
// Arrange
|
|
var chats = _fixture.CreateMany<ChatGroup>();
|
|
var userId = chats.First().Members.First().Id;
|
|
|
|
_repositoryMock.Setup(r => r.GetByUserIdAsync(userId))
|
|
.ReturnsAsync([chats.First()]);
|
|
|
|
// Act
|
|
var result = await _getterService.GetUserGroupsAsync(userId);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result.Count(), Is.EqualTo(1));
|
|
Assert.That(result, Is.EquivalentTo([chats.First()]));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetUserGroups_ButGroupDoesNotExist_ShouldReturnEmptyList()
|
|
{
|
|
// Arrange
|
|
var userId = _fixture.Create<Guid>();
|
|
|
|
_repositoryMock.Setup(r => r.GetByUserIdAsync(userId))
|
|
.ThrowsAsync(new NotFoundByKeyException<Guid>(userId));
|
|
|
|
// Act
|
|
var result = await _getterService.GetUserGroupsAsync(userId);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result.Count(), Is.EqualTo(0));
|
|
}
|
|
} |