mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
UserValidatorTests
This commit is contained in:
@@ -7,6 +7,7 @@ public class UserValidator : IObjectValidator<User>
|
||||
{
|
||||
public const int MIN_LENGHT_OF_NAME = 4;
|
||||
public const int MAX_LENGHT_OF_NAME = 100;
|
||||
|
||||
public void Validate(User user)
|
||||
{
|
||||
try
|
||||
@@ -15,12 +16,12 @@ public class UserValidator : IObjectValidator<User>
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
if(user.Id == Guid.Empty)
|
||||
throw new ArgumentException("User ID cannot be empty", nameof(user.Id));
|
||||
if(user.Username is null
|
||||
|| user.Username.Length < MIN_LENGHT_OF_NAME
|
||||
|| user.Username.Length > MAX_LENGHT_OF_NAME)
|
||||
throw new ArgumentException($"Username cannot be empty or less then {MIN_LENGHT_OF_NAME} chars or more then {MAX_LENGHT_OF_NAME}", nameof(user.Username));
|
||||
if(user.HashPassword is null || user.HashPassword == string.Empty)
|
||||
throw new ArgumentException("Password cannot be empty", nameof(user.HashPassword));
|
||||
if(user.Name is null
|
||||
|| user.Name.Length < MIN_LENGHT_OF_NAME
|
||||
|| user.Name.Length > MAX_LENGHT_OF_NAME)
|
||||
throw new ArgumentException($"Username cannot be empty or less then {MIN_LENGHT_OF_NAME} chars or more then {MAX_LENGHT_OF_NAME}", nameof(user.Name));
|
||||
if(user.PasswordHash is null || user.PasswordHash == string.Empty)
|
||||
throw new ArgumentException("Password cannot be empty", nameof(user.PasswordHash));
|
||||
if(user.CreatedOn == DateOnly.MinValue)
|
||||
throw new ArgumentException("Time of creation account cannot be empty", nameof(user.CreatedOn));
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace Govor.Core.Models;
|
||||
public class User
|
||||
{
|
||||
public Guid Id {get; set;}
|
||||
public string Username {get; set;}
|
||||
public string Name {get; set;}
|
||||
public string Description {get; set;}
|
||||
public string HashPassword {get; set;}
|
||||
public string PasswordHash {get; set;}
|
||||
public Guid IconId {get; set;}
|
||||
public DateOnly CreatedOn {get; set;}
|
||||
public DateTime WasOnline {get; set;}
|
||||
|
||||
Reference in New Issue
Block a user