I am looking for guidance on setting up the synchronization context for a complex integration test where the SUT includes async ASP.NET actions.
I have a mock HttpContext and can exercise synchronous action methods. But async actions often fail with HttpContext.Current null. From reading around, I think I need to call SynchronizationContext.SetSynchronizationContext in order to get the HttpContext.Current to be "moved" from one thread to another as the async operations proceed.
I've tried:
- A simple TestSynchronizationContext similar to this - still fails with null HttpContext.Current
- Instantiate an AspNetSynchronizationContext using reflection - not managed yet as class and dependencies are internal which makes this really difficult
Any suggestions?