One of our Sitecore solutions is heavily based on dynamic user flows (we call them wizards) that consist of multiple pages which several restrictions each. One of those wizards is meant to activate gift cards.

In short: You need to login with a unique number and a PIN code before you can start the activation process. As soon as you login, there is a context available that contains some information about the card to be activated. This information is then used to personalize the users' experience, e.g. by outputting their product image or personlizing the texts based on the gift type. Long story short: without any context, the entire process is without any use.

Now, for normal users the solution is simple: don't let them access any of the wizard pages without an active context. For content editors, however, it's a completely different story: You want them to access all of the pages so that they can edit them. And moreover, they should be able to edit those pages without the need to log into the process before hands. Also, you don't want to bother them with broken components. So you'll need to provide them with an alternative.

The solution is indeed very simple: Use mock data.

You can either switch out the implementation of the context provider in the DI container of your choice, which I decided against to make the usage of mocks as obvious as possible. Or you can check for the page mode inside the controller and set the context information accordingly by either fetching from context provider or creating a new instance of the mock data:

private readonly ActivatableInformation _activatableInformation;

public SomeComponentController(ActivationContext activationContext) {
    _activatableInformation = Context.PageMode.IsNormal ? activationContext.ActivatableInformation : ActivatableInformationMock.Create();
}

The ActivatableInformationMock is a simple static class whose Create method will return an instance of the data object that should be mocked (in this case ActivatableInformation).

public static class ActivatableInformationMock {

    public static ActivatableInformation Create() {
        return new ActivatableInformation() {
            Product = Product.MGL,
            Type = ActivatableType.Voucher,
            Number = "987654321012",
            // ...
        };
    }

}