는 내가이 작업을 수행 할 수 있습니다 알고있는 스텁 방법에 대한 새로운 결과를 할당 할 재 :코뿔소 모의 객체 :
대신 IDateTimeFactory.Now가 속성 인 경우이 방법 IDateTimeFactory는 무엇IDateTimeFactory dtf = MockRepository.GenerateStub<IDateTimeFactory>();
dtf.Now = new DateTime();
DoStuff(dtf); // dtf.Now can be called arbitrary number of times, will always return the same value
dtf.Now = new DateTime()+new TimeSpan(0,1,0); // 1 minute later
DoStuff(dtf); //ditto from above
.GetNow(), 어떻게 같은 일을합니까? 유다의 제안 사항에 따라
다음과 같이 내 SetDateTime 도우미 방법을 다시 한 아래 :
private void SetDateTime(DateTime dt) {
Expect.Call(_now_factory.GetNow()).Repeat.Any();
LastCall.Do((Func<DateTime>)delegate() { return dt; });
}
을하지만 여전히 발생 "ICurrentDateTimeFactory.GetNow()의 결과는, 이미 설치되었습니다." 오류.
플러스는 여전히 당신은 이러한 목표를 달성하기 위해 Expect.Call을 사용할 수 있습니다
당신의 도움에 감사합니다 유다 –
그것이 당신을 위해 일해 주어 기쁘다! FWIW, 나는이 포스트에 관해 Ayende에게 이메일을 보냈다. 그는 내가하는 것보다 더 나은 대답을 할 수도 있습니다. –
George, Ayende는 이러한 해답을 보았습니다. 그는 우리가 Closure를 사용하고 Expect.Call (...) 대신 SetupResult.For를 사용할 수 있다고 말했다. Repeat.Any(). 그렇지 않으면 그는이 대답에 반대하지 않았습니다. –