Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to test custom membership provider

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.

like image 867
BobRock Avatar asked Apr 25 '12 11:04

BobRock


1 Answers

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>"
         ... />
like image 119
Xharze Avatar answered Oct 16 '22 01:10

Xharze