views:

44

answers:

1
  • .Net4.0
  • MVC 2
  • NHibernate
  • NUnit

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.

+1  A: 

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:

http://stackoverflow.com/questions/1054871/what-am-i-doing-wrong-this-time-with-moq

Dave Swersky
Slight problem... I'm using WatiN, so I don't have access to the controller directly. I don't think I can mock like that, can I?
Matt Grande