0

The ValidationManager has a public Dictionary for storing UI components that implement the IValidatable interface.

I am testing a command class that needs an instance of ValidationManager and I want it to fail the validations. So I override the ValidationManager's "validateItem()" method like so:

var validationManagerRepos:ValidationManager = ValidationManager(mockRepository.createStub(ValidationManager));
var validationItem:IValidatable = IValidatable(mockRepository.createStub(IValidatable));

var validatableItems:Dictionary = new Dictionary();
validatableItems[validationItem] = false;

SetupResult.forCall(validationManagerRepos.validateItem(validationItem)).returnValue(false);

My problem is in the execute method of the command. It checks to see if the validationItem is both a DisplayObject (isVisble) and IValidatable. Any slick way to stub a typed object AND an interface? Or do I just need to create an instance of some existing object that already satisfies both?

for (var iVal:Object in validationManager.validatableItems)
            {
                if (isVisible(DisplayObject(iVal)))
                {
                    passed = validationManager.validateItem(IValidatable(iVal));
                    eventDispatcher.dispatchEvent(new ValidationEvent(ValidationEvent.VALIDATE_COMPLETED, IValidatable(iVal), passed));
                    if (!passed)
                    {
                        allPassed = false;
                    }
                }
            }
razlebe
  • 7,134
  • 6
  • 42
  • 57
Tony Smith
  • 869
  • 1
  • 11
  • 25

2 Answers2

1

I'm fairly sure you can't do both within asMock. It's a limitation of the Flash Player because of lack of polymorphism.

I believe what you'll have to do is create a testing object that does both (extend DisplayObject and implement IValidatable) and create a mock object of that.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
0

The concept of a "multimock" is certainly possible, but floxy (the framework that asmock uses to generate dynamic proxies) doesn't support it. I previously considered adding support for it, but it would be difficult to expose via the various Mock metadata and there's be other issues to worry about (like method name clashes).

I agree with J_A_X's recommendation of creating a custom class and then mocking that.

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237