In the event of a successful AJAX call I want to return a simple object with Success = true
public ActionResult Foo(int id)
{
// ...
return Json(new {Success=true});
}
This works fine and the object my javascript receives looks like
{ Success : true }
but because the object returned is an anonymous type, I can't do (something like) the following in my test:
var result = (JsonResult)controller.AddNote(id, message);
dynamic data = result.Data;
// Assert
Assert.That(data.Success, Is.EqualTo(true));
So I tried returning an ExpandoObject which allows the test to work in the way I want but the the JSON sent back in the AJAX response is a mess, as detailed in this question.
[{"Key":"Success","Value":true}]
Is there a simple, clean way to achieve what seems like it should be easy, or is the only way to implement some custom serialization as in the linked question?