0
나는 (Rhino 모의로) 비동기 서비스의 행동을 모의하려고합니다.Rhyno 모의로 비동기 서비스 동작을 조롱 할 수 없습니다.
다음은 하나의 예입니다. void GetServerState()라는 메서드 하나가있는 서비스가 있습니다. 이 메서드는 비동기식이므로 void이지만 호출 될 때 프록시를 호출하고 GetServerStateCompleted (object, eventargs) 이벤트를 호출합니다. 나는 모든 사람들이 여전히 나를 따라 희망이 시점에서 ;-)
이지금, 모의 살펴보기로하자 (느릅 나무가 가리키고 그루터기,하지만 결코 마음을) 다 같이
public class MyStub
{
protected MockRepository MockRepository {get;set;}
public IMyService MyService {get;set;} //the service with GetServerState() Method
protected delegate void DelegateVoid(); //for easy writting
public MyStub()
{
MockRepository = new MockRepository();
MyService = MockRepository.Stub<IMyService >();
//And now, let's try to mock the behaviour
MyService.Stub(sm => sm.GetServerState())
.IgnoreArguments()
.Do((DelegateVoid)GetServerStateCompletedBehaviour);
}
//the method that should be launched when someone call GetServerState on the Stub
protected void GetServerStateCompletedBehaviour()
{
MyService.Raise(x=>x.GetServerStateCompleted+=null,MyService,new EventArgs());
}
}
//And here is how I would like to use it
[TestMethod]
void Test()
{
try
{
IMyService Stub = new MyStub().MyService;
Stub += new EventHandler(EventMethod);
Stub.GetServerState();
Assert.Fail();
}
catch(MyException){}
}
void EventMethod(Object sender, EventArgs e)
{
Throw new MyException();
}
나를 위해 잘 보인다 ,이 코드는 전혀 작동하지 않습니다. 누군가가 왜 효과가 없어야하는지에 대한 설명이 시작 되었습니까?
들으,