3.9.3. Middleware Setup

Step by Step instructions

Implement your own SubscriptionStorageProvider

FakeXrmEasy automatically retrieves information about the current user using FakeXrmEasy, and will validate your subscription for you, however you’ll need to implement a SubscriptionStorageProvider interface that you’ll use to decide where the information about these users is stored / read from.

If you want to try and use Blob Storage, then there is an implementation already done in the next section: Tutorial - Blob Storage Implementation.

The SubscriptionStorageProvider interface basically needs to implement two methods:

  • Read: FakeXrmEasy will be reading from that storage, so when reading for the first time, you’ll need to provide a null response so that FakeXrmEasy will initialize it for you.
  • Write: FakeXrmEasy will be calling this method to store information about your users in your preferred location.

These two methods are means of serialising (Write) and deserialising (Read) the Subscription usage data.

Add your SubscriptionStorageProvider to the Middleware

Once you have your SubscriptionStorageProvider, you need to tell FakeXrmEasy it exists and to use it. This is done in the middleware configuration.

Please make sure to call this method after the .SetLicense and before the .Build methods.

public class FakeXrmEasyCommercialLicenseTestsBase
    protected readonly IXrmFakedContext _context;
    protected readonly IOrganizationService _service;

    public FakeXrmEasyCommercialLicenseTestsBase()
        _context = MiddlewareBuilder




                    // Your provider goes here ...
                    .SetSubscriptionStorageProvider(new SubscriptionBlobStorageProvider())

        _service = _context.GetOrganizationService();