.net - Is there a way to unit test an async method? -
I am using NETMAT and NMK on the NAT platform. I am testing a presentation model where a method is asynchronous, the method creates an async function and executes it so that the system arrives immediately and the situation I see is not yet ready.
I can set a flag on the finish without modifying the SU but it would mean that I
Itemprop = "text">
Does your object end an asynchronous method of any kind of sign, such as an event? If this is the case, then you can use the following approach:
[test] Public Zero CanTestAsync () {MyObject Example = New MyObject () AutoResetEvent waitHandle = new AutoResetEvent (false); // Create and append event handlers for "End" Event EventHandler eventHandler = delegate (Object Sender, EventArgs E) {waitHandle.Set (); // Signal that the event that ended was raised} Example Asynciminated + = EventHandler; Call the // async method example. CallAsyncMethod (); // Wait until the event handler is applied (wait! Handle.WaitOne (5000, wrong)) {Assert.Fail ("Test Time Out."); } Example.AsyncMethodFinished - = eventHandler; Confirm. Arqueol ("Expected", Example ValueToCheck); }
Comments
Post a Comment