1

I created a custom RoleProvider in a custom library. I would like to unit test it. Via Moq I created a fake HttpContextBase. How to pass this to the to be tested RoleProvider?

The Identity is a custom test implementation class. This works fine. I only don't know how to pass in the fake context in my provider. This is not an MVC application but standard Webforms if that's information needed.

Grz, Kris.

Community
  • 1
  • 1
Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61

1 Answers1

1

You could use Dependency Injection (DI) and pass it through your custom RoleProvider's constructor.

public MyRoleProvider(HttpContextBase httpContext)
{
    // ...
}

This would allow you to pass the Moq instance via the constructor.

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736