I'm using a wrapper for HttpClient to be able to emulate http responses. I'm having a problem with those who are sending anonymous types.
This is the setup response for my HttpClient class wrapper:
var x = new {category = 1, products = "1"};
Func<HttpRequestMessage, HttpResponseMessage> functionResponse;
functionResponse = request =>
request.CreateResponse(code, responseValue, _httpConfig);
_client.PostAsJsonAsync(
Arg.Is<string>(x => x.Contains(URL)),
Arg.Is<T>(x => x.ToJsonStringSafe() == postValue.ToJsonStringSafe())
).Returns(
System.Threading.Tasks.Task.Factory.StartNew(() =>
functionResponse(_message)));
This is piece of code in the target method doing the httpClient call:
var response =
await _httpClient.PostAsJsonAsync(
_serviceUrl + "/productbyid",
new {category = _category, products = _products});
At this point, response
is null, but should be a Task with responseValue
set.
This configuration is working for anything but anonymous types.
*I verified the match of URL, category and _products on debug time.