Skip to content

Feeling tricky? Use the Fake providers to avoid depending on the real 3rd Party Providers (for development purposes!)

PureKrome edited this page Nov 24, 2012 · 1 revision

So you're manually testing your website's authentication. Which means you will (at some point) have to hit Facebook, or Google or Twitter.

Blech :(

This is just development .. so why have that hard-dependency?

Yes, you can mock the providers .. but we've included some Fake Providers for you :) They are just a tiny InMemory provider that either pretends it worked ... or pretends it failed.

You define how you want to pretened it to work :)

Code talks - show me da code!

Look at where you register your providers, and replace it with this.

Simple 'happy path' with a fake successful authentication

var facebookProvider = new FakeFacebookProvider(new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=facebook"));

_authenticationService = new AuthenticationService();
_authenticationService.AddProvider(facebookProvider);

that's it!

OoOoOOoooO! Testing some error handling, eh?

var facebookProviderThatErrors =
    new FakeFacebookProvider(new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=facebook"))
    {
        AuthenticateClientExceptionMessage =
            "ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
    };

_authenticationServiceThatErrors = new AuthenticationService();
_authenticationServiceThatErrors.AddProvider(facebookProviderThatErrors);

and that's it, again!

So now .. you can easily forget about ever having to really hit Facebook or Google or Twitter for quick development.

Pew to the Pew!