2010-07-14 2 views
0

다음은 코드입니다. GetParentPath는 보통대로 호출됩니다!첫 번째 몰 테스트 - 리디렉션이 발생하지 않습니다.

[TestMethod] 
    [HostType("Moles")] 
    public void GetParentPath_slashOnEnd_returns() 
    { 
     var sapi = new MPhotobucketApi(); 
     sapi.GetParentPathString = s => s; 

     var api = new PhotobucketApi(); 
     var parentPath = api.GetParentPath("hello/world/"); 

     Assert.AreEqual(parentPath, "hello"); 
    } 
+0

을 테스트 통과를합니까 당신은 '미래'PhotobucketApi의 인스턴스가있는 PhotobucketApi의 생성자를 가로 챌 필요 차단 ? 무슨 일이 일어나기를 기대하고 있니? –

+0

GetParentPath에 대한 호출은 's => s'대리자로 리디렉션되어야합니다. –

답변

1

테스트 작성 방법에 따라 리디렉션은 sapi에 임베드 된 런타임 인스턴스에만 적용됩니다.

MPhotobucketApi.Contructor = (me) => { 
    new MPhotobucketApi { GetParentPathString = s => s }; 
}; 
... 

다른 aproach이 수행하여 모든 예를 들어 GetParentPath을 리디렉션하는 것입니다 :

MPhotobucketApi.AllInstances.GetParentPathString = (me, s) => s; 
... 
+0

답장을 보내 주셔서 감사합니다. 'AllInstances'스 니펫은 원래 코드 대신 작동했지만 'Constructor'스 니펫은 아무런 효과가 없습니다. 내가 당황한 것은 17 페이지의 코드입니다. http://research.microsoft.com/en-us/projects/pex/molestutorial.docx. 마치 원래 코드와 같습니다. –

+0

Aarg 내 나쁜, 나를 Moles 생성자에 전달하는 걸 잊었. 새 MPhotobucketApi (나) {GetParentPathString = s => s}; – Peli