public void AsyncValidationTest() { var a1 = new A { name = "a1" }; var validator = new AsyncValidator(); var vEngine = new ValidationEngine { RulesProvider = new SimpleValidationRulesProvider <ValidationResult> { validator } }; EnqueueConditional(() => vEngine.EntitiesInError.Count() != 0); vEngine.Validate(new List <Entity> { a1 }); EnqueueCallback( () => { Assert.IsTrue(vEngine.EntitiesInError.Single() == a1); Assert.IsTrue(a1.ValidationErrors.Count == 1); }); Assert.IsFalse(a1.ValidationErrors.Count == 1); EnqueueTestComplete(); }
public void PermutationsThreeParameterNamesValidatorTest2() { var a1 = new A { name = "a1" }; var a2 = new A { name = "a2" }; var a3 = new A { name = "a3" }; var validator = new ValidationEngine { RulesProvider = new SimpleValidationRulesProvider <ValidationResult> { new PermutationsThreeParameterNamesValidator() } }; validator.Validate(new List <Entity> { a1, a2, a3 }); Assert.IsTrue(a1.ValidationErrors.Count == 6); Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a1a2a3")); Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a1a3a2")); Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a2a1a3")); Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a2a3a1")); Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a3a1a2")); Assert.IsTrue(a1.ValidationErrors.Any(e => e.ErrorMessage == "a3a2a1")); Assert.IsTrue(a2.ValidationErrors.Count == 6); Assert.IsTrue(a3.ValidationErrors.Count == 6); }
public void AValidatorTest2() { AValidator.TestResult = ValidationResult.Success; b.name = "hello"; var validator = new ValidationEngine { RulesProvider = new MEFValidationRulesProvider <ValidationResult>() }; validator.Validate(b, "name", new List <Entity> { a, b, c, d }); Assert.IsFalse(AValidator.TestResult == ValidationResult.Success); c.name = b.name; validator.Validate(c, "name", new List <Entity> { a, b, c, d }); Assert.IsTrue(AValidator.TestResult == ValidationResult.Success); }
public IList <IValidationRule> BrokenEntryRules(IDictionary <string, object> variables) { if (EntryRules != null && variables != null) { var engine = new ValidationEngine(EntryRules, variables); engine.Validate(); return(engine.BrokenRules); } return(new List <IValidationRule>()); }
public void ValidationEngine_Validate_Inactive_ShouldFail() { ValidationRule <Customer> rule1 = new ValidationRule <Customer>(x => x != null, "Item cannot be null"); ValidationRule <Customer> rule2 = new ValidationRule <Customer>(x => x.IsActive, "IsActive needs to be true"); ValidationEngine <Customer> engine = new ValidationEngine <Customer>(rule1, rule2); ValidationResult runResult = engine.Validate(new Customer()); Assert.IsTrue(!runResult.IsValid); Assert.IsTrue(runResult.Messages.Count() == 1); Assert.IsTrue(runResult.Messages.ElementAt(0) == "IsActive needs to be true"); }
public void SingleEntityValidation1() { var validator = new ValidationEngine { RulesProvider = new SimpleValidationRulesProvider <ValidationResult> { new AValidator() } }; AValidator.TestResult = ValidationResult.Success; validator.Validate(a, "name"); Assert.IsTrue(AValidator.TestResult == ValidationResult.Success); }
public void SingleEntityValidation2() { var a = new A(); var validator = new ValidationEngine { RulesProvider = new SimpleValidationRulesProvider <ValidationResult> { new PermutationsOneParameterValidator() } }; AValidator.TestResult = ValidationResult.Success; validator.Validate(a, "name"); Assert.IsTrue(a.ValidationErrors.Count() == 1); }
public void RegisterTest() { var validator = new ValidationEngine { RulesProvider = new MEFValidationRulesProvider <ValidationResult>() }; RegisterUnregisterValidation.visited = false; validator.Validate(a, "B", new List <Entity> { a }); Assert.IsTrue(RegisterUnregisterValidation.visited); }
public void ValidationEngine_ValidData_ShouldPass() { ValidationRule <Customer> rule1 = new ValidationRule <Customer>(x => x != null, "Item cannot be null"); ValidationRule <Customer> rule2 = new ValidationRule <Customer>(x => x.IsActive, "IsActive needs to be true"); ValidationEngine <Customer> engine = new ValidationEngine <Customer>(rule1, rule2); ValidationResult runResult = engine.Validate(new Customer { IsActive = true }); Assert.IsTrue(runResult.IsValid); Assert.IsTrue(!runResult.Messages.Any()); }
public void SignatureMatchTest() { var a = new A(); a.B = new B(); var validator = new ValidationEngine { RulesProvider = new SimpleValidationRulesProvider <ValidationResult> { new SignatureValidator() } }; validator.Validate(a, "name"); Assert.IsFalse(a.HasValidationErrors); }
static void Main(string[] args) { var engine = new ValidationEngine(); Users users = new Users { UserID = "fulano[at]site.com", UserName = "******", UserCountry = "Supercalifragilisticexpialidocious" }; engine.Validate(users); foreach (var prop in engine.Error) foreach (var msg in prop.Value) Console.WriteLine(string.Format("{0} {1}", prop.Key.Name, msg)); Console.ReadKey(); }
public void PermutationsThreeParameterNamesValidatorTest1() { var a1 = new A { name = "a1" }; var a2 = new A { name = "a2" }; var validator = new ValidationEngine { RulesProvider = new SimpleValidationRulesProvider <ValidationResult> { new PermutationsThreeParameterNamesValidator() } }; validator.Validate(new List <Entity> { a1, a2 }); Assert.IsTrue(a1.ValidationErrors.Count == 0); Assert.IsTrue(a2.ValidationErrors.Count == 0); }
private void InitializeHelper() { //Whenever the Value changes, validate this entity //DistinctUntilChanged to prevent StackOverflow on continuous validation Observable2.FromPropertyChangedPattern(this, x => x.LocationId).DistinctUntilChanged().ObserveOnDispatcher() .Subscribe(_ => { this.ValidationErrors.Clear(); var validator = new ValidationEngine { RulesProvider = new MEFValidationRulesProvider<ValidationResult>() }; validator.Validate(this); }); Observable2.FromPropertyChangedPattern(this, x => x.Value).DistinctUntilChanged().ObserveOnDispatcher() .Subscribe(_ => { //When a LocationField's value is set automatically set the parent Service's if (Value != null && Value.Client != null && OwnerServiceTemplate != null && OwnerServiceTemplate.OwnerService != null) { OwnerServiceTemplate.OwnerService.Client = Value.Client; } }); }
static void Main(string[] args) { var engine = new ValidationEngine(); Users users = new Users { UserID = "fulano[at]site.com", UserName = "******", UserCountry = "Supercalifragilisticexpialidocious" }; engine.Validate(users); foreach (var prop in engine.Error) { foreach (var msg in prop.Value) { Console.WriteLine(string.Format("{0} {1}", prop.Key.Name, msg)); } } Console.ReadKey(); }
public void ContinueValidation(ValidationContext context) { ValidationEngine.Validate(ValidationElementState.LinkedElement, context, this); }
private void OnValidate(ValidationContext context) { ValidationEngine.Validate(ValidationElementState.FirstElement, context, this); }
public void TestEngineInstance() { engine.Validate(this); }
public SchemaValidationResult Validate(Package package, TrustSchemaValidationOptions options = TrustSchemaValidationOptions.Full) { var engine = new ValidationEngine(_packageBinary, _derivationServiceFactory, _merkleStrategyFactory, _hashAlgorithmFactory, options, _validatorFactory); return(engine.Validate(package)); }
public void ValidateWithNullInputTest() { // Act var result = _classUnderTest.Validate(null); // Assert result.IsValid.Should().BeFalse(); result.ValidationError.Should().Be("model should not be null."); }