PureMVC /复杂如模拟

时间:2011-04-21 22:05:34

标签: flex mocking asmock

好的 - 我在这里有一个复杂的asMock设置;我有一个PureMVC异步命令试图调用另一个实现接口的类,以便为没有后端的开发设置一些asmocks。

import test.mix.common.business.MockInterbahnServiceFactory;

public class InitMockInterbahnServiceFactory extends AsyncCommand{
     public static var mockServiceFactory:MockInterbahnServiceFactory = new MockInterbahnServiceFactory();

    override public function execute(notification:INotification):void{
        var serviceResult:IEventDispatcher = mockServiceFactory.mockRepository.prepare([EchoBusinessObjects, SendBusinessObjects]);
        //serviceResult.addEventListener(Event.COMPLETE, onComplete);



    }

    private function onComplete(event:Event):void{
        mx.controls.Alert.show("COMPLETE!");
        var logMessage:String = "4  MOCK   SERVICE FACTORY MOCKED !!!!!";
        sendNotification( MixConstants.LOG_OUTPUT, logMessage );    
        //sendNotification(MixConstants.INTERBAHN_CONNECTED, mockServiceFactory);
    //  commandComplete() ;
    }
}

这实际上是在设置一个MockRepositoryFactory:

public class MockInterbahnServiceFactory implements ServiceFactory
{
    [Mock] public static var withMocks : Array = [
        SendBusinessObjects, EchoBusinessObjects
    ];

    //public static var mockRepository:MockRepository ;//= new MockRepository();
    public var mockSendBusinessObjects:SendBusinessObjects;
    public var mockEchoBusinessObjects:EchoBusinessObjects ;
    public var mockRepository:MockRepository;



    public function MockInterbahnServiceFactory(){
        mockRepository = new MockRepository();
        prepareMocks();
    }

    public function prepareMocks():void{
        var prepareDispatcher:IEventDispatcher = mockRepository.prepare([SendBusinessObjects, EchoBusinessObjects]);
        prepareDispatcher.addEventListener(Event.COMPLETE, setupMocks);
    }

    public function setupMocks(event:Event):void{
        mockSendBusinessObjects = SendBusinessObjects(mockRepository.create(SendBusinessObjects));
        mockEchoBusinessObjects = EchoBusinessObjects(mockRepository.create(EchoBusinessObjects));

        SetupResult.forCall(mockSendBusinessObjects.sendOrder(new Order())).returnValue('wee');

    }

    public function createSendBusinessObjectService():SendBusinessObjects{

        return mockSendBusinessObjects;
    }

    public function createEchoBusinessObjectService():EchoBusinessObjects{

        return mockEchoBusinessObjects;
    }

}

}

在某些时候,这个工厂将被传递并用于多个通信的发送/接收端点(真正的后端是scala)。

我收到了这个错误:

ArgumentError: returnValue must be assignable from :void
at asmock.framework.expectations::AbstractExpectation/set returnValue()[C:\Users\Richard\SVN\asmock\trunk\source\ASMock\src\asmock\framework\expectations\AbstractExpectation.as:107]
at asmock.framework::MethodOptions/returnValue()[C:\Users\Richard\SVN\asmock\trunk\source\ASMock\src\asmock\framework\MethodOptions.as:134]
at test.mix.common.business::MockInterbahnServiceFactory/setupMocks()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/trunk/src/test/mix/common/business/MockInterbahnServiceFactory.as:56]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at Function/org.floxy:ProxyRepository/org.floxy:IProxyRepository:prepare/org.floxy:swfLoadedHandler()[C:\transfer\IdeaProjects\as3-interbahn\floxy\main\as3\src\org\floxy\ProxyRepository.as:218]

我假设这是因为我正在使用的接口函数?

public interface SendBusinessObjects {
     function sendFirmExchangePermission(frp:FirmExchangePermission):void ; 
     function sendFirm(f:Firm):void ;
     function sendExchange(ex:Exchange):void ;
     function sendFXConversion(fx:FXConversion):void ;
     function sendInstrument(ins:Instrument):void ;
     function sendQuote(q:Quote):void ;

1 个答案:

答案 0 :(得分:1)

在我看来,SendBusinessObjects返回void,但是当你模拟对它的调用时,你正在调用returnValue。移除returnValue('wee')电话,它应该按预期工作。