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); }
private static void FindAndValidateArgument(IEnumerable <object> arugments) { if (arugments == null) { throw new ArgumentNullException("arugments"); } Type typeOfT = typeof(T); foreach (var obj in arugments) { if (typeOfT.IsInstanceOfType(obj)) { var validationResult = ValidationEngine.TryValidate((T)obj); if (validationResult != null) { if (!validationResult.Valid) { throw new ValidationException(validationResult); } } } } }
static void Main(string[] args) { ValidationEngine validationEngine = new ValidationEngine(new IValidationRule <object>[] { }); //PersonListProcessor processor = new PersonListProcessor(validationEngine); //processor.Process(new List<Person> //{ // new Person // { // FirstName = "John", // LastName = "Doe", // CNP = "123433443", // DateOfBirth = new DateTime(1980, 1, 20) // }, // new Person // { // FirstName = "Johnny", // LastName = "Deep", // CNP = "", // DateOfBirth = new DateTime(1976, 5, 20) // } //}); Console.ReadLine(); }
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 override void Process(FlowInstance flow, Runners.IRunFlows runner) { var engine = new ValidationEngine(ExitRules, Variables); _isValid = engine.IsValid; IsProcessed = true; }
protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults) { string elementNamePropertyValue = ValidationEngine.GetUniquePropertyValue(currentTarget, elementNameProperty); string projectPropertyValue = ValidationEngine.GetUniquePropertyValue(currentTarget, projectProperty); ModelElement element = currentTarget as ModelElement; IServiceProvider serviceProvider = element.Store as IServiceProvider; if (string.IsNullOrEmpty(projectPropertyValue)) { //The Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator is fired return; } try { IVsSolution vsSolution = GetService <IVsSolution, SVsSolution>(serviceProvider); using (HierarchyNode hNode = new HierarchyNode(vsSolution, projectPropertyValue)) { if (hNode == null) { validationResults.AddResult( new ValidationResult(string.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, elementNamePropertyValue), objectToValidate, key, String.Empty, this) ); } } } catch (Exception) { //Thrown if Project doesn't exist on solution validationResults.AddResult( new ValidationResult(string.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, elementNamePropertyValue), objectToValidate, key, String.Empty, this) ); } }
bool messageFilterBase(Proxies.Event.NotificationMessageHolderType message, TopicInfo topicInfo, string expectedPropertyOperation, string validationScript) { if (!string.IsNullOrEmpty(expectedPropertyOperation)) { if (!message.Message.HasAttribute(OnvifMessage.PROPERTYOPERATIONTYPE)) { return(false); } XmlAttribute propertyOperationType = message.Message.Attributes[OnvifMessage.PROPERTYOPERATIONTYPE]; if (expectedPropertyOperation != propertyOperationType.Value) { return(false); } } var logger = new StringBuilder(); string validationScriptPath = string.Format("TestTool.Tests.TestCases.TestSuites.QuickInstall.Scripts.{0}", validationScript); Assert(ValidationEngine.GetInstance().Validate(message, topicInfo, validationScriptPath, logger), logger.ToStringTrimNewLine(), "Validate received notification(s)"); return(true); }
public void ValidationEngineTests_TestMe() { var eng = new ValidationEngine(); var results = eng.TestMe(); Assert.IsFalse(string.IsNullOrEmpty(results)); Assert.AreEqual("TwitterSearchBackend.Engines.ValidationEngine", results); }
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 ValidationEngineTests_Success() { var eng = new ValidationEngine(); var results = eng.ValidateSearchText("norm"); Assert.IsTrue(results != null); Assert.IsTrue(results.IsValid); Assert.IsTrue(string.IsNullOrEmpty(results.Error)); }
public void ValidationEngineTests_HandleNull() { var eng = new ValidationEngine(); var results = eng.ValidateSearchText(null); Assert.IsTrue(results != null); Assert.IsFalse(results.IsValid); Assert.AreEqual(ErrorCodes.InvalidSearchParameter, results.Error); }
/// <summary> /// Does the validate. /// </summary> /// <param name="objectToValidate">The object to validate.</param> /// <param name="currentTarget">The current target.</param> /// <param name="key">The key.</param> /// <param name="validationResults">The validation results.</param> protected override void DoValidate(ModelBusReference objectToValidate, object currentTarget, string key, ValidationResults validationResults) { ModelElement currentElement = currentTarget as ModelElement; Debug.Assert(currentElement != null); string elementNamePropertyValue = ValidationEngine.GetUniquePropertyValue(currentTarget, elementNameProperty); if (!validationResults.IsValid) { return; } if (objectToValidate == null) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, Resources.ModelReferenceValidatorMessage, key, currentTarget.GetType().Name, elementNamePropertyValue), currentTarget, key, String.Empty, this)); return; } //Check if we need to refresh an updated DC reference. ModelElement element = ModelBusReferenceResolver.ResolveAndDispose(objectToValidate); if (element == null) { validationResults.AddResult( new ValidationResult( String.Format(CultureInfo.CurrentUICulture, Resources.CannotResolveReference, currentTarget.GetType().Name, elementNamePropertyValue, objectToValidate.GetDisplayName()), currentTarget, key, String.Empty, this)); return; } string referenceElementDisplayName = ValidationEngine.GetUniquePropertyValue(element, "Name"); if (!objectToValidate.ElementDisplayName.Equals(referenceElementDisplayName, StringComparison.CurrentCulture)) { using (Transaction tx = ((ModelElement)currentTarget).Store.TransactionManager.BeginTransaction("Update reference value")) { ModelBusReference refresh = new ModelBusReference( objectToValidate.ModelBus, objectToValidate.LogicalAdapterId, objectToValidate.ModelDisplayName, referenceElementDisplayName, objectToValidate.SerializedAdapterReference, objectToValidate.ReferenceContext); // refresh value PropertyInfo typeProp = currentTarget.GetType().GetProperty("Type"); typeProp.SetValue(currentTarget, null, null); //Set it null to force updating typeProp.SetValue(currentTarget, refresh, null); //Now set the final value tx.Commit(); } validationResults.AddResult(new ValidationResult( string.Format(CultureInfo.CurrentCulture, Resources.ModelBusRefrenceUpdate, elementNamePropertyValue, referenceElementDisplayName), currentTarget, key, Constants.LogWarningTag, this)); } }
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 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 AValidatorTest() { 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); }
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 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 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(); }
protected override void OnValidationEnded(ValidationContext context) { if (context != null) { if (context.Categories == ValidationCategories.Menu && context.CurrentViolations.Count == 0) { Logger.Write( string.Format(CultureInfo.CurrentCulture, Properties.Resources.ValidationEndedMessage, Logger.Messages[TraceEventType.Error], Logger.Messages[TraceEventType.Warning], Logger.Messages[TraceEventType.Information]), TraceEventType.Information); } Logger.ResumeRefresh(); ValidationEngine.Reset(); } status.Clear(); }
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); }
/// <summary> /// Checks if requests item is not null and if it has value validates by nested validator. /// </summary> /// <param name="instance"></param> /// <returns></returns> public override ValidationResult Validate(T instance) { var result = base.Validate(instance); var innerType = typeof(T).GetGenericArguments().First(); var validator = ValidationEngine.GetValidator(innerType); if (validator == null) { return(result); } var itemValidation = validator.Validate(instance.Item); if (itemValidation.IsValid) { return(result); } return(new ValidationResult((result.Errors ?? new List <ValidationFailure>()).Concat(itemValidation.Errors))); }
/// <summary> /// Validate a single item in the collection. /// </summary> /// <param name="objectToValidate"></param> /// <param name="currentTarget"></param> /// <param name="key"></param> /// <param name="validationResults"></param> /// <remarks> /// Implement this in order to validate individual collection elements. /// </remarks> protected override void DoValidateCollectionItem(T objectToValidate, object currentTarget, string key, ValidationResults validationResults) { string currentTargetName = GetObjectName(currentTarget); string uniquePropertyValue = ValidationEngine.GetUniquePropertyValue(objectToValidate, this.UniquePropertyName); if (String.IsNullOrEmpty(uniquePropertyValue)) { return; } if (nameCounter.Contains(uniquePropertyValue)) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, currentTargetName, this.UniquePropertyName), objectToValidate, key, String.Empty, this) ); } else { nameCounter.Add(uniquePropertyValue, true); } }
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; } }); }
private void button2_Click(object sender, EventArgs e) { //Run Validation CreateNeuralNetwork(); List <string> listOfInputattribute = new List <string>(); foreach (object attribute in checkedListBox1.CheckedItems) { listOfInputattribute.Add(attribute.ToString()); } float predictionThreshold = float.Parse(txtPredictionThreshold.Text); float positiveLevel = float.Parse(txtPostiveClassificationLevel.Text); float negativeLevel = float.Parse(txtNegativeClassificationLevel.Text); validationEngine = new ValidationEngine(1, ANN, listOfInputattribute, comboBox1.Text, predictionThreshold, positiveLevel, negativeLevel); validationEngine._ValidationDataTable = ValidationDataTable; validationEngine.Run(); lblMCC.Text = validationEngine.PerformanceEvaluation.MCC.ToString(); lblAcc.Text = validationEngine.PerformanceEvaluation.Accuracy.ToString(); lblSn.Text = validationEngine.PerformanceEvaluation.Sensitivity.ToString(); lblSp.Text = validationEngine.PerformanceEvaluation.Specificity.ToString(); }
bool messageFilterBase(Proxies.Event.NotificationMessageHolderType message, TopicInfo topicInfo, string expectedPropertyOperation, string validationScript, IEnumerable <AccessProfile> accessProfileList) { if (!string.IsNullOrEmpty(expectedPropertyOperation)) { if (!message.Message.HasAttribute(OnvifMessage.PROPERTYOPERATIONTYPE)) { return(true); } XmlAttribute propertyOperationType = message.Message.Attributes[OnvifMessage.PROPERTYOPERATIONTYPE]; if (expectedPropertyOperation != propertyOperationType.Value) { return(false); } } var variables = new Dictionary <string, string>(); variables.Add("accessProfileList", string.Format(@"{{{0}}}", string.Join(",", accessProfileList.Select(s => string.Format(@"""{0}"" : ""{1}""", s.token, s.Description))))); var logger = new StringBuilder(); string validationScriptPath = string.Format("TestTool.Tests.TestCases.TestSuites.AccessRules.Script.{0}", validationScript); Assert(ValidationEngine.GetInstance().Validate(message, topicInfo, validationScriptPath, logger, variables), logger.ToStringTrimNewLine(), "Validate received notification(s)"); return(true); }
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 TearDown() { engine = null; }
public void Setup() { engine = new ValidationEngine(); }