我试图测试一个使用 DotNetOpenAuth 的 AccountController,但我遇到了问题。我想测试 Logon Actionresult 以查看它是否返回了正确的视图。测试失败是因为领域(我认为)有一个要求 HttpContext.Current 不为空的合同。我想我必须以某种方式模拟请求,但我不确定我应该如何做到这一点。
这是 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");
}
提前致谢,
泡菜