Created
July 10, 2011 16:36
-
-
Save DarrenBishop/1074673 to your computer and use it in GitHub Desktop.
FlexUnit4 Testing with Parsley: Missing example files
This file contains 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
package com.darrenbishop.support.flexunit.async { | |
import flash.utils.setTimeout; | |
import mx.core.mx_internal; | |
import mx.rpc.AsyncResponder; | |
import mx.rpc.AsyncToken; | |
import mx.rpc.events.ResultEvent; | |
import mx.rpc.remoting.RemoteObject; | |
use namespace mx_internal; | |
public class AsyncUtils { | |
private static function resultHandler(event:ResultEvent, token:AsyncToken=null):void { | |
event.token.dispatchEvent(event); | |
} | |
private static function applyResult(token:AsyncToken, result:Object):void { | |
var event:ResultEvent = new ResultEvent(ResultEvent.RESULT, false, true, result, token); | |
token.mx_internal::applyResult(event); | |
} | |
public static function createToken(result:Object, timeout:Number=500):AsyncToken { | |
var token:AsyncToken = new AsyncToken(null); | |
setTimeout(applyResult, timeout, token, result); | |
token.addResponder(new AsyncResponder(resultHandler, null)); | |
return token; | |
} | |
} | |
} |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Object xmlns:mx="http://www.adobe.com/2006/mxml" | |
xmlns:application="com.darrenbishop.crm.directory.application.*"> | |
<!-- Application --> | |
<application:StubDirectoryService /> | |
<application:GetPersonCommand /> | |
</mx:Object> |
This file contains 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
package com.darrenbishop.crm.directory.application { | |
import com.darrenbishop.crm.directory.domain.Person; | |
import com.darrenbishop.support.flexunit.async.AsyncUtils; | |
import flash.utils.Dictionary; | |
import mx.rpc.AsyncToken; | |
public class StubDirectoryService implements DirectoryService { | |
private var people:Dictionary = new Dictionary(); | |
public var dodgyPerson:uint; | |
public var soundPerson:uint; | |
public function add(...newPeople):void { | |
for each (var person:Person in newPeople) { | |
if (people[person.id]) { | |
throw new Error('A person with id ' + person.id + ' already exists.'); | |
} | |
people[person.id] = person; | |
} | |
} | |
public function lookupById(id:uint):AsyncToken { | |
var token:AsyncToken = AsyncUtils.createToken(id == dodgyPerson ? people[soundPerson] : people[id]); | |
return token; | |
} | |
} | |
} |
This file contains 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
package com.darrenbishop.crm.directory.application { | |
import com.darrenbishop.crm.directory.domain.Person; | |
import flash.utils.Dictionary; | |
import mx.rpc.AsyncToken; | |
public class StubLookupTrackingDirectoryService implements DirectoryService { | |
private var people:Dictionary; | |
private var lookups:Array; | |
public function StubLookupTrackingDirectoryService() { | |
people = new Dictionary(); | |
resetLookups(); | |
} | |
public function resetLookups():void { | |
lookups = []; | |
} | |
public function add(person:Person):void { | |
if (people[person.id]) { | |
throw new Error('A person with id ' + person.id + ' already exists.'); | |
} | |
people[person.id] = person; | |
} | |
public function nextLookup():Person { | |
return lookups.shift(); | |
} | |
public function lookupById(id:uint):AsyncToken { | |
lookups.push(people[id]); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment