public void AbstractViewModel_When_merge_errors_changes_it_should_not_fail() { var sut = new SampleTestViewModel(); var svc = new DataAnnotationValidationService <SampleTestViewModel>(sut); sut.ValidateUsing(svc, forceIsValidationEnabledTo: true); sut.Validate(); svc.MergeValidationErrors = !svc.MergeValidationErrors; }
public void AbstractViewModel_as_INotifyDataErrorInfo_with_validation_service_invalid_property_not_validated_is_valid() { var sut = new SampleTestViewModel(); sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut)); var errors = sut.GetErrors("NotNullNotEmpty").OfType <Object>(); Assert.AreEqual(0, errors.Count()); }
public void AbstractViewModel_as_IDataErrorInfo_with_validation_service_invalid_property_not_validated_is_valid() { var sut = new SampleTestViewModel(); sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut)); var error = sut["NotNullNotEmpty"]; Assert.IsNull(error); }
public void AbstractViewModel_with_validation_service_should_generate_expected_errors() { var sut = new SampleTestViewModel(); sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut)); sut.Validate(); var errors = sut.ValidationErrors; Assert.IsTrue(errors.Count == 1); }
public void AbstractViewModel_it_should_be_possible_to_change_a_validatable_property_in_the_validated_event() { var sut = new SampleTestViewModel(); var svc = DataAnnotationValidationService.CreateFor(sut); sut.ValidateUsing(svc, forceIsValidationEnabledTo: true); sut.Validated += (s, e) => { sut.AnotherOne = "fail"; }; sut.NotNullNotEmpty = "a value"; }
public void AbstractViewModel_When_ValidateProperty_PropertyChanged_event_should_not_be_raised() { 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); Assert.IsFalse(raised.Contains(propName)); }
public void AbstractViewModel_When_ValidateProperty_with_Trigger_berhavior_ErrorsChanged_event_should_be_raised() { 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.ErrorsChanged += (s, e) => raised.Add(e.PropertyName); sut.Test_ValidateProperty(propName, ValidationBehavior.TriggerValidationErrorsOnFailure); Assert.IsTrue(raised.Contains(propName)); }
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_validation_is_reset_ErrorsChanged_should_be_raised() { bool raised = false; var sut = new SampleTestViewModel(); sut.ErrorsChanged += (s, e) => { raised = true; }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut), forceIsValidationEnabledTo: true); sut.ResetValidation(); Assert.IsTrue(raised); }
public void AbstractViewModel_when_validation_status_changes_Validated_should_be_raised() { bool raised = false; var sut = new SampleTestViewModel(); sut.Validated += (s, e) => { raised = true; }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut), forceIsValidationEnabledTo: true); sut.NotNullNotEmpty = ""; Assert.IsTrue(raised); }
public void AbstractViewModel_PropertyChanged_is_raised_IsValid_should_be_false() { Boolean isValid = true; var sut = new SampleTestViewModel(); sut.PropertyChanged += (s, e) => { isValid = sut.IsValid; }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut), forceIsValidationEnabledTo: true); sut.NotNullNotEmpty = ""; Assert.IsFalse(isValid); }
public void AbstractViewModel_PropertyChanged_is_raised_Error_indexer_should_contain_expected_errors() { String errors = null; var sut = new SampleTestViewModel(); sut.PropertyChanged += (s, e) => { errors = sut["NotNullNotEmpty"]; }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut), forceIsValidationEnabledTo: true); sut.NotNullNotEmpty = ""; Assert.IsFalse(String.IsNullOrWhiteSpace(errors)); }
public void AbstractViewModel_PropertyChanged_is_raised_GetErrors_should_contain_expected_errors() { IEnumerable <Object> errors = null; var sut = new SampleTestViewModel(); sut.PropertyChanged += (s, e) => { errors = sut.GetErrors("NotNullNotEmpty").OfType <Object>(); }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut)); sut.NotNullNotEmpty = ""; Assert.IsNotNull(errors); Assert.AreEqual(0, errors.Count()); }
public void AbstractMementoViewModel_it_should_be_possible_to_change_a_validatable_property_in_a_custom_validation_rule() { var sut = new SampleTestViewModel(); var svc = DataAnnotationValidationService.CreateFor(sut); svc.AddRule( property: () => sut.NotNullNotEmpty, error: ctx => "error", rule: ctx => { sut.AnotherOne = "fail"; return(true); }); sut.ValidateUsing(svc, forceIsValidationEnabledTo: true); sut.NotNullNotEmpty = "a value"; }
public void AbstractViewModel_PropertyChanged_is_raised_ValidationErrors_should_contain_expected_errors() { ObservableCollection <ValidationError> errors = null; var sut = new SampleTestViewModel(); sut.PropertyChanged += (s, e) => { errors = sut.ValidationErrors; }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut), forceIsValidationEnabledTo: true); sut.NotNullNotEmpty = ""; Assert.IsNotNull(errors); Assert.AreEqual(1, errors.Count); }
public void AbstractMementoViewModel_when_validation_status_changes_PropertyChanged_for_HasErrors_property_should_be_raised() { bool raised = false; var sut = new SampleTestViewModel(); sut.PropertyChanged += (s, e) => { if (e.PropertyName == "HasErrors") { raised = true; } }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut), forceIsValidationEnabledTo: true); sut.NotNullNotEmpty = ""; Assert.IsTrue(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)); }
public void AbstractViewModel_when_validating_entire_entity_PropertyChanged_for_IsValid_property_should_be_raised() { bool raised = false; var sut = new SampleTestViewModel(); sut.PropertyChanged += (s, e) => { if (e.PropertyName == "IsValid") { raised = true; } }; sut.ValidateUsing( new DataAnnotationValidationService <SampleTestViewModel>(sut), forceIsValidationEnabledTo: true); var isValid = sut.Validate(); Assert.IsFalse(isValid); Assert.IsTrue(raised); }