我正在尝试测试我的自定义成员资格提供程序,因为它描述为here
在测试时,我有System.TypeLoadException:
Could not load type 'Domain.WebProviders' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral....,
这是我的代码 的 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 = "jamesbond@mi6.uk";
// 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>
使用
更新了App.config行<add name="CustomMembershipProvider"
type="Domain.WebProviders.CustomMembershipProvider, "Domain.WebProviders"
现在我报告的例外是
System.IO.FileNotFoundException : Could not load file or assembly 'Domain.WebProviders' or one of its dependencies
引用了Domain.WebProviders,非常困惑。
答案 0 :(得分:8)
我可能是因为您的会员资格部分没有定义程序集名称。
<add name="CustomMembershipProvider"
type="Domain.WebProviders.CustomMembershipProvider"
... />
尝试将其更改为:
<add name="CustomMembershipProvider"
type="Domain.WebProviders.CustomMembershipProvider, <assemblyname>"
... />