0
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);
        }

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?

AnonyMouse
  • 18,108
  • 26
  • 79
  • 131

1 Answers1

0

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.

Community
  • 1
  • 1
RPM1984
  • 72,246
  • 58
  • 225
  • 350