Note that there are some explanatory texts on larger screens.

plurals
  1. POWebAPI in memory testing - getting error serialize IQueryable
    text
    copied!<p>I have WebAPI implementation with method like this:</p> <pre><code> public IEnumerable&lt;Device&gt; GetAllDevices() public Device GetDeviceById(int id) </code></pre> <p>Looks ok, it works when running in IIS or selfhosted. Returns JSON objects correctly.</p> <p>However first method fails in my unit test where I attempt to use inmemory server.</p> <pre><code> System.InvalidOperationException : Cannot create and populate list type System.Linq.IQueryable`1[Test.Device]. </code></pre> <p>This goes down to Newtonsoft.Json.Serialization assembly. An example of the test follow:</p> <pre><code> [Test] public void GET_AskingForListOfDevices_GettingOk200WithListOfDevicesInJSON() { var client = new HttpClient(InMemoryServer); HttpRequestMessage request = CreateRequest("api/devices", "application/json", HttpMethod.Get); using (HttpResponseMessage response = client.SendAsync(request).Result) { Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.NotNull(response.Content); Assert.AreEqual("application/json", response.Content.Headers.ContentType.MediaType); // next line throws exc var content = response.Content.ReadAsAsync&lt;IQueryable&lt;Device&gt;&gt;().Result; Assert.AreEqual(3, content.Count()); } request.Dispose(); } </code></pre> <p>Any idea where to look?</p> <p>UPDATE<br> The example below throws that error, however I found the solution to avoid it. Just by using IList&lt;> instead of IQueryable&lt;>. Still It does not answer me the question why it's working in Fiddler. Does it use the same trick?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload