Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could try writing the test to be asynchronous. Consider this test method:</p> <pre><code>[TestMethod] [Asynchronous] public void TestMethod1() { TestViewModel testViewModel = new TestViewModel(); bool firstNameChanged = false; testViewModel.PropertyChanged += (s, e) =&gt; { if (e.PropertyName == "FirstName") { firstNameChanged = true; } }; EnqueueCallback(() =&gt; testViewModel.FirstName = "first name"); EnqueueConditional(() =&gt; firstNameChanged == true); EnqueueTestComplete(); } </code></pre> <p>Notice the Asynchronous attribute at the top of the method. There are two important methods here: EnqueueCallback and EnqueueTestComplete. EnqueueCallback will add lambda expressions to a queue and the test method will wait until the current callback is executed. In the case here, we subscribe to the PropertyChanged event on the ViewModel and we set a local boolean variable to true when the FirstName property notifies a change. We then Enqueue two callbacks: one to set the FirstName property and one to assert that the local boolean variable has changed value. Finally, we need to add a call to EnqueueTestComplete() so that the framework knows the test is over.</p> <p>NOTE: In order to get EnqueueCallback and EnqueueTestComplete, you need to inherit from SilverlightTest on your test class. You also need to import Microsoft.Silverlight.Testing to get the Asynchronous attribute. It should look something like this:</p> <pre><code>using Microsoft.Silverlight.Testing; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Foo.Example.Test { [TestClass] public class Tests : SilverlightTest { // ... tests go here } } </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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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