开发者

Json test returned data in LINQ form

public JsonResult GetPayments()
        {
            var paymentTypes = PaymentRepository.GetAll();

            var jsonData = new { rows = paymentTypes.Select(q => new { Id = q.Id.ToString(), q.Name }).ToList() };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
 开发者_Go百科       }

It basically returns the Id and Name of the Payments as Json data.

I was wanting to test this so I was wanting to test that each row of data generated had the right information in it.

However the JsonResult returned I can do:

JsonResult.Data

I can't seem to get to the individual rows. Any suggestions?


I asked a similar question a few months ago.

As the accepted answer states, i ended up using a simple reflection-based test helper to check the properties.

The alternative (answered after i accepted the original answer) is to make the internals of the web project visible to your tests project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜