1
단위 테스트를 처음 사용합니다. 내가 아주 간단한 것을 테스트하기 위해 노력하고 있습니다 :File.Delete가 Moq을 사용하여 호출되었습니다.
if (!String.Equals(user.ProfilePictureUrl, _defaultPic))
내가 System.IO.File.Delete
인지 확인하고 싶습니다 : 코드의이 섹션에서는
[HttpPost]
public ActionResult EditProfile(ProfileViewModel model)
{
if (ModelState.IsValid)
{
// Retrieve current user
var userId = User.Identity.GetUserId();
var user = _dataRepository.GetUserById(userId);
//If it isn't the single-instance default picture, delete the current profile
// picture from the Profile_Pictures folder
if (!String.Equals(user.ProfilePictureUrl, _defaultPic))
System.IO.File.Delete(Server.MapPath(user.ProfilePictureUrl));
를,이 라인이 참으로 평가하는 조건을 만드는 오전 라는.
가장 좋은 방법은 무엇입니까?
System.IO.File.Delete
호출을 랩핑하여 인터페이스를 구현하는 클래스를 랩핑하여 호출해야한다는 사실을 모의 할 수 있어야합니까?
저는 Moq를 사용하고 있습니다.
귀하의 마지막 문으로 확인 될 수 있도록 할 절대적으로 올바른 것입니다. 입출력 호출을 모방 할 수있는 추상화로 캡슐화합니다. – Nkosi
감사합니다 @ Nkosi! –
당신은 또한'Service.MapPath'에 대해서도 똑같이해야합니다. 이것들은 추상화 될 수있는 구현 문제입니다. 실제로 전체 문장을 하나의 추상화로 캡슐화 할 수 있습니다. – Nkosi