リファレンスthis questionと投票しますがマークされていない、具体的this answerにあります。コントローラを単体テストする必要があるので、私はマークされた答えが嫌いです。これは、HttpRequestとHttpResponseを必要とするAPIでのユニットテストの推奨方法ですか?
Application_BeginRequest中にこれらをHttpRequestとHttpResponseに入れるのは少し匂いがありますが、私はComponentSpace SAML 2 libraryを扱い、メソッドの引数としてこれらの型をとります。 MVCでユニットテスト可能な方法でこれらにアクセスする良い方法はありますか?ここで
は、私は今で働いているものです。キャストと魔法の文字列をカプセル化するために、拡張メソッドに出.Itemsをリファクタリングが、これは主なアイデアである可能性があります
のGlobal.asax:サービスメソッドで
protected void Application_BeginRequest()
{
// put the raw request in context items for use by ComponentSpace SAML lib
Context.Items["HttpRequest"] = Context.Request;
Context.Items["HttpResponse"] = Context.Response;
}
:
// HttpContext is an instance of HttpContextBase
ServiceProvider.SendAuthnRequestByHTTPPost(
HttpContext.Items["HttpResponse"] as HttpResponse,
authnRequest.Destination, authnRequestXml, relayState);
ServiceProvider.ReceiveSAMLResponseByHTTPPost(
HttpContext.Items["HttpRequest"] as HttpRequest,
out samlResponseXml, out relayState);
_Iを行うことによって影響を与え得ることができますが起動しない理由answer_マークそのスレッドの賞金? –
@ sh4nx0r、この方法は安かった。 – danludwig