In my xUnit test case I am reading JSON from a file, loading it in string and passing it a function that is originally called by controller.
My controller is:
[HttpPost]
public List<SomeCls> Post([FromBody] object ds)
{
var result = Myservice.DoSomething(ds);
}
This controller API works fine, I tested by posting raw json via Postman. However, in my unit test when I read JSON from a file and pass it into Myservice.DoSomething(ds)
, I get error:
---- System.ArgumentException : Could not cast or convert from System.String to System.Collections.Generic.List`1[MyDataSet].
In my xUnit test, how to convert JSON string into an object similar to the one that gets passed into the controller method by POST request?