Add username validation and initial friends feature

Introduced a UsernameValidator with Cyrillic and length checks, integrated into AuthService and registration flow. Added InvalidUsernameException and related interface. Updated User model to support friend requests, added FriendsController (stub), and configured Friendship entity in EF Core. Adjusted UserValidator max name length and removed navigation properties from PrivateChat.
This commit is contained in:
Artemy
2025-06-27 16:36:56 +07:00
parent 9b9cd73a96
commit ec44347bbe
14 changed files with 201 additions and 6 deletions
@@ -0,0 +1,43 @@
using Govor.Application.Validators; // или другой namespace
using Govor.Application.Exceptions.AuthService;
namespace Govor.API.Tests.UnitTests.Services.Validators;
[TestFixture]
public class UsernameValidatorTests
{
private UsernameValidator _validator;
[SetUp]
public void SetUp()
{
_validator = new UsernameValidator();
}
[TestCase("Иван")]
[TestCase("Алексей")]
[TestCase("Ёжик")]
public void Validate_ValidUsernames_ShouldNotThrow(string username)
{
Assert.DoesNotThrow(() => _validator.Validate(username));
}
[TestCase("Ivan")] // не кириллица
[TestCase("123Иван")] // начинается не с буквы
[TestCase("Иван123")] // содержит цифры
[TestCase("!@#$")] // спецсимволы
[TestCase("")] // пусто
[TestCase("И")] // меньше минимума
[TestCase("ИванИванИванИванИванИванИванИванИванИванИванИванИван")] // больше максимума (44 символа)
public void Validate_InvalidUsernames_ShouldThrow(string username)
{
Assert.Throws<InvalidUsernameException>(() => _validator.Validate(username));
}
[TestCase("Иван", ExpectedResult = true)]
[TestCase("1234", ExpectedResult = false)]
public bool TryValidate_ShouldReturnTrueRegardlessOfInput(string username)
{
return _validator.TryValidate(username);
}
}