-
Notifications
You must be signed in to change notification settings - Fork 82
Test Driven Development Yes! This library supports it!
Pure Krome edited this page Jul 17, 2013
·
3 revisions
Yes! This library supports test driven development - because everyone knows that we all should be doing TDD with all our .NET applications.
A common scenario of this would be to test your ASP.NET MVC controller methods or your NancyFX modules.
There are two ways you can use this library while you practice TDD.
- Simple 99% 'ers - Use the Fake providers.
- Hardcore 1% 'ers - Mock out the
IRestClient
and setup the Methods you wish to mock.
// Arrange.
var authenticationService = new AuthenticationService();
authenticationService.AddProvider(new FakeFacebookProvider(
new Uri("http://localhost:1338/home/AuthenticateCallback?providerKey=facebook"));
var homeController = new HomeController(authenticationService);
// Act.
var result = homeController.AuthenticateCallback("facebook");
// Assert.
Assert.NotNull(result);
// .. etc..
or an error occurs, like the user doesn't accept the providers accept policy.
// Arrange.
var authenticationService = new AuthenticationService();
var facebookProvider =
new FakeFacebookProvider(new Uri("http://localhost:1338/home/AuthenticateCallbackThatErrors?providerKey=facebook"))
{
AuthenticateCallbackExceptionMessage =
"ZOMG! Something nasty has occured! ID10T Error!1!1!1. -le sad panda-"
};
authenticationService.AddProvider(facebookProvider);
var homeController = new HomeController(authenticationService);
// Act.
var result = Assert.Throws<AuthenticationException>( () => homeController.AuthenticateCallback("facebook"));
// Assert.
Assert.NotNull(result);
// .. etc..
This is a lot more complex, but gives you finer granular control of various success/failing scenarios. Please look at the extensive unit tests for examples about how this is achieved.
- NancyFX Manual Setup
- NancyFX Automatic Setup
- MVC Manual Setup
- MVC Automatic Setup
- web.config
- global.asax
- bootstrapper