1
我想測試一個使用DotNetOpenAuth的AccountController,但我遇到了問題。我想測試Logon ActionResult以查看它是否返回了正確的視圖。測試失敗,因爲領域(我認爲)有一個合同,要求HttpContext.Current不爲null。我想我必須以某種方式嘲笑這個請求,但我不知道我該怎麼做。測試/模擬DotNetOpenAuth控制器
這是ActionResult代碼。它直接來自DotNetOpenAuth示例。
[AcceptVerbs(HttpVerbs.Post), ValidateAntiForgeryToken]
public ActionResult LogOn(string openid_identifier,
bool rememberMe,
string returnUrl)
{
Identifier userSuppliedIdentifier;
if (Identifier.TryParse(openid_identifier, out userSuppliedIdentifier))
{
try
{
var request = this.RelyingParty
.CreateRequest(openid_identifier,
Realm.AutoDetect,
Url.ActionFull("LogOnReturnTo"));
if (!string.IsNullOrEmpty(returnUrl))
{
request.SetUntrustedCallbackArgument("returnUrl", returnUrl);
}
return request.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{
ModelState.AddModelError("OpenID", ex.Message);
}
}
else
{
ModelState.AddModelError("openid_identifier",
"This doesn't look like a valid OpenID.");
}
return RedirectToAction("LogOn", "Account");
}
由於提前,
Pickels