0
私は(Rhynoモックで)非同期サービスの動作をモックしようとします。Rhynoモックで非同期サービスの動作をモックできません
ここに例があります:void GetServerState()というメソッドを持つサービスがあります。このメソッドは非同期であるため、無効ですが、呼び出されると、プロキシを呼び出し、イベント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();
}
(ウィッヒがInfactはスタブですが、気にしない)モックを見てみましょう、誰もが今も;-)
を私に従っ願っています。この時点で、 、このコードはまったく動作しません。誰かがそれがうまくいかない理由について説明を始めていますか?
THX、