Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / General Discussion / Re: Unit Tests for my pureMVC proxies with asyncronous data. on: September 16, 2008, 12:03:47
...When my service proxies are instantiated they fire off a remote method to fill the data property of the proxy with an array of data from the server....

You can try this to get data from the server in your unit test:

         var timer:Timer = new Timer(1);
         
         //because the remote call will be asynchronous, then test it here
         var testSuccess:Function = function(evt:*= null):void {
            //for info on facade catching events
            //http://forums.puremvc.org/index.php?topic=276.0
            if (facade.wasReceived(AuthenticationProxy.LOGIN_SUCCESSFUL)) {
               trace("testing async stuff");
               timer.stop();
            }
            else {
               //test will loop until server return data
               timer.addEventListener(TimerEvent.TIMER, addAsync(testSuccess, 10000));
            }
            
         }
      
         
         timer.addEventListener(TimerEvent.TIMER, addAsync(testSuccess, 10000));         
         timer.start();
      

2  Announcements and General Discussion / General Discussion / Re: Testing practices for Pure MVC on: September 16, 2008, 07:39:06
... Really sending a perviously stored notification just requires doing a super.SendNotificaiton call...
Thanks for the idea, here is a simple example of notjones concept:
--Facade--

      public var incommingNotificationAray:ArrayCollection = new ArrayCollection();
      public var sentNotificationArray:ArrayCollection = new ArrayCollection();
      
      override public  function sendNotification(notificationName:String, body:Object = null, type:String = null):void
      {
         var aNotification:Notification = new Notification(notificationName, body, type);
         incommingNotificationAray.addItem(aNotification);
      }
      
      
      public function sendNote(notification:Notification):void {         
         incommingNotificationAray.removeItemAt(incommingNotificationAray.getItemIndex(notification));
         sentNotificationArray.addItem(notification);
         super.sendNotification(notification.getName(), notification.getBody(), notification.getType());
      }
      
      
      public function wasReceived(notificationName:String ):Notification {
         var i:int;
         var arr:Array = incommingNotificationAray.source;
         while(i < arr.length) {
              if(Notification(arr).getName()  == notificationName) {
                  return arr as Notification;
              }
              i++;
         }
         return null;
      }

--TestCase--
      public function testSaveHistory():void {
         var historyProxy:HistoryProxy = registerProxy();
         facade.sendNotification(ApplicationFacade.SAVE_USER_ACTION, new HistoryVO());
         var receivedNote:Notification = facade.wasReceived(ApplicationFacade.SAVE_USER_ACTION);
         if(receivedNote) {
            facade.sendNote(receivedNote);
         }         
         assertTrue("there is 1 item in the history list", historyProxy.historyArray.length == 1);
      }
3  Announcements and General Discussion / General Discussion / Re: Testing practices for Pure MVC on: September 15, 2008, 05:14:31
....Give this approach a try and see if it will work for you.

Thanks, it works. Cool!
Pages: [1]