Created
July 5, 2011 01:14
-
-
Save drewbourne/1064127 to your computer and use it in GitHub Desktop.
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.iorad.flexclient.command | |
{ | |
public class GetUserServiceTest | |
{ | |
[Rule] | |
public var mocks:MockolateRule = new MockolateRule(); | |
[Mock] | |
public var webService:WebService; | |
public var service:GetUserService; | |
public var dispatcher:IEventDispatcher; | |
public const SESSION_ID:String = "TestSessionID"; | |
public const RESULT_XML:XML = <user><id>123</id></user>; | |
public const FAULT_XML:XML = <error><code>404</code></error> | |
[Before] | |
public function setup():void | |
{ | |
service = new GetUserService(); | |
service.webService = webService; | |
service.dispatcher = new EventDispatcher(); | |
} | |
[Test] | |
public function getUser_shouldRequestUserFromWebServiceWithSessionID():void | |
{ | |
service.getUser(SESSION_ID); | |
assertThat(webService. received().method("getUser").args(SESSION_ID).once()); | |
} | |
[Test(async)] | |
public function onResult_shouldDispatchEventWithResult():void | |
{ | |
mock(webService).method("getUser").args(SESSION_ID).dispatches(new ResultEvent(ResultEvent.RESULT, false, false, RESULT_XML)); | |
service.getUser(SESSION_ID); | |
Async.handleEvent(this, dispatcher, WebServiceEvent.GET_USER_SERVICE_CALL_RESULT_EVENT, handleResult); | |
function handleResult(event:WebServiceEvent, unusedAsyncData:Object):void | |
{ | |
assertThat(event.webServiceCallResult, equalTo(RESULT_XML)); | |
} | |
} | |
[Test(async)] | |
public function onFault_shouldDispatchEventWithFault():void | |
{ | |
mock(webService).method("getUser").args(SESSION_ID).dispatches(new FaultEvent(FaultEvent.FAULT, false, false, new Fault(FAULT_XML))); | |
service.getUser(SESSION_ID); | |
Async.handleEvent(this, dispatcher, WebServiceEvent.GET_USER_SERVICE_CALL_FAULT_EVENT, handleFault); | |
function handleFault(event:WebServiceEvent, unusedAsyncData:Object):void | |
{ | |
assertThat(event.webServiceCallFault, instanceOf(Fault)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment