I am writing integration test cases where I need to mock web service. I will have a dictionary that maps requests to fake responses. The IEqualityComparer<HttpRequestMessage>
is suitably overloaded to treat similar requests as same. To populate the dictionary, I am planning to store request messages in raw format in test files. Copying sample file content below:
POST https://example.com/api/users HTTP/1.1
Prefer: return=representation
Authorization: Bearer BearerToken
Content-Type: application/json; IEEE754Compatible=true
Host: example.com
Content-Length: 23
Expect: 100-continue
Accept-Encoding: gzip, deflate
{"fullname":"John Doe"}
Is it possible to translate the same into HttpRequestMessage
object? I do not want to use string
as key for dictionary since that would cause false alarms when request message does not significantly differ. Please note that I do not have an option to add a new NuGet package to the project.