title: Unit testing that events are raised in C# (in order)
body: <p>I have some code that raises <code>PropertyChanged</code> events and I would like to be able to unit test that the events are being raised correctly.</p>
  
  <p>The code that is raising the events is like</p>
  
  <pre><code>public class MyClass : INotifyPropertyChanged
  {
     public event PropertyChangedEventHandler PropertyChanged;  
  
     protected void NotifyPropertyChanged(String info)
     {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(info));
          }
     }  
  
     public string MyProperty
     {
         set
         {
             if (_myProperty != value)
             {
                 _myProperty = value;
                 NotifyPropertyChanged("MyProperty");
             }
         }
     }
  }
  </code></pre>
  
  <p>I get a nice green test from the following code in my unit tests, that uses delegates:</p>
  
  <pre><code>[TestMethod]
  public void Test_ThatMyEventIsRaised()
  {
      string actual = null;
      MyClass myClass = new MyClass();
  
      myClass.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
      {
           actual = e.PropertyName;
      };
  
      myClass.MyProperty = "testing";
      Assert.IsNotNull(actual);
      Assert.AreEqual("MyProperty", actual);
  }
  </code></pre>
  
  <p>However, if I then try and chain the setting of properties together like so:</p>
  
  <pre><code>public string MyProperty
  {
      set
      {
          if (_myProperty != value)
          {
              _myProperty = value;
              NotifyPropertyChanged("MyProperty");
              MyOtherProperty = "SomeValue";
          }
      }
  }
  
  public string MyOtherProperty
  {
      set
      {
          if (_myOtherProperty != value)
          {
              _myOtherProperty = value;
              NotifyPropertyChanged("MyOtherProperty");
          }
      }
  }
  </code></pre>
  
  <p>My test for the event fails - the event that it captures is the event for the MyOtherProperty.</p>
  
  <p>I'm pretty sure the event fires, my UI reacts like it does, but my delegate only captures the last event to fire.</p>
  
  <p>So I'm wondering:<br>
  1. Is my method of testing events correct?<br>
  2. Is my method of raising <em>chained</em> events correct?  </p>