I apologize if this a duplicate question (I didn’t find anything like that).
I’m trying to build an OpenId Authentication service and unit test it, currently I have the following setup:
public class OpenIdAuthenticationService : IAuthenticationService
{
private IConfigurationService _configService;
private OpenIdRelyingParty _openIdRelyingParty;
public OpenIdAuthenticationService(IConfigurationService configService)
{
_configService = configService;
_openIdRelyingParty = new OpenIdRelyingParty();
}
}
Apparently OpenIdRelyingParty requires access to HttpContext, is there a way to mock OpenIdRelyingParty and inject it the service ? Or maybe mock HttpContext and provide it to OpenIdRelyingParty somehow ?
To mock HttpContext for OpenIdRelyingParty you should modify the code of that class. Even you would waste some time mocking it due that it is a sealed class (but is not impossible you can use MOCKWCF).
I think that is better make a wrapper or adapter for OpenIdRelyingParty. like:
Then you will able to mock it as you want.