Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > Avalon

Creating Unit Test for Function which uses recursive dispatcher

Reply
 
Thread Tools Display Modes
Old 04-09-2008   #1
Mike D
Guest
 
Posts: n/a

Creating Unit Test for Function which uses recursive dispatcher

Hi,

I'm having difficulty creating a unit test - perhaps some of you more
experienced WPF guys out there can help out a bit. The method I'm testing
(let's call it fadeVolume) calls itself recursively with a Dispatcher 60
times, sleeping for 50 milliseconds on each iteration (this is for a volume
fade over the course of 3 seconds).

In my unit test file,

1) I invoke fadeVolume (a private method) by an accessor class which I have
created.

VolumeFade_Accessor = new VolumeFade_Accessor();
accessor.volumeFade(); // should take 3 seconds
performEvents(10000); // should wait while the previous statement iterates

2) performEvents does what the algorithm below shows. The wait time of 10
seconds is there just for the sake of giving my 3 second fade all the time it
needs to execute.

private void performEvents (int wait Time)
{
System.Threading.Thread.Sleep(waitTime);
DispatcherFrame frame = new DispatcherFrame();

Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new
DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}


So the problem lies here.... even though I'm waiting for 10 seconds after I
call volumeFade from my unit test file, my volumeFade method never iterates
60 times. Actually, it recursively calls itself just once, which seems very
slow to me, considering that there's only a 50 millisecond sleep for each
iteration.

I know this method works normally, as the program normally performs as
expected. It only goes wrong in this test case scenario. Can anyone give me
any advice about unit testing a function which calls a dispatcher
recursively?? Thanks for any help in advance.

Cheers,
Mike

--
Mike D
  Reply With Quote

Reply

Thread Tools
Display Modes









Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Vistax64.com 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48