저는 Pex와 Moles를 처음 사용합니다. 내 코드에서 Pex를 실행하려고하는데 Constructor injection을 사용하고있다. Pex에게 생성자 주입 방법을 지시하는 방법이 있습니까?Pex & Moles - Dependencey Injection
편집
public UserLogic(IUserRepository userRepository)
{
_userRepository = userRepository;
}
public int GetUsersAge(int id)
{
User user = _userRepository.GetById(id);
DateTime DOB = user.DOB;
DateTime now = DateTime.Today;
int age = now.Year - DOB.Year;
if (DOB > now.AddYears(-age)) age--;
return age;
}
나는 스텁 userRepository를 주입해야합니다. _userRepository.GetById (id)를 호출하면 Pex가 NullReferenceException으로 실패합니다. 나는 단위 테스트를 위해 Moq를 사용하고 있었지만 pex와 moles로 바꾸고 싶다.
내 스텁을 만들기 위해 PexFactories를 사용해야 할까?
쇼 몇 가지 코드, 당신은 두더지와 코드를 대체 할 수 있습니다. – Peter
이것은 완전히 사실이 아닙니다. Moles를 사용할 수없는 시나리오가 있습니다 (예 : http://social.msdn.microsoft.com/Forums/en-US/pex/thread/c262d8f1-246e-4157). -a7b4-f7ddeaf1890c /) – Gorgsenegger
한 가지 더 생각해 보면, 처음부터 응용 프로그램을 디자인 할 수있는 기회가 있다면 인터페이스를 적절하게 사용하는 한 일반적으로 MOQ를 사용하는 것이 좋습니다. 두더지는 더 이상 변경할 수 없거나 허용 할 수없는 기존 코드를 도울 수 있습니다. – Gorgsenegger