1

I have an n-tier MVC app with an MVC5 frontend, and a WebAPI2 backend.

I am normally calling between the two using RestSharp

For testing/development purposes (primarily to be able to use glimpse or other profiling tools end-to-end) I want to be able to easily flip a switch to use the application in a single tier mode.

I could manually make calls to the appropriate WebAPI controller classes and methods, but that would be a lot of duplication of logic.

Since I already have URLs built up with all of the parameters correctly set, is there a way to call the controller (or some factory that can pick between controllers) and say "Hey, pretend this just came in over the wire and process it for me"

Jason Coyne
  • 6,509
  • 8
  • 40
  • 70
  • OWIN self host is what I use for my Web API unit testing. – tia May 29 '15 at 15:51
  • that would still send things out of process over http wouldn't it? – Jason Coyne May 29 '15 at 16:05
  • Based on how URL routing works in WebAPI, I don't believe this is either too feasible or too advisable. It's self-defeating at that point. If you just want to test the method signatures and you've managed to stay decoupled from HttpContext (or can mock it), perhaps you're better off invoking the controllers directly from your test code. Else, send it across the wire. That's the only true way to guarantee successful integration. – David L May 29 '15 at 16:11