2013-03-22 34 views
1

我建立方法,返回ProfileBase.Create:.NET自定义配置文件提供方法

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: This method cannot be called during the application's pre-start initialization phase.

PS 这里测试的代码:

_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)); 

回答

1

固定的,我只是BR消除ProfileBase和我的类之间的依赖关系。

相关问题