2013-05-02 1 views
0

내 단위 테스트에 RhinoMock을 사용하고 있는데 어떻게 설정해야하는지 알고 싶습니다. 특정 메소드가 항상 매개 변수로받은 것과 동일한 객체를 반환합니다. 내가 만들기 메서드를 호출 할 때마다의 조롱 스텁이로 전달 된 같은 객체를 반환하는 방식으로 RhinoMocks을 설정하려는RhinoMocks에 매개 변수로 전달 된 동일한 객체를 반환하도록 지정하는 방법

public interface IItemRepository 
{ 
    Item Craete(Item item); 
} 

:

내가 조롱하고자하는 인터페이스입니다 매개 변수.

[TestInitialize] 
public void CrateServiceWithMockRepository() 
{ 
    var stubRepository = MockRepository.GenerateStub<IItemRepository>(); 

    // ... how to set-up the stubRepository as described above ... 

    // Create the target service for this unit test 
    this.targetService = new ServiceXYZ(stubRepository); 
} 

답변

2

당신은 Do를 사용하고 메소드가 호출 될 때 실행하는 대리자를 전달할 수 있습니다 :

내 테스트 초기화 방법입니다

stubRepository.Stub(r => r.Create(null)).IgnoreArguments() 
    .Do(new Func<Item, Item>(item => item)); 
관련 문제