/// <summary> /// Gets all validators associated with a property. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="property">The property.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators(IValidatorRunner validatorRunner, Type targetType, PropertyInfo property, RunWhen runWhen) { object[] builders = (object[])this.attrsPerProperty[property]; if (builders == null) { builders = property.GetCustomAttributes(typeof(IValidatorBuilder), true); this.attrsPerProperty[property] = builders; } ArrayList validators = new ArrayList(); foreach (IValidatorBuilder builder in builders) { IValidator validator = builder.Build(validatorRunner, targetType); if (!IsValidatorOnPhase(validator, runWhen)) { continue; } validator.Initialize(this, property); // Translate the error message of the validator. This way we can use the error message of a validator as resource key. string translatedErrorMessage = TranslateErrorMessage(validator.ErrorMessage); if (translatedErrorMessage != null) { validator.ErrorMessage = translatedErrorMessage; } validators.Add(validator); } return((IValidator[])validators.ToArray(typeof(IValidator))); }
public void TestQueueValidatorRunsCorrectly(ValidatorInstanceInfo info, IValidatorRunner validatorRunner, IScheduleCallback scheduleCallbacker, IValidationScheduler validatorScheduler, IValidatorProvider validatorProvider, IList <IValidatorInstance> validatorInstancesToReturn, IValidationResultHandler[] notificationHandler, IPublishEndpoint publishEndpoint) { var vs = new ValidationServer(validatorProvider, validatorRunner, validatorScheduler, scheduleCallbacker, publishEndpoint, notificationHandler); vs.QueueValidatorForExecution(info); }
public void TestQueueValidatorFailsWhenNullParameter(IValidatorRunner validatorRunner, IScheduleCallback scheduleCallbacker, IValidationScheduler validatorScheduler, IValidatorProvider validatorProvider, IList <IValidatorInstance> validatorInstancesToReturn, IValidationResultHandler[] notificationHandler, IPublishEndpoint publishEndpoint) { var vs = new ValidationServer(validatorProvider, validatorRunner, validatorScheduler, scheduleCallbacker, publishEndpoint, notificationHandler); Assert.ThrowsAny <Exception>(() => vs.QueueValidatorForExecution(null)); }
public SimpleValidatingModelBinder(IValidatorRunner runner) { if (runner == null) { throw new ArgumentNullException("runner"); } _runner = runner; }
public EmailSenderService(IValidatorRunner validatorRunner) { if (validatorRunner == null) { throw new ArgumentNullException("validatorRunner"); } _validatorRunner = validatorRunner; }
/// <summary> /// Constructs and configures an <see cref="IValidator"/> /// instance based on the properties set on the attribute instance. /// </summary> public override IValidator Build(IValidatorRunner validatorRunner, Type type) { IValidator validator = base.Build(validatorRunner, type); if (validator is IReferenceAccessAware) { ((IReferenceAccessAware)validator).ReferenceAccessor = referenceAccessor; } return(validator); }
public PRProcessor(ILogService logService, IVstsHelper vstsHelper, IValidatorRunner validatorRunner, IBasicJsonValidator basicJsonValidator, IARMValidator armValidator) { _logService = logService; _vstsHelper = vstsHelper; _validatorRunner = validatorRunner; _basicJsonValidator = basicJsonValidator; _armValidator = armValidator; }
/// <summary> /// Constructs and configures an <see cref="IValidator"/> /// instance based on the properties set on the attribute instance. /// </summary> public virtual IValidator Build(IValidatorRunner validatorRunner, Type type) { IValidator validator = Build(); if (validator is IPropertyAccessAware) { ((IPropertyAccessAware)validator).PropertyAccessor = propertyAccessor; } return(validator); }
/// <summary> /// Constructs and configures an <see cref="IValidator"/> /// instance based on the properties set on the attribute instance. /// </summary> public override IValidator Build(IValidatorRunner validatorRunner, Type type) { IValidator validator = base.Build(validatorRunner, type); if (validator is IReferenceAccessAware) { ((IReferenceAccessAware)validator).ReferenceAccessor = referenceAccessor; } return validator; }
public ValidationServer(IValidatorProvider validatorProvider, IValidatorRunner validatorRunner, IValidationScheduler validationScheduler, IScheduleCallback scheduleCallback, IPublishEndpoint publishEndpoint, IValidationResultHandler[] notificationHandlers) { this._publishEndpoint = Guard.NotNull(publishEndpoint, "publishEndpoint", log); this._validatorProvider = Guard.NotNull(validatorProvider, "validatorProvider", log); this._validatorRunner = Guard.NotNull(validatorRunner, "validatorRunner", log); this._validationScheduler = Guard.NotNull(validationScheduler, "validationScheduler", log); this._scheduleCallback = Guard.NotNull(scheduleCallback, "scheduleCallback", log); this._notificationHandlers = Guard.NotNull(notificationHandlers, "notificationHandlers", log); this._scheduleCallback.RunValidatorEvent += _scheduleCallback_RunValidatorEvent; this._validatorRunner.ValidatorResultsReady += _validatorRunner_ValidatorResultsReady; }
/// <summary> /// Constructs and configures an <see cref="IValidator"/> /// instance based on the properties set on the attribute instance. /// </summary> /// <param name="validatorRunner"></param> /// <param name="type"></param> /// <returns></returns> public override IValidator Build(IValidatorRunner validatorRunner, Type type) { GroupNotEmptyValidator validator = (GroupNotEmptyValidator) validatorRunner.ExtendedProperties[group]; if (validator == null) { validatorRunner.ExtendedProperties[group] = validator = new GroupNotEmptyValidator(group); } ConfigureValidatorMessage(validator); return validator; }
/// <summary> /// Constructs and configures an <see cref="IValidator"/> /// instance based on the properties set on the attribute instance. /// </summary> /// <param name="validatorRunner"></param> /// <param name="type"></param> /// <returns></returns> public override IValidator Build(IValidatorRunner validatorRunner, Type type) { GroupNotEmptyValidator validator = (GroupNotEmptyValidator) validatorRunner.ExtendedProperties[group]; if (validator == null) { validatorRunner.ExtendedProperties[group] = validator = new GroupNotEmptyValidator(group); } ConfigureValidatorMessage(validator); return(validator); }
/// <summary> /// Invoked before the interceptor proceeds with the method in /// </summary> /// <param name="invocation">The invocation.</param> protected override void PreProceed(IInvocation invocation) { MethodInfo method = invocation.Method; IValidatorRunner runner = CreateRunner(); bool isValid = runner.IsValid(invocation); if (!isValid) { ErrorSummary errors = runner.GetErrorSummary(invocation); OnInvalidMethod(method, errors); } }
/// <summary> /// Gets all validators associated with a property. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="property">The property.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators( IValidatorRunner validatorRunner, Type targetType, PropertyInfo property, RunWhen runWhen) { var builders = (object[])attrsPerProperty[property]; if (builders == null) { var metaDataTypeProperty = _metaDataType.GetProperty(property.Name); if (metaDataTypeProperty == null) { return((IValidator[])(new ArrayList()).ToArray(typeof(IValidator))); } builders = metaDataTypeProperty.GetCustomAttributes(typeof(IValidatorBuilder), true); // Attribute order cannot be guaranted in C# // this way we assure there order by Type Name Array.Sort(builders, new TypeNameComparer()); attrsPerProperty[property] = builders; foreach (IValidatorBuilder builder in builders) { builder.Initialize(this, property); } } var validators = new List <IValidator>(); foreach (IValidatorBuilder builder in builders) { IValidator validator = builder.Build(validatorRunner, targetType); if (!IsValidatorOnPhase(validator, runWhen)) { continue; } validator.Initialize(this, property); validators.Add(validator); } return(validators.ToArray()); }
/// <summary> /// Gets all validators associated with a <see cref="Type"/>. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators(IValidatorRunner validatorRunner, Type targetType, RunWhen runWhen) { PropertyInfo[] properties = (PropertyInfo[]) propertiesPerType[targetType]; if (properties == null) { propertiesPerType[targetType] = properties = ResolveProperties(targetType); } ArrayList list = new ArrayList(); foreach(PropertyInfo prop in properties) { list.AddRange(GetValidators(validatorRunner, targetType, prop, runWhen)); } return (IValidator[]) list.ToArray(typeof(IValidator)); }
/// <summary> /// Gets all validators associated with a <see cref="Type"/>. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators(IValidatorRunner validatorRunner, Type targetType, RunWhen runWhen) { PropertyInfo[] properties = (PropertyInfo[])propertiesPerType[targetType]; if (properties == null) { propertiesPerType[targetType] = properties = ResolveProperties(targetType); } var list = new List <IValidator>(); foreach (PropertyInfo prop in properties) { list.AddRange(GetValidators(validatorRunner, targetType, prop, runWhen)); } return(list.ToArray()); }
/// <summary> /// Gets all validators associated with a <see cref="Type"/>. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators(IValidatorRunner validatorRunner, Type targetType, RunWhen runWhen) { PropertyInfo[] properties = (PropertyInfo[])propertiesPerType[targetType]; if (properties == null) { this.propertiesPerType[targetType] = properties = ResolveProperties(targetType); } ArrayList list = new ArrayList(); foreach (PropertyInfo prop in properties) { list.AddRange(GetValidators(validatorRunner, targetType, prop, runWhen)); } return((IValidator[])list.ToArray(typeof(IValidator))); }
/// <summary> /// Gets all validators associated with a <see cref="Type"/>. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators(IValidatorRunner validatorRunner, Type targetType, RunWhen runWhen) { _metaDataType = ((MetadataTypeAttribute)targetType.GetCustomAttributes(typeof(MetadataTypeAttribute), false)[0]).MetadataClassType; var properties = (PropertyInfo[]) propertiesPerType[targetType]; if (properties == null) { propertiesPerType[targetType] = properties = ResolveProperties(targetType); } var list = new List<IValidator>(); foreach (PropertyInfo prop in properties) { list.AddRange(GetValidators(validatorRunner, targetType, prop, runWhen)); } return list.ToArray(); }
/// <summary> /// Gets all validators associated with a <see cref="Type"/>. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators(IValidatorRunner validatorRunner, Type targetType, RunWhen runWhen) { _metaDataType = ((MetadataTypeAttribute)targetType.GetCustomAttributes(typeof(MetadataTypeAttribute), false)[0]).MetadataClassType; var properties = (PropertyInfo[])propertiesPerType[targetType]; if (properties == null) { propertiesPerType[targetType] = properties = ResolveProperties(targetType); } var list = new List <IValidator>(); foreach (PropertyInfo prop in properties) { list.AddRange(GetValidators(validatorRunner, targetType, prop, runWhen)); } return(list.ToArray()); }
/// <summary> /// Constructs and configures an <see cref="IValidator"/> /// instance based on the properties set on the attribute instance. /// </summary> public virtual IValidator Build(IValidatorRunner validatorRunner, Type type) { IValidator validator = Build(); if (validator is IPropertyAccessAware) { ((IPropertyAccessAware)validator).PropertyAccessor = propertyAccessor; } return validator; }
public void ValidationServerInitWithNullParametersThrow(IValidatorProvider validatorProvider, IValidatorRunner validatorRunner, IValidationScheduler validationScheduler, IScheduleCallback scheduleCallbacker, IValidationResultHandler[] notificationHandler, IPublishEndpoint publishEndpoint) { Assert.ThrowsAny <Exception>( () => { ValidationServer vs = new ValidationServer(null, validatorRunner, validationScheduler, scheduleCallbacker, publishEndpoint, notificationHandler); }); Assert.ThrowsAny <Exception>( () => { ValidationServer vs = new ValidationServer(validatorProvider, null, validationScheduler, scheduleCallbacker, publishEndpoint, notificationHandler); }); Assert.ThrowsAny <Exception>( () => { ValidationServer vs = new ValidationServer(validatorProvider, validatorRunner, null, scheduleCallbacker, publishEndpoint, notificationHandler); }); Assert.ThrowsAny <Exception>( () => { ValidationServer vs = new ValidationServer(validatorProvider, validatorRunner, validationScheduler, null, publishEndpoint, notificationHandler); }); Assert.ThrowsAny <Exception>( () => { ValidationServer vs = new ValidationServer(validatorProvider, validatorRunner, validationScheduler, scheduleCallbacker, null, notificationHandler); }); Assert.ThrowsAny <Exception>( () => { ValidationServer vs = new ValidationServer(validatorProvider, validatorRunner, validationScheduler, scheduleCallbacker, publishEndpoint, null); }); }
public EntityValidator(IValidatorRunner validatorRunner) { _validatorRunner = validatorRunner; }
public void ValidationServerInitWithNonNullParametersSucceeds(TestValidatorProvider validatorProvider, IValidatorRunner validatorRunner, IValidationScheduler validationScheduler, IScheduleCallback scheduleCallbacker, IValidationResultHandler[] notificationHandler, IPublishEndpoint publishEndpoint) { Assert.NotNull(new ValidationServer(validatorProvider, validatorRunner, validationScheduler, scheduleCallbacker, publishEndpoint, notificationHandler)); }
public void AddScheduleToValidationServerVerificationWorks(IValidatorRunner validatorRunner, IScheduleCallback scheduleCallbacker, IValidationScheduler validatorScheduler, IValidatorProvider validatorProvider, IList <IValidatorInstance> validatorInstancesToReturn, string unknownInstanceId, string includedAndNotScheduledValidatorIdInstanceId, string includedAndScheduledValidatorIdInstanceId, string includedAndScheduledValidatorId, string includedAndNotScheduledValidatorId, string unknownProxyId, IList <IValidatorProxy> validatorProxiesToReturn, IValidationResultHandler[] notificationHandler, IPublishEndpoint publishEndpoint) { var includedProxy = Substitute.For <IValidatorProxy>(); var includedInstance = Substitute.For <IValidatorInstance>(); includedProxy.ValidatorId.ReturnsForAnyArgs(includedAndNotScheduledValidatorId); includedInstance.ValidatorInstanceId.ReturnsForAnyArgs(includedAndNotScheduledValidatorIdInstanceId); var includedAndScheduledProxy = Substitute.For <IValidatorProxy>(); var includedAndScheduledInstance = Substitute.For <IValidatorInstance>(); includedAndScheduledProxy.ValidatorId.ReturnsForAnyArgs(includedAndScheduledValidatorId); includedAndScheduledInstance.ValidatorInstanceId.ReturnsForAnyArgs(includedAndScheduledValidatorIdInstanceId); validatorProvider.GetValidatorProxy(includedProxy.ValidatorId).Returns(includedProxy); validatorProvider.GetValidatorProxy(includedAndScheduledProxy.ValidatorId).Returns(includedAndScheduledProxy); validatorProvider.GetValidatorInstance(includedAndScheduledValidatorId, includedAndScheduledValidatorIdInstanceId).Returns(includedAndScheduledInstance); validatorProvider.GetValidatorInstance(includedAndNotScheduledValidatorId, includedAndNotScheduledValidatorIdInstanceId).Returns(includedInstance); validatorScheduler.IsValidationScheduled(includedAndNotScheduledValidatorId, includedAndNotScheduledValidatorIdInstanceId).Returns(false); validatorScheduler.IsValidationScheduled(includedAndScheduledValidatorId, includedAndScheduledValidatorIdInstanceId).Returns(true); validatorProvider.When(x => x.GetValidatorProxy(Arg.Is <string>(d => d != includedAndNotScheduledValidatorId && d != includedAndScheduledValidatorId))).Do(g => { throw new Exception(); }); validatorProvider.When(x => x.GetValidatorInstance(Arg.Any <string>(), Arg.Is <string>(d => d != includedAndNotScheduledValidatorIdInstanceId && d != includedAndScheduledValidatorIdInstanceId))).Do(g => { throw new Exception(); }); var vs = new ValidationServer(validatorProvider, validatorRunner, validatorScheduler, scheduleCallbacker, publishEndpoint, notificationHandler); ScheduleRequest validRequest = new ScheduleRequest(includedProxy.ValidatorId, includedInstance.ValidatorInstanceId, "* * * * *"); ScheduleRequest requestWithInValidInstance = new ScheduleRequest(includedProxy.ValidatorId, unknownInstanceId, "* * * * *"); ScheduleRequest requestWithInValidProxy = new ScheduleRequest(unknownProxyId, unknownInstanceId, "* * * * *"); ScheduleRequest alreadyScheduledRequest = new ScheduleRequest(includedAndScheduledValidatorId, includedAndScheduledValidatorIdInstanceId, "* * * * *"); //This do not throw - Pass Verification vs.AddValidationsToSchedule(new List <ScheduleRequest>() { validRequest }); //This throw cause proxy is not available Assert.ThrowsAny <Exception>(() => vs.AddValidationsToSchedule(new List <ScheduleRequest>() { requestWithInValidInstance })); //This throws cause instance is not available Assert.ThrowsAny <Exception>(() => vs.AddValidationsToSchedule(new List <ScheduleRequest>() { requestWithInValidInstance })); //This throws cause item is already scheduled is not available Assert.ThrowsAny <Exception>(() => vs.AddValidationsToSchedule(new List <ScheduleRequest>() { alreadyScheduledRequest })); }
public ValidateModelAttribute(Type viewModelType, IValidatorRunner validatorRunner) { _viewModelType = viewModelType; _validatorRunner = validatorRunner; }
/// <summary> /// Gets all validators associated with a property. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="property">The property.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators( IValidatorRunner validatorRunner, Type targetType, PropertyInfo property, RunWhen runWhen) { object[] builders = (object[]) attrsPerProperty[property]; if (builders == null) { builders = property.GetCustomAttributes(typeof(IValidatorBuilder), true); // Attribute order cannot be guaranted in C# // this way we assure there order by Type Name Array.Sort(builders, new TypeNameComparer()); attrsPerProperty[property] = builders; foreach(IValidatorBuilder builder in builders) { builder.Initialize(this, property); } } ArrayList validators = new ArrayList(); foreach(IValidatorBuilder builder in builders) { IValidator validator = builder.Build(validatorRunner, targetType); if (!IsValidatorOnPhase(validator, runWhen)) continue; validator.Initialize(this, property); validators.Add(validator); } return (IValidator[]) validators.ToArray(typeof(IValidator)); }
public AccountController(JsonResult jResult, IValidatorRunner validationRunner, Feedback feed) { _validationRunner = validationRunner; _feed = feed; _jResult = jResult; }
public CategoriasController(ICategoriaService service, IValidatorRunner validationRunner) { _service = service; _validationRunner = validationRunner; }
/// <summary> /// Gets all validators associated with a property. /// <para> /// The validators returned are initialized. /// </para> /// </summary> /// <param name="validatorRunner">The validator runner.</param> /// <param name="targetType">Target type.</param> /// <param name="property">The property.</param> /// <param name="runWhen">Restrict the set returned to the phase specified</param> /// <returns>A Validator array</returns> public IValidator[] GetValidators(IValidatorRunner validatorRunner, Type targetType, PropertyInfo property, RunWhen runWhen) { object[] builders = (object[])this.attrsPerProperty[property]; if (builders == null) { builders = property.GetCustomAttributes(typeof(IValidatorBuilder), true); this.attrsPerProperty[property] = builders; } ArrayList validators = new ArrayList(); foreach (IValidatorBuilder builder in builders) { IValidator validator = builder.Build(validatorRunner, targetType); if (!IsValidatorOnPhase(validator, runWhen)) continue; validator.Initialize(this, property); // Translate the error message of the validator. This way we can use the error message of a validator as resource key. string translatedErrorMessage = TranslateErrorMessage(validator.ErrorMessage); if (translatedErrorMessage != null) { validator.ErrorMessage = translatedErrorMessage; } validators.Add(validator); } return (IValidator[])validators.ToArray(typeof(IValidator)); }