I need to mock the WebOperationContext and specifically the IncomingRequest with a header that assigns the Accept value, as to test that the value is being read properly and the OutgoingReponse.ContentType matches that the desired format. I'm using WCFMock and all was well with the general testing, but I can't get my head around what I need to do to mock the Incoming Response.
The Accept property is readonly so assigning is directly can't happen. I've tried adding the setter to WCFMock.IncomingWebRequestContextWrapper which predictably bombs since it's inheriting from System.SericeModel.Web.IncomingWebRequestContext.
So something like this would be desired
[Test]
public void SerializeObjectToXMLTest()
{
var fake = new FakeRest();
var mockContext = new Mock<IWebOperationContext> { DefaultValue = DefaultValue.Mock };
using (new MockedWebOperationContext(mockContext.Object))
{
// WHAT I WOULD LOVE:
MockedWebOperationContext.Current.IncomingRequest.Accept = "application/json";
fake.SetResponseContentType();
}
// Assert
mockContext.VerifySet(c => c.OutgoingResponse.ContentType, "application/json");
}
I'm afraid I have to totally mock a WebRequest and I'm looking to avoid that if possible.