public void Should_Not_Try_To_Set_Value_On_Broken_Chain() { var data = new Class1 { Foo = new Class2 { Bar = "bar" } }; var target = new ExpressionObserver(data, "Foo.Bar"); // Ensure the ExpressionObserver's subscriptions are kept active. target.OfType<string>().Subscribe(x => { }); data.Foo = null; Assert.False(target.SetValue("foo")); }
public void Exception_Validation_Sends_DataValidationError() { var data = new ExceptionTest { MustBePositive = 5 }; var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true); var validationMessageFound = false; observer.OfType<BindingNotification>() .Where(x => x.ErrorType == BindingErrorType.DataValidationError) .Subscribe(_ => validationMessageFound = true); observer.SetValue(-5); Assert.True(validationMessageFound); }
public void Exception_Validation_Sends_DataValidationError() { var data = new ExceptionTest { MustBePositive = 5 }; var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true); var validationMessageFound = false; observer.OfType <BindingNotification>() .Where(x => x.ErrorType == BindingErrorType.DataValidationError) .Subscribe(_ => validationMessageFound = true); observer.SetValue(-5); Assert.True(validationMessageFound); }
public void Should_Not_Try_To_Set_Value_On_Broken_Chain() { var data = new Class1 { Foo = new Class2 { Bar = "bar" } }; var target = new ExpressionObserver(data, "Foo.Bar"); // Ensure the ExpressionObserver's subscriptions are kept active. target.OfType <string>().Subscribe(x => { }); data.Foo = null; Assert.False(target.SetValue("foo")); }
public void Doesnt_Send_DataValidationError_When_DataValidatation_Not_Enabled() { var data = new ExceptionTest { MustBePositive = 5 }; var observer = new ExpressionObserver(data, nameof(data.MustBePositive), false); var validationMessageFound = false; observer.OfType <BindingNotification>() .Where(x => x.ErrorType == BindingErrorType.DataValidationError) .Subscribe(_ => validationMessageFound = true); observer.SetValue(-5); Assert.False(validationMessageFound); GC.KeepAlive(data); }