请告诉我如何通过不更改控制器操作来获取值。
Controller
[HttpPost]
public JsonResult A_Action_In_Controller(Guid ID)
{
var operationConfirmation = _repository.DoSomethingInDB(emailID);
return Json(new { operationConfirmation }, JsonRequestBehavior.AllowGet);
}
Test Method
[TestMethod]
public void DoSomethingInDB_SendOperationConfirmationToTheUI()
{...
var expected = "Successfully Completed";
var target = controller.A_Action_In_Controller(obj1.Id);
Assert.AreEqual(expected, target.Data);
}
错误
Assert.AreEqual failed. Expected:<Successfully Completed (System.String)>. Actual:<{ operationConfirmation = Successfully
已完成 } (<>f__AnonymousType2`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]])>。
请告诉我如何写类似的东西
Assert.AreEqual(expected, target.Data.operationConfirmation);
而不是我现在所拥有的,我不想更改我的控制器代码
Assert.AreEqual(expected, target.Data);