Overview

Overview of File Storage

Minimum Version: 2.6.0 / 3.6.0

FakeXrmEasy has a built-in In-Memory file storage mechanism. When you upload a file using some of the available messages, FakeXrmEasy will automatically process each block and store it as a binary In-Memory. FakeXrmEasy will also perform data validation like, allowed / blocked MIME or file types, file max size… and so on. These settings (allowed / blocked MIME types, max file size,…) use default values that you can override to fit your scenario.

Because files are referenced in File and Image columns, there is an intricate relationship between files, entity records, and entity metadata. For example, a file might be removed by updating a file column in an entity record to a null value.

Before diving into unit testing of files and images, please check the official Microsoft documentation to get an overview of how files and images work if you haven’t done so yet.

Default file storage settings

In Dataverse, some file and image settings are stored in column metadata, whereas other settings are stored in the Organization table / entity.

SettingLocation
Max sizeIn column metadata
Allowed / Blocked MIME typesOrganization entity (‘blockedmimetypes’ and ‘allowedmimetypes’ properties)
Blocked file extensionsOrganization entity (‘blockedattachments’ attribute)

Max Sizes

With FakeXrmEasy, if you don’t use fake entity metadata in your tests, then max sizes won’t be enforced in FakeXrmEasy when uploading files.

However if you do, then you can set the max size of a given column using fake entity metadata as follows:

var fileAttributeMetadata = new FileAttributeMetadata()
{
    LogicalName = "dv_file"
};
fileAttributeMetadata.MaxSizeInKB = 1; //1 KB

_entityMetadata = new EntityMetadata()
{
    LogicalName = dv_test.EntityLogicalName
};
_entityMetadata.SetAttributeCollection(new List<AttributeMetadata>()
{
    fileAttributeMetadata  
});

The above can be handy if you want to test a scenario of a particular file column with a specific file size. However, it might be tedious to do for every single file column when you have many.

That’s why FakeXrmEasy has a default max file and image size properties that you can override by calling .SetProperty(). If you don’t specify a specific file size for a given column in metadata, the default will be used.

There are different defaults for files and images:

SettingDescription
MaxSizeInKBThe default max size for files
ImageMaxSizeInKBThe default max size for images

You can set override these values as follows:


_context.SetProperty<IFileStorageSettings>(new FileStorageSettings()
{
    MaxSizeInKB = 1234,
    ImageMaxSizeInKB = 1234
});

If you do that before initializing metadata, the new settings will apply. If you generate fake entity metadata from an early bound assembly, these default values will also be used.

Uploading and Downloading

Uploading and downloading of files using the SDK is explained in this Microsoft documentation link. We’ve implemented these messages so they are transparent to you (i.e. FakeXrmEasy will execute these messages and store them in the In-Memory file storage database like if they were uploaded to a real instance).

Initialize with files

By default, the In-Memory file storage has no files, but similarly to entity records, you can also initialize the state of the In-Memory file database with a set of files. This is covered in the initialize files section.