Backdoors

Subscribing to backdoors in the app

Within an iOS app, the UIViewController.GetBackdoor() extension method gets a backdoor for any view controller:

// Get a backdoor for any UIViewController:
var backdoor = viewController.GetBackdoor();
// Subscribe to backdoor messages:
backdoor.On("event", message => {
  Console.WriteLine("Received backdoor message: " + message);
});

The backdoor is an invisible view added to the view hierarchy, so beware that resetting your root view or removing its children can discard the backdoor.

Calling backdoors from tests

The current backdoor is invoked with simply:

Backdoor.Invoke("event", "some value");

Multiple Simultaneous Backdoors

The first example assumes that only one backdoor is on screen at a time; if you have multiple backdoors and are worried about conflicts, you can specify an optional id.

In your app:

var backdoor = viewController.GetBackdoor("photoBackdoor");
backdoor.On("setPhoto", SetPhotoFromUrl);

In your test:

var photoBackdoor = Backdoor["photoBackdoor"];
photoBackdoor.Invoke("setPhoto", "htt://imgur.co/9898dw");