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.
69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using AutoFixture;
|
|
using Govor.Application.Interfaces.Friends;
|
|
using Govor.Application.Interfaces.UserOnlineStatus;
|
|
using Govor.Application.Services.UserOnlineStatus;
|
|
using Govor.Domain.Models;
|
|
using Govor.Domain.Models.Users;
|
|
using Govor.Data.Repositories.Exceptions;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
|
|
namespace Govor.Application.Tests.Services.UserOnlineStatus;
|
|
|
|
[TestFixture]
|
|
[TestOf(typeof(UserNotificationScopeService))]
|
|
public class UserNotificationScopeServiceTests
|
|
{
|
|
private Mock<ILogger<UserNotificationScopeService>> _mockLogger;
|
|
private Mock<IFriendshipService> _mockFriendshipService;
|
|
private IUserNotificationScopeService _service;
|
|
private Fixture _fixture;
|
|
private Guid _userId;
|
|
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_fixture = new Fixture();
|
|
_fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList().ForEach(b => _fixture.Behaviors.Remove(b));
|
|
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
|
|
|
|
_userId = Guid.NewGuid();
|
|
|
|
_mockLogger = new Mock<ILogger<UserNotificationScopeService>>();
|
|
_mockFriendshipService = new Mock<IFriendshipService>();
|
|
|
|
_service = new UserNotificationScopeService(_mockLogger.Object, _mockFriendshipService.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetNotifiedUsers_ReturnsNotifiedUsers()
|
|
{
|
|
// Arrange
|
|
var random = new Random();
|
|
var users = _fixture.CreateMany<User>(random.Next(3, 10)).ToList();
|
|
|
|
_mockFriendshipService.Setup(f => f.GetFriendsAsync(_userId))
|
|
.ReturnsAsync(users);
|
|
|
|
// Act
|
|
var result = await _service.GetNotifiedUsers(_userId);
|
|
// Assert
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result.Count, Is.EqualTo(users.Count));
|
|
Assert.That(result, Is.EquivalentTo(users.Select(u => u.Id)));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetNotifiedUsers_ThrowsInvalidOperationException_WhenUserDoesNotExist()
|
|
{
|
|
// Arrange
|
|
_mockFriendshipService.Setup(f => f.GetFriendsAsync(_userId))
|
|
.ThrowsAsync(new NotFoundByKeyException<Guid>(_userId, "Database is empty."));
|
|
|
|
// Act & Assert
|
|
var ex = Assert.ThrowsAsync<InvalidOperationException>(async () => await _service.GetNotifiedUsers(_userId));
|
|
Assert.That(ex.Message, Is.EqualTo("User not found"));
|
|
}
|
|
}
|