im trying unit-test custom apicontroller. in custom controller override initialize method evaluate authorization-header.
so problem is, there 2 request-headers available.
protected override void initialize(httpcontrollercontext controllercontext) { base.initialize(controllercontext); // headers 1 var headersone = controllercontext.request.headers; // headers 2 var headerstwo = httpcontext.current.request.headers; } but not problem itself. problem is, headers don't match. productive operating: have authorization-header. , have apply authorization-header test-scenario.
at moment apply authorization-header controllercontext:
var fakecontrollercontext = new httpcontrollercontext { request = new httprequestmessage { requesturi = new uri("http://localhost/api/test"), headers = { { "authorization", "fake authorization-header"} } } }; but said. header later not available in httpcontext.current.request.headers. can please me out? unfortunately don't understand context fulfills purpose.
what found out httpcontext.current old implementation should not used anymore. because can not take control on it's content unit-test it.
httpcontrollercontext newer implementation. , it's content exchangable. submitted controllercontext method initialize available in controllercontext-property. should use this.
found here in first answer: testing web api method uses httpcontext.current.request.files? to: martin liversage
Comments
Post a Comment