Reputation: 11
I'm working on MVC4 application and interested in creating a set of controller unit tests. All my attempts to unit test methods from AccountController end up with the same exception related to WebMatrix.WebData.WebSecurity:
To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".
I'm using SimpleMemebership
provider that is being initialized through InitializeSimpleMembershipAttribute
Can someone provide guidance how to do this properly?
Upvotes: 1
Views: 1397
Reputation: 14982
I'll drop it as answer since this will become painfully ugly in a comment. What I did, is add a membershipprovider in my test project. I have a custom membership provider, but in your case the app.config would look something like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<clear/>
<add name="SimpleMembershipProvider"
type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
</system.web>
</configuration>
You probably get complaints about a missing reference of WebMatrix. Add the following references:
Set copy to local to true
.
Then make sure you call the WebSecurity.InitializeDatabaseConnection
and you're good to go.
Hope this helps.
Upvotes: 1