public void AbstractMementoViewModel_When_Validate_and_Validation_is_suspended_Validated_event_should_not_be_raised() { Boolean raised = false; var sut = new SampleTestViewModel(); var svc = new DataAnnotationValidationService <SampleTestViewModel>(sut); sut.ValidateUsing(svc, forceIsValidationEnabledTo: true); sut.Validated += (s, e) => raised = true; using (svc.SuspendValidation()) //so that we can change a property without triggering the validation process { sut.Validate(); } Assert.IsFalse(raised); }
public void AbstractViewModel_When_ValidateProperty_and_Validation_is_suspended_Validated_event_should_not_be_raised() { Boolean raised = false; var propName = "NotNullNotEmpty"; var sut = new SampleTestViewModel(); var svc = new DataAnnotationValidationService <SampleTestViewModel>(sut); sut.ValidateUsing(svc, forceIsValidationEnabledTo: true); sut.Validated += (s, e) => raised = true; using (svc.SuspendValidation()) //so that we can change a property without triggering the validation process { sut.Test_ValidateProperty(propName, ValidationBehavior.TriggerValidationErrorsOnFailure); } Assert.IsFalse(raised); }
public void AbstractViewModel_When_ValidateProperty_with_Trigger_berhavior_PropertyChanged_event_should_be_raised_if_the_status_of_errors_changes() { List <String> raised = new List <string>(); var propName = "NotNullNotEmpty"; var sut = new SampleTestViewModel(); var svc = new DataAnnotationValidationService <SampleTestViewModel>(sut); sut.ValidateUsing(svc, forceIsValidationEnabledTo: true); sut.PropertyChanged += (s, e) => raised.Add(e.PropertyName); sut.Test_ValidateProperty(propName, ValidationBehavior.TriggerValidationErrorsOnFailure); using (svc.SuspendValidation()) //so that we can change a property without triggering the validation process { sut.NotNullNotEmpty = "qwertyqwerty"; //this raises 1 PropertyChanged } sut.Test_ValidateProperty(propName, ValidationBehavior.TriggerValidationErrorsOnFailure); Assert.AreEqual(3, raised.Count(p => p == propName)); }