Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight async unit testing
    primarykey
    data
    text
    <p>I'm having a weird issue with Silverlight Unit Test Framework. The very first method executed fails, every time. I have a second test with the exact same code, and it passes. The strange thing about the first time it's called is that it actually waits for the timeout <em>and then</em> executes the repository call (underneath it's an HTTP PUT if you care). Here's the code - the first one fails every time, second one passes every time:</p> <pre><code> [TestMethod] public void AuthShouldSucceed() { var autoResetEvent = new AutoResetEvent(false); _authRepository.Authenticate(_username, _password, response =&gt; { Assert.IsTrue(response); autoResetEvent.Set(); }); if (!autoResetEvent.WaitOne(Constants.Timeout)) { Assert.Fail("Test timed out."); } } [TestMethod] public void AuthShouldSucceed2() { var autoResetEvent = new AutoResetEvent(false); _authRepository.Authenticate(_username, _password, response =&gt; { Assert.IsTrue(response); autoResetEvent.Set(); }); if (!autoResetEvent.WaitOne(Constants.Timeout)) { Assert.Fail("Test timed out."); } } </code></pre> <p><strong>Edit:</strong> My final solution is a modification of Vladmir's solution:</p> <pre><code> [TestMethod] [Asynchronous] public void AuthShouldSucceed() { var complete = false; var result = false; _authRepository.Authenticate(_username, _password, response =&gt; { complete = true; result = response; }); EnqueueConditional(() =&gt; complete); EnqueueCallback(() =&gt; Assert.IsTrue(result)); EnqueueTestComplete(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload