I'm trying to test user creation. From my test, I'm calling the following:
MembershipCreateStatus status;
// _session is my current NHibernate session.
var mmp = new MyMembershipProvider(_session);
mmp.CreateUser(username, password, "[email protected]", "", "", true, Guid.NewGuid(), out status);
In the CreateUser
method, it gets this far:
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 the Web.config I have this:
<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'm guessing the the problem is that my tests are creating a SQLite DB, and the web.Config is trying to hit my SqlServer DB, but I'm not sure how to proceed.
Shouldn't the name be the same as that specified in the web.config?
i.e. OnyxMembershipProvider
You might want to consider mocking the membership provider. Your unit tests should be testing your code, not Microsoft's.
Here's some information on using Moq to mock out the membership provider:
What am I doing wrong this time with Moq?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With