public void WhenNotifyingOnAnInstancePropertyThenAnEventIsFired()
    {
      var testObject = new TestNotificationObject();
      var changeTracker = new PropertyChangeTracker(testObject);

      testObject.InstanceProperty = "newValue";

      Assert.IsTrue(changeTracker.ChangedProperties.Contains("InstanceProperty"));
    }
    public void WhenValidationOnAnInstancePropertyWithEmptyError()
    {
      var testObject = new TestValidationObject();
      var changeTracker = new PropertyChangeTracker(testObject);

      testObject.InstanceProperty = null;

      Assert.IsTrue(changeTracker.ChangedProperties.Contains("InstanceProperty"));
      Assert.IsInstanceOfType(testObject, typeof(INotifyDataErrorInfo));

      var errorInfo = (INotifyDataErrorInfo)testObject;
      var list = errorInfo.GetErrors("InstanceProperty").Cast<string>().ToList();
      CollectionAssert.Contains(list, "The InstanceProperty field is required.");
    }
    public void WhenValidationOnMaxPropertyErrorThenNoError()
    {
      var testObject = new TestValidationObject();
      var changeTracker = new PropertyChangeTracker(testObject);

      testObject.MaxValue = 0;

      Assert.IsTrue(changeTracker.ChangedProperties.Contains("MaxValue"));
      Assert.IsInstanceOfType(testObject, typeof(INotifyDataErrorInfo));

      var errorInfo = (INotifyDataErrorInfo)testObject;
      var list = errorInfo.GetErrors("MaxValue").Cast<string>().ToList();
      CollectionAssert.Contains(list, "The field MaxValue must be between 1 and 10.");

      changeTracker.Reset();
      testObject.MaxValue = 2;

      Assert.IsTrue(changeTracker.ChangedProperties.Contains("MaxValue"));
      list = errorInfo.GetErrors("MaxValue").Cast<string>().ToList();
      Assert.AreEqual(0, list.Count);
    }
    public void WhenValidationOnAnInstancePropertyWithEmptyError()
    {
      var testObject = new TestValidationObject();
      var changeTracker = new PropertyChangeTracker(testObject);

      testObject.InstanceProperty = null;

      Assert.IsTrue(changeTracker.ChangedProperties.Contains("InstanceProperty"));      
      Assert.IsInstanceOfType(testObject, typeof(IDataErrorInfo));

      var errorInfo = (IDataErrorInfo)testObject;
      Assert.AreEqual("The InstanceProperty field is required.", errorInfo["InstanceProperty"]);
    }
    public void WhenValidationOnMaxPropertyErrorThenNoError()
    {
      var testObject = new TestValidationObject();
      var changeTracker = new PropertyChangeTracker(testObject);

      testObject.MaxValue = 0;

      Assert.IsTrue(changeTracker.ChangedProperties.Contains("MaxValue"));
      Assert.IsInstanceOfType(testObject, typeof(IDataErrorInfo));

      var errorInfo = (IDataErrorInfo)testObject;
      Assert.AreEqual("The field MaxValue must be between 1 and 10.", errorInfo["MaxValue"]);

      changeTracker.Reset();
      testObject.MaxValue = 2;

      Assert.IsTrue(changeTracker.ChangedProperties.Contains("MaxValue"));
      Assert.AreEqual(null, errorInfo["MaxValue"]);
    }