I'm trying to test my custom membership provider as it was described here
On testing I have System.TypeLoadException:
Could not load type 'Domain.WebProviders' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral....,
Here is my code TestBase.cs
public class TestBase
{
protected string _username;
protected string _password;
protected string _email;
protected CustomMembershipProvider _provider;
protected NameValueCollection _config;
protected MembershipCreateStatus _status = new MembershipCreateStatus();
[SetUp]
public void initialize()
{
_username = "james";
_password = "bondjamesbond";
_email = "[email protected]";
// setup the membership provider
_provider = new CustomMembershipProvider ();
_config = new NameValueCollection();
_config.Add("applicationName", "My App");
_config.Add("name", "CustomMembershipProvider ");
_config.Add("requiresQuestionAndAnswer", "false");
_config.Add("connectionStringName", "ConnectionString");
_provider.Initialize(_config["name"], _config);
_status = new MembershipCreateStatus();
}, ...
MembershipTests.cs
[TestFixture]
class MembershipTests : TestBase
{
[Test]
public void CanUserBeCreated()
{
using (ISession open session ....)
{
using (ITransaction begin transaction ... )
{
_provider.CreateUser(_username, _password, _email, null, null, true, null, out _status);
tx.Commit();
}
Assert.AreEqual(MembershipCreateStatus.Success, _status);
}
}
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="...." />
</connectionStrings>
<system.web>
<!-- Membership provider -->
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear />
<add name="CustomMembershipProvider" type="Domain.WebProviders.CustomMembershipProvider"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<!-- Ends membership provider section-->
<!-- Role provider -->
<roleManager enabled="true" defaultProvider="MyRoleProvider">
<providers>
<clear />
<add applicationName="/"
name="MyRoleProvider"
type="Domain.WebProviders.MyRoleProvider" />
</providers>
</roleManager>
<!-- Ends role provider -->
</system.web>
</configuration>
Updated App.config line with
<add name="CustomMembershipProvider"
type="Domain.WebProviders.CustomMembershipProvider, "Domain.WebProviders"
Now my reported exception is
System.IO.FileNotFoundException : Could not load file or assembly 'Domain.WebProviders' or one of its dependencies
Domain.WebProviders is referenced, pretty confused.
I could be because you membership section don't define the assembly name.
<add name="CustomMembershipProvider"
type="Domain.WebProviders.CustomMembershipProvider"
... />
Try to change it to:
<add name="CustomMembershipProvider"
type="Domain.WebProviders.CustomMembershipProvider, <assemblyname>"
... />
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