The specified membership provider name is invalid. Parameter Name: providerName

  • .Net4.0
  • MVC 2
  • NHibernate
  • Nunit

I am trying to verify user creation. From my test, I call the following:

MembershipCreateStatus status; // _session is my current NHibernate session. var mmp = new MyMembershipProvider(_session); mmp.CreateUser(username, password, " something@example.com ", "", "", true, Guid.NewGuid(), out status); 

In the CreateUser method CreateUser he accomplishes this:

 var user = new MembershipUser(Name, username, providerUserKey, email, passwordQuestion, passwordAnswer, isApproved, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now); 

... before throwing this exception:

 The membership provider name specified is invalid. Parameter name: providerName 

I have my name set to MyMembershipProvider , and in Web.config I have the following:

 <add name="OnyxMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> 

And also my connection string:

 <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> 

Now I assume that the problem is that my tests create SQLite DB and web.Config is trying to hit my SqlServer DB, but I'm not sure how to do it.

+6
c # nunit nhibernate asp.net-membership
source share
2 answers

Should the name be the same as indicated in the web.config file?

i.e. OnyxMembershipProvider

+8
source share

You might want to consider the mockery of a membership provider. Your unit tests should test your code, not Microsoft.

Here is some information about using Moq to extract a membership provider:

What am I doing wrong this time with Moq?

+1
source share

All Articles