Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista Tutorial - Creating Unit Test for Function which uses recursive dispatcher

 
 
Old 04-09-2008   #1 (permalink)
Mike D
Guest


 
 

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

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Unit Test Software .NET General
How to unit test a Dataset? .NET General
separate long test from unit tests in vsts .NET General
About Creating ParameterSets for a function PowerShell


Vista Forums 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.
© Designer Media Ltd

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