저는 Castle Windsor를 DI로 사용하고 데이터 계층에 액세스하고 구현하기 위해 저장소를 사용하고 있습니다. 레포에 모든 데이터 액세스 레이어를 구현 했으므로 API 컨트롤러에서 해당 메서드를 호출 할 차례입니다. 그래서 'getAllReportsByClient 메소드'와 'CreateReport'POST 메소드가 있습니다. 따라서 실제로 뷰와 AJAX 호출을 구현하지 않고 일부 메소드가 작동하는지 테스트하려면 'Create Report'메소드를 사용하여 샘플 데이터를 어떻게 삽입 할 수 있습니까?모델을 전달하여 HTTPPOST 요청을 테스트하는 가장 좋은 방법은 무엇입니까?
의 repo에서 방법은 다음과 같습니다 : 아래
public void CreateReport(TReportHeaderModel model)
{
using (var connection = new TReportEntitiesConnection())
{
connection.THeader.Add(new THeader()
{
ClientID=model.ClientID,
ID=model.ID,
THeaderTitle=model.THeaderTitle,
RowNumber=model.RowNumber
});
foreach (var d in model.TReports)
{
connection.TReport.Add(new TReport()
{
ID=d.ID,
TReportName=d.TReportName,
URL=d.URL,
RowNumber=d.RowNumber,
});
}
connection.SaveChanges();
}
throw new NotImplementedException();
}
입니다 HTTPPOST createReport 컨트롤러에 전화 :
[HttpPost]
public ActionResultModel CreateReport([FromBody] TReportHeaderModel model)
{
try
{
_tReportingService.CreateReport(model);
return new ActionResultModel() //return void, must not be followed by object expression
{
Success = true,
Message = "Report Successfully Created."
};
}
catch (Exception ex)
{
return new ActionResultModel()
{
Success = false,
Message = "Report not created.",
Obj=ex.Message
};
}
}