单元测试成员资格

发布于 2025-01-04 03:50:45 字数 2096 浏览 1 评论 0原文

我正在集成测试使用成员资格 API 的 MVC 控制器。我在下面添加了我的 app.config 。测试尝试运行,但当它们调用 api 时,它们返回 null。我检查了 Membership 对象,它不包含我的连接字符串,它包含来自 machine.config 的默认连接字符串。它也不会获取我配置的应用程序名称。在我看来,我的 app.config 存在问题,以至于会员 api 无法获取其设置。

任何人都可以发现错误吗?

var usr = Membership.GetUser(AValidGuid);  This is always null!!!!


<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="membership" type="System.Web.Configuration.MembershipSection, System.Web" />
        <section name="roleManager" type="System.Web.Configuration.RoleManagerSection, System.Web" />
      </configSections>
      <connectionStrings>
        <add connectionString="server=;user id=;password=;database=" name="SqlProvider" />
      </connectionStrings>

      <membership defaultProvider="AspNetSqlMembershipProvider">
        <providers>
          <remove name="AspNetSqlMembershipProvider"></remove>
          <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SqlProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/test" />
        </providers>
      </membership>
      <roleManager enabled="true" defaultProvider="AspNetSqlProvider">
        <providers>
          <remove name="AspNetSqlRoleProvider"></remove>
          <add connectionStringName="SqlProvider" applicationName="/test" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </providers>
      </roleManager>
</configuration>

I'm integration testing an MVC controller that uses the membership API. I've added my app.config below. The tests attempt to run, but when they make a call to the api, they return null. I inspect the Membership object, and it doesn't contain my connection string, it contains the default one that comes from the machine.config. It also does not pick up my configured application name. It seems to me that I have an issue with my app.config to the point where the membership api is not picking up its settings.

Can anyone spot the error?

var usr = Membership.GetUser(AValidGuid);  This is always null!!!!


<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="membership" type="System.Web.Configuration.MembershipSection, System.Web" />
        <section name="roleManager" type="System.Web.Configuration.RoleManagerSection, System.Web" />
      </configSections>
      <connectionStrings>
        <add connectionString="server=;user id=;password=;database=" name="SqlProvider" />
      </connectionStrings>

      <membership defaultProvider="AspNetSqlMembershipProvider">
        <providers>
          <remove name="AspNetSqlMembershipProvider"></remove>
          <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SqlProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/test" />
        </providers>
      </membership>
      <roleManager enabled="true" defaultProvider="AspNetSqlProvider">
        <providers>
          <remove name="AspNetSqlRoleProvider"></remove>
          <add connectionStringName="SqlProvider" applicationName="/test" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </providers>
      </roleManager>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2025-01-11 03:50:45

您的 app.config 将需要针对执行测试的应用程序进行更新。这是发布的 app.config 所适用的吗?我知道这是一个基本的事情,但很多人都对测试运行程序正在使用哪个配置感到困惑。

Your app.config will need to be updated for the application executing the test. Is that what the posted app.config applies to? I know that's a basic thing but a lot of people get hung up on which config is being utilized by the test runner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文