您好,我正在对我的ASP.Net MVC2项目进行一些单元测试。我使用Moq框架。在我的LogOnController中,
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl = "")
{
FormsAuthenticationService FormsService = new FormsAuthenticationService();
FormsService.SignIn(model.UserName, model.RememberMe);
}
在 FormAuthenticationService 类中,
public class FormsAuthenticationService : IFormsAuthenticationService
{
public virtual void SignIn(string userName, bool createPersistentCookie)
{
if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
}
public void SignOut()
{
FormsAuthentication.SignOut();
}
}
我的问题是如何避免执行 ""。
FormsService.SignIn(model.UserName, model.RememberMe);
我需要翻译的是这行文字。或者有没有一种方法可以使用Moq进行测试?
FormsService.SignIn(model.UserName, model.RememberMe);
使用Moq框架,在不改变我的ASP.Net MVC2项目的情况下。