Can't get ASMock to Dipatch Events
I can't find my mistake, hope someone can help me out. I am trying to unit test my actionscript application using ASMock. I want to perform an a开发者_JS百科synchron test, but I don't get my mocked function to dispatch. this is what I did:
[Test(async,timeout="5000")]
public function testFailedIDResponse() : void {
var mockRepository : MockRepository = new MockRepository();
// Record
var oMock:ConnectionProcessor = ConnectionProcessor(mockRepository.createStub(ConnectionProcessor));
oMock.addEventListener("ConnectionProcessor.LOGICALERROR", Async.asyncHandler(this, onWrongID, 5000));
SetupResult.forCall(oMock.logigalErrorCode).returnValue("NOT_FOUND");
SetupResult.forEventDispatcher(oMock);
SetupResult.forCall(oMock.load()).dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));
mockRepository.replayAll();
oMock.load();
but the event never arrives at my onWrongID handler. where is my error? thanks a lot guys!
You need to move your call to addEventListener
until after replayAll
. As it stands, it's just recording your call to addEventListener
.
You just have to call the dispatchEvent-method from your mocked object.
e.g.
oMock.dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));
Then your class/method/... under test will be able to handle the event.
or if you expect the load method to be called in somewhere before you could work with
Expect.call(oMock.load()).dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));
hope that helped. br,
精彩评论