The code is in ASP.NET Core. MVC controller returns Json(someData). I am trying to retrieve the data in the Unit test. The best I can do is to have
string data = JsonConvert.SerializeObject(jsonResult.Value);
and then compare the string. But I would prefer to get an object or an array to be able to do some more specific comparisons. Interesting, under debugger I can see that jsonResult.Value
is of type Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<MyType>
and there is even Results View that warns not to expand it or else; and if I expand it, I get exactly what I want! In my case it is a 4-element array of MyType
objects. However, if I do something like from i in jsonResult.Value select i
I get an error
Could not find an implementation of the query pattern for source type 'object'.
'Select' not found
I hope there is a better way than comparing a JSON string!
Aucun commentaire:
Enregistrer un commentaire