public void Validate_ErrorsShouldContainsErrorMessages_WhenValidationIsNotValid() { var v = new ReactiveValidatableObject <string>(); v.Validations.Add(new ActionValidationRule <string>(arg => { return(false); }, "You have entered an invalid email")); Assert.Equal(0, v.Errors.Count); v.Validate(); v.Errors.CollectionChanged += (sender, e) => { Assert.Equal(1, v.Errors.Count); Assert.True(v.Errors.Contains("You have entered an invalid email")); }; }
public void Validate_IsValidShouldBeTrue_WhenValidEmailIsGiven() { var v = new ReactiveValidatableObject <string>(); v.Validations.Add(new IsNotNullOrEmptyRule <string>("Email must not be empty")); v.Validations.Add(new EmailRule <string>() { ValidationMessage = "You have entered an invalid email" }); Assert.True(v.IsValid); v.Value = "*****@*****.**"; v.Validate(); Assert.True(v.IsValid); }
public void Validate_ShouldSetIsValid_WhenExecuted() { var v = new ReactiveValidatableObject <string>(); v.Validations.Add(new IsNotNullOrEmptyRule <string>("Email must not be empty")); v.Validations.Add(new EmailRule <string>() { ValidationMessage = "You have entered an invalid email" }); Assert.True(v.IsValid); v.Validate(); v.Errors.CollectionChanged += (sender, e) => { Assert.False(v.IsValid); Assert.Equal(2, v.Errors.Count); Assert.Equal("Email must not be empty", v.Errors[0]); }; }