问题描述
我需要创建一个自定义成员资格的用户和供应商的ASP.NET MVC应用程序,我期待使用TDD。我创建了一个用户类,从类的MembershipUser继承,但是当我尝试测试它,我得到了我想不通一个错误。我怎么给它一个有效的供应商的名字吗?我只是需要将其添加到web.config文件?但是我还没有在这一点上测试Web应用程序。
I need to create a custom membership user and provider for an ASP.NET mvc app and I'm looking to use TDD. I have created a User class which inherits from the MembershipUser class, but when I try to test it I get an error that I can't figure out. How do I give it a valid provider name? Do I just need to add it to web.config? But I'm not even testing the web app at this point.
[失效] UserTests.SetUp.UserShouldHaveMembershipUserProperties
TestCase的UserTests.SetUp.UserShouldHaveMembershipUserProperties
失败:指定的成员资格提供程序名称无效。
参数名:的providerName
System.ArgumentException
消息:指定的成员资格提供程序名称无效。
参数名:的providerName
来源:System.Web程序
[failure] UserTests.SetUp.UserShouldHaveMembershipUserPropertiesTestCase 'UserTests.SetUp.UserShouldHaveMembershipUserProperties'failed: The membership provider name specified is invalid.Parameter name: providerName System.ArgumentException Message: The membership provider name specified is invalid. Parameter name: providerName Source: System.Web
推荐答案
添加到您的单元测试项目的配置文件看起来像这样的配置:
The configuration to add to your unit test project configuration file would look something like this:
<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>
这篇关于我如何TDD的一个自定义的成员资格提供程序和自定义成员资格用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!