【问题标题】:.NET Custom Profile Provider methods.NET 自定义配置文件提供程序方法
【发布时间】:2013-03-22 12:57:57
【问题描述】:

我构建返回 ProfileBase.Create 的方法:

public class ProfilesProvider : ProfileBase, IProfilesProvider
{
    public ProfilesProvider GetUserProfile()
    {
        return (HttpContext.Current.Profile) as ProfilesProvider;
    }

    public ProfilesProvider GetUserProfile(string userName)
    {
        if (String.IsNullOrEmpty(userName))
            return (HttpContext.Current.Profile) as ProfilesProvider;

        return Create(userName) as ProfilesProvider;
    }
}

这段代码运行良好,但是当我尝试为此方法创建单元测试时出现错误:

System.InvalidOperationException:在应用程序的预启动初始化阶段无法调用此方法。

附言 这里是测试的代码:

_mockProfiles.Setup(m => m.GetUserProfile()).Returns(new ProfilesProvider());
        var result = _controller.Settings(model);

        _mockProfiles.Verify(m => m.GetUserProfile(), Times.Once());
        Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

【问题讨论】:

    标签: c# .net profile


    【解决方案1】:

    已修复,我只是打破了 ProfileBase 和我的类之间的依赖关系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      相关资源
      最近更新 更多