0

다음과 같은 메소드에 대한 테스트 케이스를 생성했습니다. Action 결과 - json "Success"문자열을 반환합니다. 생성 된 스크립트를 수정하는 방법?작성 단위 작업 결과를 반환하는 메소드의 테스트 케이스

public ActionResult LoginClick(string username, string password) 
    { 
     LoginRepo loginrepo = new LoginRepo(); 
     BL bl = new BL(); 

     bool loginStatus = loginrepo.CheckLogin(username, password); 
     if (loginStatus) 
     { 
      bl.SetSessionVariable("Username", username); 
      return Json(new { Status = "Success" }, JsonRequestBehavior.AllowGet); 
     } 
     return Json(new { Status = "Failed" }, JsonRequestBehavior.AllowGet); 
    } 

다음은 생성 된 테스트 케이스입니다.

[TestMethod()] 
     [HostType("ASP.NET")] 
     [UrlToTest("http://localhost:1280")] 
     public void LoginClickTest() 
     { 
      LoginController target = new LoginController(); // TODO: Initialize to an appropriate value 
      string username = null; // TODO: Initialize to an appropriate value 
      string password = null; // TODO: Initialize to an appropriate value 
      ActionResult expected = null ; // TODO: Initialize to an appropriate value 
      ActionResult actual; 
      actual = target.LoginClick(username, password); 
      Assert.AreEqual(expected, actual); 
      Assert.Inconclusive("Verify the correctness of this test method."); 

     } 

성공적으로 실행하려면 어떻게 수정해야합니까? 액션 결과와 데이터가 json string으로 예상되는 것이기 때문에 실제 결과는 어떻게 작성해야합니까?

+0

이 되었습니까? – SBirthare

답변

0
How should i modify it so that it can run successfully? 

LoginRepo을 입력해야합니다. 예를 here

의 작업 결과 이후

데이터 내가 작성하는 방법을 은, 실제 결과를 예상한다 무엇을 JSON 문자열이? 주장되어보다 상세한 정보는?

당신은 너무 ActionResult에서 JsonResult를 얻기 위해 같은 주조 유형을 수행해야합니다 답변이 도움이

var viewResult = yourTargetController.LoginClickTest() as JsonResult; 
    Assert.AreEqual(false, viewResult.Data);