I am facing issue in reading consents using Content.ReadAsAsync
.
Have a look at my code.
private HttpResponseMessage _responseMessage;
_responseMessage = UnitTestHelper.Get(string.Format("api/StudentController/Get/?StartDate={0}&EndDate={1}", DateTime.Now, DateTime.Now));
Assert.IsTrue(_responseMessage.IsSuccessStatusCode);
Assert.IsTrue(_responseMessage.Content.ReadAsAsync<List<StudentModel>>().Result.Count > 0);
var auditData = _responseMessage.Content.ReadAsStringAsync().Result;
_responseMessage.Content.ReadAsAsync<List<StudentModel>>().Result;
Outcome of above code:
It successfully make post call, gets the result back.
Result.Count shows 1.
ReadAsStringAsync shows data in the following format.
[{\"User\":\"Test\",\"Location\":\"MyCountry\",\"Class\":\"Grade1\",\"Time\":\"2016-07-06T07:26:11.183\",\"SchoolName\":\"ABC School System\"}]
Last line gives null. I am expecting a list here.
My Problem.
The following line of code always shows null. Whereas I am expecting to have list.
_responseMessage.Content.ReadAsAsync<List<StudentModel>>().Result;
Why? What is wrong here?