Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpService mocking problem - and solution #47

Open
MurrayFurtado opened this issue Sep 14, 2011 · 0 comments
Open

HttpService mocking problem - and solution #47

MurrayFurtado opened this issue Sep 14, 2011 · 0 comments

Comments

@MurrayFurtado
Copy link

Drew,

I've just started using Mockolate, which seems to me to be the most fully featured Flex mocking framework out there, and I have been wrestling with getting a mock HttpService working.

Here's the consumer of the service:

public class LoadEmployeesDelegate 
{
    private var responder : IResponder;
    public var service : HTTPService;

    public function LoadEmployeesDelegate( responder : IResponder ) 
    {
        this.service = new HTTPService();
        this.service.url="assets/Employees.xml";
        this.responder = responder;
    }

    public function loadEmployeesService() : void 
    {
        var token:AsyncToken = service.send();
        token.addResponder( responder );
    }
}

The first approach I used was:

[Rule]
public var rule:MockolateRule = new MockolateRule();

[Mock]
public var httpService : HTTPService;

...
// no send parameters so set to null
// don't care about the fault details so set blank
mock(httpService).asHTTPService().send(null).fault("","","");

This didn't work because it failed to return an AsyncToken :(

I then tried the following which did work :)

var token:AsyncToken = new AsyncToken();
var faultEvent:FaultEvent = new FaultEvent(FaultEvent.FAULT, false, false, new Fault("", "", ""), token);
mock(httpService).method("send").returns(token).answers(new FaultAnswer(token, faultEvent));

My question is, why did the first example fail, and what is the purpose of the asHTTPService() method. Is there any way to refactor the failing example so that it returns the AsyncToken without the verbose setup of the second?

Many thanks,

Murray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant