public void Validating(ValidatingContext context) { if (context.FormName != "EmailActivity") { return; } var recipients = context.ValueProvider.GetValue("Recipients").AttemptedValue; var subject = context.ValueProvider.GetValue("Subject").AttemptedValue; var body = context.ValueProvider.GetValue("Body").AttemptedValue; if (String.IsNullOrWhiteSpace(recipients)) { context.ModelState.AddModelError("Recipients", T("You must specify at least one recipient.").Text); } if (String.IsNullOrWhiteSpace(subject)) { context.ModelState.AddModelError("Subject", T("You must provide a Subject.").Text); } if (String.IsNullOrWhiteSpace(body)) { context.ModelState.AddModelError("Body", T("You must provide a Body.").Text); } }
public void Validating(ValidatingContext context) { if (context.FormName != "ActivityActionEmail") { return; } var recipientFormValue = context.ValueProvider.GetValue("Recipient"); var recipient = recipientFormValue != null ? recipientFormValue.AttemptedValue : String.Empty; if (recipient == String.Empty) { context.ModelState.AddModelError("Recipient", T("You must select at least one recipient").Text); } if (context.ValueProvider.GetValue("Subject").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Subject", T("You must provide a Subject").Text); } if (context.ValueProvider.GetValue("Body").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Body", T("You must provide a Body").Text); } if (context.ValueProvider.GetValue("RecipientOther").AttemptedValue == String.Empty && recipient == "other") { context.ModelState.AddModelError("RecipientOther", T("You must provide an e-mail address").Text); } }
public void Validating(ValidatingContext context) { if (context.FormName == "ActionEmail") { if (context.ValueProvider.GetValue("Recipient").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Recipient", T("You must select at least one recipient").Text); } if (context.ValueProvider.GetValue("Subject").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Subject", T("You must provide a Subject").Text); } if (context.ValueProvider.GetValue("Body").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Body", T("You must provide a Body").Text); } if (context.ValueProvider.GetValue("RecipientOther").AttemptedValue == String.Empty && context.ValueProvider.GetValue("Recipient").AttemptedValue == "other") { context.ModelState.AddModelError("Recipient", T("You must provide an e-mail address").Text); } } }
public Task Validate_ValidatingHandlerContext_Static_Run() { MyMessage message = new(); MyHandler handler = new(); return(Assert.ThrowsAsync <MessageValidationException>(() => ValidatingContext.Run(handler, message))); }
public override void Validating(ValidatingContext context) { return; //always valid; if (context.FormName == "TileNavLayout") { if (context.ValueProvider.GetValue("Alignment") == null) { context.ModelState.AddModelError("Alignment", T("The field Alignment is required.").Text); } if (context.ValueProvider.GetValue("Columns") == null) { context.ModelState.AddModelError("Columns", T("The field Columns/Lines is required.").Text); } else { int value; if (!Int32.TryParse(context.ValueProvider.GetValue("Columns").AttemptedValue, out value)) { context.ModelState.AddModelError("Columns", T("The field Columns/Lines must be a valid number.").Text); } } } }
void IFormEventHandler.Validating(ValidatingContext context) { if (context.FormName != "CreateUser") { return; } var userName = context.ValueProvider.GetValue("UserName").AttemptedValue; var email = context.ValueProvider.GetValue("Email").AttemptedValue; var password = context.ValueProvider.GetValue("Password").AttemptedValue; if (String.IsNullOrWhiteSpace(userName)) { context.ModelState.AddModelError("UserName", T("You must specify a username or a token that evaluates to a username.").Text); } if (String.IsNullOrWhiteSpace(email)) { context.ModelState.AddModelError("Email", T("You must specify an email address or a token that evaluates to an email address.").Text); } if (String.IsNullOrWhiteSpace(password)) { context.ModelState.AddModelError("Password", T("You must specify a password or a token that evaluates to a password.").Text); } }
public Task Validate_ValidatingHandlerContext() { MyMessage message = new(); var handlerContext = ValidatingContext.Build(message); MyHandler handler = new(); return(Assert.ThrowsAsync <MessageValidationException>(() => handlerContext.Run(handler))); }
public override void Validating(ValidatingContext context) { if (context.FormName == NumericFilterForm.FormName) { var isRange = new[] { "Between", "NotBetween" }.Contains(context.ValueProvider.GetValue("Operator").AttemptedValue); var min = context.ValueProvider.GetValue("Min"); var max = context.ValueProvider.GetValue("Max"); var value = context.ValueProvider.GetValue("Value"); // validating mandatory values if (isRange) { if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text); } if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text); } } else { if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text); } } if (!context.ModelState.IsValid) { return; } decimal output; if (isRange) { if (!Decimal.TryParse(min.AttemptedValue, out output) && !IsToken(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} should contain a valid number", T("Min").Text).Text); } if (!Decimal.TryParse(max.AttemptedValue, out output) && !IsToken(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} should contain a valid number", T("Max").Text).Text); } } else { if (!Decimal.TryParse(value.AttemptedValue, out output) && !IsToken(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} should contain a valid number", T("Value").Text).Text); } } } }
public async Task ThrowsForIncoming() { var message = new MyMessage(); var context = ValidatingContext.Build(message); var handler = new OtherHandler(); await context.Run(handler); Assert.IsType <OtherMessage>(context.SentMessages.Single().Message); }
public override void Validating(ValidatingContext context) { if (context.FormName == "EventRangeForm") { var min = context.ValueProvider.GetValue("DateFrom"); //validate... context.ModelState.AddModelError("DateFrom", "You did it wrong!"); } }
public async Task Should_throw_for_handle() { SimpleMessage message = new(); var handlerContext = ValidatingContext.Build(message); HandlerThatSends handler = new(); var exception = await Assert.ThrowsAsync <Exception>(() => handler.Handle(message, handlerContext)); await Verifier.Verify(exception.Message); }
public void Validating(ValidatingContext context) { if (context.FormName == "RazorExecuteForm") { if (context.ValueProvider.GetValue("RazorExecuteActivity_RazorView").AttemptedValue == string.Empty) { context.ModelState.AddModelError("RazorExecuteActivity_RazorView", T("You must provide a Razor View").Text); } } }
public void Validating(ValidatingContext context) { if (context.FormName == "ActivityActionDecision") { if (context.ValueProvider.GetValue("Script").AttemptedValue == string.Empty) { context.ModelState.AddModelError("Script", T("You must provide a Script").Text); } } }
public override void Validating(ValidatingContext context) { if (context.FormName == SortCriterionFormProvider.FormName) { if (context.ValueProvider.GetValue("Sort") == null) { context.ModelState.AddModelError("Sort", T("The Sort field is required.").Text); } } }
public override void Validating(ValidatingContext context) { if (context.FormName == "ListLayout") { if (context.ValueProvider.GetValue("Order") == null) { context.ModelState.AddModelError("Order", T("You must provide an Order").Text); } } }
public void Validating(ValidatingContext context) { if (context.FormName != ConfigurableSortCriterionProviderForm.FormName) { return; } if (string.IsNullOrWhiteSpace(context .ValueProvider.GetValue("CriterionIndex").AttemptedValue)) { context.ModelState .AddModelError("CriterionIndex", T("Insert a value for the Index (it is allowed to be a token).").Text); } try { var json = context .ValueProvider.GetValue("CriteriaArray").AttemptedValue; // remove double braces we are using because of tokens json = json.Replace("{{", "{").Replace("}}", "}"); var criteria = JsonConvert .DeserializeObject <SortCriterionConfiguration[]>(json); if (criteria == null || !criteria.Any()) { context.ModelState .AddModelError("CriteriaArray", T("The array of Criteria may not be null").Text); } for (int i = 0; i < criteria.Length; i++) { var forPart = criteria[i].IsForPart(); var forField = criteria[i].IsForField(); var forProvider = criteria[i].IsForProvider(); var boolCount = (forPart ? 1 : 0) + (forField ? 1 : 0) + (forProvider ? 1 : 0); // misconfigurations if (!criteria[i].IsForPart() && !criteria[i].IsForField() && !criteria[i].IsForProvider()) { context.ModelState .AddModelError("CriteriaArray", T("Criterion at index {0} is neither for a part or a field or a provider.", i.ToString()).Text); } else if (boolCount > 1) { context.ModelState .AddModelError("CriteriaArray", T("Criterion at index {0} is configured for more than a single option (part, field or provider).", i.ToString()).Text); } } } catch (Exception ex) { context.ModelState .AddModelError("CriteriaArray", T("Error while parsing the json array: {0}", ex.Message).Text); } }
public void Validating(ValidatingContext context) { if (context.FormName != "ActivityRangeForm") { return; } if (string.IsNullOrEmpty(context.ValueProvider.GetValue("DateFrom").AttemptedValue) && string.IsNullOrEmpty(context.ValueProvider.GetValue("DateTo").AttemptedValue)) { context.ModelState.AddModelError("ActivityRangeDateError", T("At least one date must be provided").Text); } }
public override void Validating(ValidatingContext context) { if (context.FormName == "ActivityTimer") { if (context.ValueProvider.GetValue("Amount").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Amount", T("You must provide an Amount").Text); } if (context.ValueProvider.GetValue("Unity").AttemptedValue == String.Empty) { context.ModelState.AddModelError("Unity", T("You must provide a Type").Text); } } }
public void Validating(ValidatingContext context) { if (context.FormName != HeaderValueForm.FormName) { return; } // name of header to test is required if (string.IsNullOrWhiteSpace(context .ValueProvider.GetValue("Name").AttemptedValue)) { context.ModelState .AddModelError("Name", T("Insert a value for the Name of the header to test (it is allowed to be a token).").Text); } }
public async Task Ensure_saga_data_is_added_to_context() { MyMessage message = new() { Content = "a" }; var handlerContext = ValidatingContext.Build(message); MySaga.MySagaData sagaData = new(); MySaga saga = new() { Data = sagaData }; await handlerContext.Run(saga); Assert.Equal(handlerContext.SagaData, sagaData); } }
public override void Validating(ValidatingContext context) { if (context.FormName == UserReactionsQueryFilterForm.FormName) { //UserReactions validation /////////////////////////////////////////////////////////// string reaction = context.ValueProvider.GetValue("Reaction").AttemptedValue.ToString().ToLower(); var userRT = new UserReactionsTypes(); userRT.UserReactionsType = _reactionsService.GetTypesTable().Select(r => new UserReactionsTypeVM { Id = r.Id, TypeName = r.TypeName, }).ToList(); int lenReaction = reaction.Length; var reactionsList = userRT.UserReactionsType; if ((reaction.Substring(0, 1) != "{" && reaction.Substring(lenReaction - 1, 1) != "}") && (reactionsList.FirstOrDefault(x => x.TypeName == reaction) == null)) { context.ModelState.AddModelError("Reaction", T("The field {0} should contain a valid input.", T("Reactions").Text).Text); } if (!context.ModelState.IsValid) { return; } /////// var isRange = new[] { "Between", "NotBetween" }.Contains(context.ValueProvider.GetValue("Operator").AttemptedValue); var min = context.ValueProvider.GetValue("Min"); var max = context.ValueProvider.GetValue("Max"); var value = context.ValueProvider.GetValue("Value"); // validating mandatory values if (isRange) { if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text); } if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text); } } else { if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text); } } if (!context.ModelState.IsValid) { return; } decimal output; if (isRange) { if (!Decimal.TryParse(min.AttemptedValue, out output) && !IsToken(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} should contain a valid number", T("Min").Text).Text); } if (!Decimal.TryParse(max.AttemptedValue, out output) && !IsToken(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} should contain a valid number", T("Max").Text).Text); } } else { if (!Decimal.TryParse(value.AttemptedValue, out output) && !IsToken(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} should contain a valid number", T("Value").Text).Text); } } } }
public void Validated(ValidatingContext context) { }
public void Validating(ValidatingContext context) { if (context.FormName == "MailchimpAPICallForm") { } }
public override void Validating(ValidatingContext context) { if (context.FormName == DateTimeFilterForm.FormName) { var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(context.ValueProvider.GetValue("Operator").AttemptedValue)); if (op == DateTimeOperator.IsNull || op == DateTimeOperator.IsNotNull) { // no further validation needed } else { var isRange = new[] { DateTimeOperator.Between, DateTimeOperator.NotBetween }.Contains(op); var min = context.ValueProvider.GetValue("Min"); var max = context.ValueProvider.GetValue("Max"); var value = context.ValueProvider.GetValue("Value"); var valueType = context.ValueProvider.GetValue("ValueType"); // validating mandatory values if (isRange) { if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text); } if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text); } } else { if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text); } } if (!context.ModelState.IsValid) { return; } // validating data type if (valueType.AttemptedValue == "0") { // A date if (isRange) { if (!_dateRegEx.IsMatch(min.AttemptedValue) && !IsToken(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Min").Text).Text); } if (!_dateRegEx.IsMatch(max.AttemptedValue) && !IsToken(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Max").Text).Text); } } else { if (!_dateRegEx.IsMatch(value.AttemptedValue) && !IsToken(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Value").Text).Text); } } } else { // An offset int number; if (isRange) { if (!Int32.TryParse(min.AttemptedValue, out number) && !IsToken(min.AttemptedValue)) { context.ModelState.AddModelError("Min", T("The field {0} must be a valid number.", T("Min").Text).Text); } if (!Int32.TryParse(max.AttemptedValue, out number) && !IsToken(max.AttemptedValue)) { context.ModelState.AddModelError("Max", T("The field {0} must be a valid number.", T("Max").Text).Text); } } else { if (!Int32.TryParse(value.AttemptedValue, out number) && !IsToken(value.AttemptedValue)) { context.ModelState.AddModelError("Value", T("The field {0} must be a valid number.", T("Value").Text).Text); } } } } } }
void IFormEventHandler.Validated(ValidatingContext context) { }