Hola, estoy haciendo algunas pruebas de unidad en mi proyecto ASP.Net MVC2. Estoy usando el framework Moq. En mi LogOnController,FormsAuthentication.SetAuthCookie burlando usando Moq
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl = "")
{
FormsAuthenticationService FormsService = new FormsAuthenticationService();
FormsService.SignIn(model.UserName, model.RememberMe);
}
En la clase 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();
}
}
Mi problema es cómo puedo evitar la ejecución de
FormsService.SignIn(model.UserName, model.RememberMe);
esta línea. O ¿hay alguna manera de MOQ
FormsService.SignIn(model.UserName, model.RememberMe);
usando marco Moq sin cambiar mi proyecto ASP.Net MVC2.
¿Qué es el SUT (Sistema bajo prueba) - 'LogOnController' o' FormsAuthenticationService'? Si es el primero, se debe suministrar un falso para el 'FormsAuthenticationService' y usted debe verificar que se llame al método' SignIn'. Este último es más difícil de probar por unidad, ya que requiere un 'HttpContext' actual al cual agregar una cookie (al' HttpResponse'). –
Quiero probar LogOnController. Traté de burlar FormsService.SignIn (model.UserName, model.RememberMe); de esta manera, var formService = new Mock(); Pero formservice.SignIn no devuelve nada. ¿Cómo puedo evitar ejecutar esa línea o cómo burlar esa línea? No tengo idea de cómo simular eso usando Moq. –
Dilma