20
mam kod w kontrolerze, który zużywa HttpContext
Jak Mock HttpContext.User.Identity.Name w ASP.NET MVC 4
public ActionResult Index()
{
var currentUser=HttpContext.User.Identity.Name;
......
}
Starając się pisać testu przy użyciu NUnit jak ten
[Test]
public void CanDisplayRequest()
{
//Act
var result= (ViewResult)_requestController.Index();
//Assert
Assert.IsInstanceOf<OrderRequest>(resut.Model);
}
test nie powiedzie się, ponieważ nie można znaleźć HttpContext
Więc jak mogę kpić HttpContext.Current.User.Identity.Name
Używam Moq dla wyśmianie
Czy macie również fragment o robi to samo, ale używa Microsft podróbki/test i nie ma żadnej innej struktury testowania stron trzecich? –