May012008

How to Unit Test a Custom Membership Provider

Published by Guillermo at 6:30 PM under Development

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.



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: , , ,

E-mail | Permalink | Trackback | Post RSSRSS comment feed 0 Responses

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview


Response by on 1/7/2009 7:07:03 AM