diff --git a/src/FakeXrmEasy.Core/FileStorage/Db/FileAttachment.cs b/src/FakeXrmEasy.Core/FileStorage/Db/FileAttachment.cs index bf0c27e0..16e6c92d 100644 --- a/src/FakeXrmEasy.Core/FileStorage/Db/FileAttachment.cs +++ b/src/FakeXrmEasy.Core/FileStorage/Db/FileAttachment.cs @@ -4,15 +4,38 @@ namespace FakeXrmEasy.Core.FileStorage.Db { /// - /// Contains information about the file contents and file metadata associated to an existing record (Target) and field (AttributeName) + /// Represents a file associated to an existing Dataverse record. /// public class FileAttachment: IFileAttachment { + /// + /// The unique identifier of the file to be uploaded(i.e. the Guid of the fileattachment record) + /// public string Id { get; set; } + + /// + /// The file name, including the file extension + /// public string FileName { get; set; } + + /// + /// The file MIME type + /// public string MimeType { get; set; } + + /// + /// The actual file contents as a byte array + /// public byte[] Content { get; set; } + + /// + /// The associated record to which this file belongs + /// public EntityReference Target { get; set; } + + /// + /// The logical name of the File or Image column / field of the Target EntityReference + /// public string AttributeName { get; set; } } } \ No newline at end of file diff --git a/src/FakeXrmEasy.Core/FileStorage/Db/InMemoryFileDb.cs b/src/FakeXrmEasy.Core/FileStorage/Db/InMemoryFileDb.cs index d1c8d271..52a63042 100644 --- a/src/FakeXrmEasy.Core/FileStorage/Db/InMemoryFileDb.cs +++ b/src/FakeXrmEasy.Core/FileStorage/Db/InMemoryFileDb.cs @@ -127,7 +127,6 @@ public List GetFilesForTarget(EntityReference target) (f => f.Target.LogicalName.Equals(target.LogicalName) && f.Target.Id.Equals(target.Id)) - .Select(f => f as IFileAttachment) .ToList(); } @@ -303,22 +302,19 @@ private void ValidateMaxFileSize(FileUploadSession fileUploadSession, FileAttach return; } - if (attributeMetadata is FileAttributeMetadata fileAttributeMetadata) + if (attributeMetadata is FileAttributeMetadata fileAttributeMetadata + && (decimal) fileAttachment.Content.Length / 1024 > fileAttributeMetadata.MaxSizeInKB) { - if ((decimal) fileAttachment.Content.Length / 1024 > fileAttributeMetadata.MaxSizeInKB) - { - throw new MaxSizeExceededException(tableLogicalName, fileUploadSession.Properties.FileAttributeName, - fileAttributeMetadata.MaxSizeInKB.Value); - } + throw new MaxSizeExceededException(tableLogicalName, fileUploadSession.Properties.FileAttributeName, + fileAttributeMetadata.MaxSizeInKB.Value); } - if (attributeMetadata is ImageAttributeMetadata imageAttributeMetadata) + if (attributeMetadata is ImageAttributeMetadata imageAttributeMetadata && + (decimal) fileAttachment.Content.Length / 1024 > imageAttributeMetadata.MaxSizeInKB) { - if ((decimal) fileAttachment.Content.Length / 1024 > imageAttributeMetadata.MaxSizeInKB) - { - throw new MaxSizeExceededException(tableLogicalName, fileUploadSession.Properties.FileAttributeName, - imageAttributeMetadata.MaxSizeInKB.Value); - } + + throw new MaxSizeExceededException(tableLogicalName, fileUploadSession.Properties.FileAttributeName, + imageAttributeMetadata.MaxSizeInKB.Value); } }