我已经使用依赖注入模式实现了名为DefaultController的mvc基本控制器,以便能够构建测试用例.示例如下:
public class DefaultController : Controller { protected readonly ISessionHelper _sessionHelper; string _thisUserOpenID; protected IUsersRepository _UserRepository; ... public DefaultController() { } //not for testing public DefaultController(ISessionHelper session,IUserRepository repo) { _sessionHelper=session; _UserRepository = repo; } }
然后我使用这个控制器,homecontroller,usercontroller等我的控制器.
现在,构建一些测试用例我发现自己处于一种我不知道如何实际使用注入依赖模式的情况.
[TestMethod] public void Welcome_Message_In_ViewData_Has_Coockie_User_Display_Name() { // Below I want to insert FakeRepositories using //ISessionHelper and so on. but the constructor //for homecontroller don't have it. HomeController controller = new HomeController();
有任何想法吗?