views:

288

answers:

1

I need to unit test this method. I'm using moq as my mocking framework, if that helps.

[AcceptVerbs(HttpVerbs.Get)]
public RedirectToRouteResult LogOff()
{
    FormsAuthentication.SignOut();
    return RedirectToAction("Index", "Post");
}

cheers :)

EDIT: It was mainly the FormsAuthentication i was wondering. Should I even be testing that? I suppose i would need to mock up an Identity and then check the IsAuthenticated is false?

+2  A: 

you could create a wrapper for FormsAuthentication and stub it out

formsAuthentication = mockery.Stub<IFormsAuthentication>();

and do something like this.

With.Mocks(mockery)
    .Expecting(() => Expect.Call(() => formsAuthentication.SignOut()))
    .Verify(() => controller.LogOff());

 /* Asserts to go here */

In terms of testing the FormsAuthentication. Test this somewhere else, separation of concerns and all that.

The test for this action merely needs to check that the SignOut method has been called and if the redirect has happened. Remember you are testing the action, not the methods within the action. You wouldn't test the data store work in a Submit action, you'd mock all that out.

John Polling
so...should have said that is done with Rhino Mocks.....but the principle is just the same
John Polling
damn. i just can't figure out how to do this with MOQ :(
Pure.Krome
sorry can't help you there as I've no experience with MOQ at all.
John Polling