繁体   English   中英

如何TDD自定义成员资格提供程序和自定义成员资格用户?

[英]How do I TDD a custom membership provider and custom membership user?

我需要为ASP.NET mvc应用程序创建自定义成员资格用户和提供程序,我希望使用TDD。 我创建了一个继承自MembershipUser类的User类,但是当我尝试测试它时,我得到一个我无法弄清楚的错误。 如何为其提供有效的提供商名称? 我只需要将它添加到web.config吗? 但此时我甚至都没有测试网络应用程序。

[failure] UserTests.SetUp.UserShouldHaveMembershipUserProperties TestCase'UserTests.SetUp.UserShouldHaveMembershipUserProperties'失败:指定的成员资格提供程序名称无效。 参数名称:providerName System.ArgumentException消息:指定的成员资格提供程序名称无效。 参数名称:providerName源:System.Web

添加到单元测试项目配置文件的配置如下所示:

  <connectionStrings>
     <remove name="LocalSqlServer"/>
     <add name="LocalSqlServer" connectionString="<connection string>" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
     <membership defaultProvider="provider">
       <providers>
         <add name="provider" applicationName="MyApp" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" maxInvalidPasswordAttempts="3" passwordAttemptWindow="15"/>
       </providers>
     </membership>
  </system.web>

是的,您需要在配置文件中配置它(可能不是测试库的web.config,而是app.config)。 您仍然使用该部分并在该部分内进行配置。 一旦你有了这个,你将能够实例化你的用户并进行测试。 在这一点上,你可能会遇到新的问题,我认为你应该将这些问题作为单独的问题发布。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM