当我们执行这个测试时,会得到一个失败提示信息“期望的属性名‘FirstName’,但接收到的是’IsChanged’”。显然,设置FirstName的属性触发了“IsChanged”标记,我们需要把它考虑在内。因此我们把它加入:

[TestMethod]
public voidPerson_FirstName_Set_PropertyChanged()
{
      varperson =newPerson("Adam","Smith");
      vareventAssert =newGranite.Testing.PropertyChangedEventAssert(person);
      person.FirstName ="Bob";
      eventAssert.SkipEvent();//this was IsChanged
      eventAssert.Expect("FirstName");
}


  鉴于以上两个测试,我们考虑当FirstName被修改时还有其他什么属性会改变。查看API,IsChanged和FullName属性会变化。

  [TestMethod]

public voidPerson_FullName_Changed_By_Setting_FirstName()
{
      varperson =newPerson("Adam","Smith");
      person.FirstName ="Bob";
      Assert.AreEqual("Bob Smith", person.FullName);
}

[TestMethod]
public voidPerson_IsChanged_Changed_By_Setting_FirstName() {       varperson =newPerson("Adam","Smith");
      person.FirstName ="Bob";
      Assert.IsTrue(person.IsChanged);
}

  当然,如果这些属性改变了,我们需要获取到属性改变通知:

  [TestMethod]

public void Person_IsChanged_Property_Change_Notification_By_Setting_FirstName()
{
      var person = new Person("Adam", "Smith");
      var eventAssert = new PropertyChangedEventAssert(person);
      person.FirstName = "Bob";
      eventAssert.Expect("IsChanged");
}
[TestMethod]
public void Person_FullName_Property_Change_Notification_By_Setting_FirstName()
{
      var person = new Person("Adam", "Smith");
      var eventAssert = new PropertyChangedEventAssert(person);
      person.FirstName = "Bob";
      eventAssert.SkipEvent(); //this was IsChanged
      eventAssert.SkipEvent(); //this was FirstName
      eventAssert.Expect("FullName");
}
 


  接下来两个测试针对HasErrors这个属性和ErrorsChanged事件。

  [TestMethod]

public void Person_FirstName_Set_HasErrorsIsFalse()
{
          var person = new Person("Adam", "Smith");
          person.FirstName = "Bob";
          Assert.IsFalse(person.HasErrors);
}
[TestMethod]
public void Person_FirstName_Set_ErrorsChanged_Did_Not_Fire()
{
          var person = new Person("Adam", "Smith");
          var errorsChangedAssert = new ErrorsChangedEventAssert(person);
          person.FirstName = "Bob";
          errorsChangedAssert.ExpectNothing();
}