mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
MediaAttachmentsTests init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using Govor.Core.Models;
|
||||
using Exception = System.Exception;
|
||||
|
||||
namespace Govor.Core.Infrastructure.Validators;
|
||||
|
||||
public class MediaAttachmentsValidator : IObjectValidator<MediaAttachments>
|
||||
{
|
||||
public void Validate(MediaAttachments attachments)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (attachments is null)
|
||||
throw new ArgumentNullException(nameof(attachments));
|
||||
if(attachments.Id == Guid.Empty)
|
||||
throw new ArgumentException("Id cannot be empty", nameof(attachments));
|
||||
if(attachments.MessageId == Guid.Empty)
|
||||
throw new ArgumentException("MessageId cannot be empty", nameof(attachments));
|
||||
if(string.IsNullOrWhiteSpace(attachments.FilePath))
|
||||
throw new ArgumentException("File path cannot be empty", nameof(attachments));
|
||||
if(string.IsNullOrWhiteSpace(attachments.EncryptedKey))
|
||||
throw new ArgumentException("Encrypted key cannot be empty", nameof(attachments));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidObjectException<MediaAttachments>(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool TryValidate(MediaAttachments attachments)
|
||||
{
|
||||
try
|
||||
{
|
||||
Validate(attachments);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,18 @@ public class MediaAttachments
|
||||
|
||||
public string? EncryptedKey { get; set; }
|
||||
public Message Message { get; set; } = null!;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is not MediaAttachments other) return false;
|
||||
|
||||
return Id == other.Id &&
|
||||
MessageId == other.MessageId &&
|
||||
EncryptedKey == other.EncryptedKey &&
|
||||
Type == other.Type &&
|
||||
FilePath == other.FilePath &&
|
||||
MimeType == other.MimeType;
|
||||
}
|
||||
}
|
||||
|
||||
public enum MediaType
|
||||
|
||||
Reference in New Issue
Block a user