Created
April 30, 2012 13:57
-
-
Save nowri/2558547 to your computer and use it in GitHub Desktop.
PureMVCTestCase for PureMVC Multicore + FlexUnit4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////////////////// | |
// | |
// PureMVCTestCase for PureMVC Multicore + FlexUnit4 | |
// | |
// PureMVC multicore versionに対応かつ | |
// FlexUnit4に対応 | |
// | |
// @author http://nowri.in | |
// @update 30 Apr 2012 | |
// @see http://code.google.com/p/puremvc-flexunit-testing/ | |
// | |
//////////////////////////////////////////////////////////////////////////////// | |
//original copyrights | |
/* Copyright (c) 2008, andCulture Inc. | |
* All rights reserved. | |
* | |
* NOTICE: You are permitted to use, modify, and distribute this file | |
* in accordance with the terms of the BSD license agreement accompanying it. | |
*/ | |
package com.andculture.puremvcflexunittesting | |
{ | |
import org.flexunit.async.Async; | |
import org.puremvc.as3.multicore.patterns.observer.Observer; | |
import org.puremvc.as3.multicore.interfaces.INotification; | |
import org.puremvc.as3.multicore.interfaces.IView; | |
import flash.events.EventDispatcher; | |
public class PureMVCTestCase { | |
/** | |
* Constructor. | |
* | |
*/ | |
public function PureMVCTestCase() { | |
} | |
/** | |
* @param view View used to register an observer. | |
* @param notificationName Notification name to listen for. | |
* @param callback Callback function to fire when the notification is received. | |
* @param timeout Timeout in milliseconds addAsync() will wait for the | |
* notification until it's declared a failure. | |
*/ | |
public function registerObserver(view:IView, notificationName:String, callback:Function, timeout:int):void { | |
var hackyDispatcher:EventDispatcher = new EventDispatcher(); | |
Async.handleEvent(this, hackyDispatcher, notificationName, callback, timeout); | |
var handler:Function = function(notification:INotification):void { | |
hackyDispatcher.dispatchEvent(new PureMVCNotificationEvent(notification)); | |
}; | |
view.registerObserver(notificationName, new Observer(handler, this)); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------------------- | |
// | |
// FacebookAPI処理のためのModelクラス、FacebookProxyのテストケースサンプル | |
// | |
//-------------------------------------------------------------------------- | |
public class FacebookProxyTest extends PureMVCTestCase | |
{ | |
private static var facade : ApplicationFacade; | |
private static var appProxy : AppProxy; | |
[BeforeClass(description="proxy,commandの初期化")] | |
public static function setUp():void | |
{ | |
facade = ApplicationFacade.getInstance(ApplicationFacade.KEY); | |
appProxy = facade.retrieveProxy(AppProxy.NAME)as AppProxy; | |
} | |
[Before(async, description="Facebookログイン処理")] | |
public function login():void | |
{ | |
registerObserver(View.getInstance(ApplicationFacade.KEY), | |
ApplicationFacade.NOTE_FACEBOOK_RESPONCE, | |
loginComplete, | |
1000 | |
); | |
facade.sendNotification(ApplicationFacade.EXE_FACEBOOK, null, FacebookCommand.FACEBOOK_LOGIN); | |
} | |
private function loginComplete(e:PureMVCNotificationEvent, passThroughData:Object) : void | |
{ | |
// trace("loginComplete"); | |
} | |
[Test(order=1, async, description="FacebookIdをAPIにリクエストしてレスポンスを処理できるか")] | |
public function testRequestFriendList():void | |
{ | |
registerObserver(View.getInstance(ApplicationFacade.KEY), | |
ApplicationFacade.NOTE_RESPONSED_API, | |
responseFriendList, | |
10000 | |
); | |
facade.sendNotification(ApplicationFacade.EXE_API,null,APICommand.GET_FRIEND_RANKING_LIST); | |
} | |
private function responseFriendList(e:PureMVCNotificationEvent, passThroughData:Object) : void | |
{ | |
var note:INotification = e.notification; | |
Assert.assertEquals(ApplicationFacade.NOTE_RESPONSED_API, note.getName()); | |
Assert.assertEquals(APICommand.GET_FRIEND_RANKING_LIST, note.getType()); | |
Assert.assertTrue(appProxy.rankDataList[0] is UserDataVO); | |
} | |
[Test(order=2, description="queryAPIのレスポンスから作られたrankDataList、のVOが正しい値を持っているか")] | |
public function testFriendListVO():void | |
{ | |
var isMeNum:int=0; | |
for (var i : int = 0; i < appProxy.rankDataList.length; i++) | |
{ | |
var vo:UserDataVO = appProxy.rankDataList[i]; | |
if(vo.isMe) | |
{ | |
isMeNum++; | |
} | |
Assert.assertTrue(vo.name, vo.rank, vo.photoId); | |
} | |
Assert.assertEquals(1, isMeNum); | |
} | |
[After] | |
public function tearDown() : void | |
{ | |
facade.removeProxy(AppProxy.NAME); | |
facade.removeProxy(APIProxy.NAME); | |
facade.removeProxy(FacebookProxy.NAME); | |
facade.registerProxy(new AppProxy()); | |
facade.registerProxy(new APIProxy()); | |
facade.registerProxy(new FacebookProxy()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment