我正在使用FakeHttpContext dll,在我执行数据库查询之前,一切正常,并且它向我发送了连接参数错误。 这是我的单元测试。
[DataTestMethod]
[DataRow("supervisor1@xxx.com.mx", "s123")]
public void VerfyMethod(string email, string pwd)
{
EkoContext db = new EkoContext();
List<Consultores> LstUsers = new List<Consultores>();
LogIn login = new LogIn
{
usuario = email,
password = pwd
};
// Mock httpcontext = Mock<HttpContextBase>();
var a = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/Files/");
using (new FakeHttpContext.FakeHttpContext())
{
LstUsers = db.Consultores.Where(u => u.Correo == login.usuario && u.Password == login.password && u.IdStatus == 1).ToList();
var b = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/Files/");
var context = new Mock<ControllerContext>();
var session = new MockHttpSession();
context.Setup(u => u.HttpContext.Session).Returns(session);
var cnt = new HomeController2();
cnt.ControllerContext = context.Object;
session["usuario"] = "rmr";
ViewResult result = cnt.ViewLog(login) as ViewResult;
Assert.IsNotNull(result, "deberia retronar un valor no nulo");
}