I'm trying to create a test for some of our webapi calls, and I'm having difficulty accessing the results. In all the examples I looked at, they used OkNegotiatedContentResult. The problem is that in our web api calls we often rewind data into anonymous objects so that we can combine datasets. I probably don’t notice anything obvious, but I can’t figure out how to correctly check the result information in order to verify it.
WebApi Snippet
var orderInfo = new { Customer = customerInfo, Order = orderInfo } return Ok(orderInfo);
Api test snippet
[TestMethod] public void TestGetOrderInfo() { var controller = new OrderController(_repo); IHttpActionResult results = controller.GetOrderInfo(46); Assert.IsNotNull(results); }
How to check results using OkNegotiatedContentResult when an anonymous type is used?
c # anonymous-types asp.net-web-api
scarpacci
source share