How to Unit Test a Custom Membership Provider

by Guillermo 1. May 2008 18:30

For my current project, I am implementing WCF services that need to be able to authenticate the caller and since the caller is coming from the public network (but from known sources), using a custom username and password validation was determined to be the correct mechanism.

As part of this implementation, I needed to create a Custom Membership Provider and in doing so I of course had to have Unit Tests for it.  Once the tests were written, I got a little surprise when I tried to run them as I got this exception:

System.ArgumentException: The membership provider name specified is invalid.

Needless to say this is an oversight on my part as it is clear that the providers need to be initialized.  To do this as part of your unit tests project you will need to configure your providers as you would on your ASP.NET application, or as in this case your WCF service host.

   1: <system.web>
   2: <membership defaultProvider="MyCustomMembershipProvider">
   3:   <providers>
   4:     <remove name="AspNetSqlMembershipProvider"/>
   5:     <add  name="MyCustomMembershipProvider" 
   6:           type="GFST.ProjectName.Providers.MyCustomMembershipProvider, GFST.ProjectName.Providers" />
   7:   </providers>
   8: </membership>
   9: </system.web>

You can then execute unit tests against your Custom Membership provider.

Tags: , , ,

Development

Powered by BlogEngine.NET 1.5.0.7
Theme by Extensive SEO

About the author

Something about the author

Your Most Recent Comments

Comment RSS

Page List