I'm using the WCFMock to mock the WebOperationContext in my web service. The only usage is to add a custom HTTP header to the WebOperationContext.Current.OutgoingResponse.Headers collection. I'm unable to verify this using Moq. What I've already tried:
How can I verify in my unit test case that a custom header has been added?
Figured it out. Here's the solution for posterity.
When we create the "moq mock" for the IWebOperationContext, the example suggests that we set the property DefaultValue = DefaultValue.Mock
. This will mock all dependincies including the HttpHeaders collection. I skipped this and mocked the OutgoingWebResponseContext
to return a WebHeaderCollection
. For my test case I simply assert on this collection.