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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user