PrivateChatsRepositoryTests

This commit is contained in:
Artemy
2025-07-07 19:33:47 +07:00
parent b027b20fc3
commit baeafad007
6 changed files with 323 additions and 14 deletions
@@ -4,13 +4,41 @@ namespace Govor.Core.Infrastructure.Validators;
public class ChatGroupValidator : IObjectValidator<ChatGroup>
{
public void Validate(ChatGroup objectToValidate)
public void Validate(ChatGroup chat)
{
throw new NotImplementedException();
try
{
if(chat is null)
throw new ArgumentNullException(nameof(chat));
if(chat.Id == Guid.Empty)
throw new ArgumentException("Id of chat group can't be empty",nameof(chat.Id));
if(string.IsNullOrEmpty(chat.Name))
throw new ArgumentException("Name of chat group can't be empty",nameof(chat.Name));
if(chat.Description is null)
throw new ArgumentException("Description of chat group can't be null",nameof(chat.Description));
if(chat.ImageId == Guid.Empty)
throw new ArgumentException("ImageId of chat group can't be empty",nameof(chat.ImageId));
if(chat.IsPrivate && chat.InviteCodes.Count <= 0)
throw new ArgumentException("Private group must have invitation links",nameof(chat.InviteCodes));
if(chat.Admins.Count <= 0)
throw new ArgumentException("Chat must have owner",nameof(chat.Admins));
}
catch (Exception ex)
{
throw new InvalidObjectException<ChatGroup>(ex);
}
}
public bool TryValidate(ChatGroup objectToValidate)
public bool TryValidate(ChatGroup chat)
{
throw new NotImplementedException();
try
{
Validate(chat);
return true;
}
catch (Exception)
{
return false;
}
}
}
+8
View File
@@ -6,4 +6,12 @@ public class PrivateChat
public Guid UserAId { get; set; }
public Guid UserBId { get; set; }
public List<Message> Messages { get; set; } = new List<Message>();
public override bool Equals(object? obj)
{
PrivateChat other = obj as PrivateChat;
return Id == other.Id &&
UserAId == other.UserAId &&
UserBId == other.UserBId;
}
}