我有一個程序是這樣的:單元測試和會話?
public bool IsValidEmployee(string email, string password)
{
bool valid = false;
var employee = dataAccess.GetEmployee(email, password);
if(employee! = null)
{
valid = true;
HttpContext.Current.Session["Employee"] = employee;
}
return valid;
}
我的單元測試:
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\Projects", "/")]
[UrlToTest("http://localhost:59349/")]
public void GetEmployeeTest()
{
Domain target = new Domain();
var mockHttpContext = new Mock<HttpContextBase>();
mockHttpContext.SetupSet(c => c.Session["Employee"] = It.IsAny<object>());
Assert.IsTrue(target.IsValidEmployee("[email protected]", "test");
}
的代碼失敗作爲
對象空引用「HttpContext.Current.Session [ 「員工」] =員工;'
任何建議如何我可以解決這個錯誤?