0
I’m trying to do unit testing in the following function (there are more ifs, but I believe this is enough to illustrate), using Nunit. The problem is that I am unable to treat the return of the Jsonresult type. When running the test, the result is
Message: Expected:
True
But was:<empty>
How can I get around that?
Function (is in a Controller):
[HttpPost]
public JsonResult ChangePassword(string password, string new_password, string confirm_password, string email)
{
//string email = Seguridad.Session.GetUserMail();
if (new_password != confirm_password)
return Json(new { success = false, message = "As senhas não coincidem" });
}
Testing:
[TestFixture]
public class CandidatoControllerTestChangePassword
{
[Test]
public void TestChangeValidPassword()
{
var controller = new CandidatoController();
var result = controller.ChangePassword("password", "newpassword", "newpassword", "[email protected]") as JsonResult;
var data = JsonConvert.SerializeObject(result.Data);
var deserializedData = JsonConvert.DeserializeObject<dynamic>(data);
Assert.AreEqual(true, deserializedData.success);
}
}
result. Date returns JSON with value?
– Barbetta
Only with this if you can not guarantee anything... you are passing two identical passwords, which in the presented code would not return anything...
– Leandro Angelo