public void ContinueAfterShownControl() { ApplicationData applicationData = new ApplicationData(); applicationData.SetValue("Hide_trigger", "No", true); ValidationResults results = new ValidationResults(); this.validator.Validate(applicationData, results); Assert.AreEqual(false, results.IsValid); }
public void CurrentSubpageValidationFail() { ApplicationData data = new ApplicationData { { "User_name", string.Empty }, { "Staff_name", "ABC" } }; var subGroup = this.subpageControlList.FindRecursive<GroupControl>(x => x.Id == 1); var subControlList = new ControlList { subGroup }; var validator = new ApplicationValidator(subControlList, validatorList: this.validatorList); var results = validator.Validate(new Application(data)); Assert.IsFalse(results.IsValid); // Test other group data.SetValue("User_name", "ABC"); data.SetValue("Staff_name", string.Empty); subGroup = this.subpageControlList.FindRecursive<GroupControl>(x => x.Id == 2); subControlList = new ControlList { subGroup }; validator = new ApplicationValidator(subControlList, validatorList: this.validatorList); results = validator.Validate(new Application(data)); Assert.IsFalse(results.IsValid); }
/// <summary> /// Populates <paramref name="target"/> with values from <paramref name="response"/> as defined by <paramref name="map"/>. /// </summary> /// <param name="response">The response object from which to get values.</param> /// <param name="map">A field map definition.</param> /// <param name="target">The target object to populate with mapped key/values.</param> private void MapPropertyField(HttpWebResponse response, MappedField map, ApplicationData target) { PropertyInfo info = response.GetType().GetProperty(map.Source); object propertyValue = info.GetValue(response); target.SetValue(map.Target, propertyValue); }
/// <summary> /// Populates <paramref name="target"/> with values from <paramref name="source"/> and <paramref name="response"/> /// as defined by <paramref name="fieldMap"/>. It also returns a new <see cref="Newtonsoft.Json.Linq.JObject"/> with mapped values. /// </summary> /// <param name="source">The response body from which to get values.</param> /// <param name="response">The response object from which to get values.</param> /// <param name="fieldMap">A definition of field mappings.</param> /// <param name="target">The target object to populate with mapped key/values.</param> /// <returns>A new <see cref="Newtonsoft.Json.Linq.JObject"/> with mapped values.</returns> public JObject MapObject(JObject source, HttpWebResponse response, MappedFieldList fieldMap, ApplicationData target) { JObject outObject = new JObject(); IEnumerable<MappedField> validMappings = fieldMap.Where(m => !string.IsNullOrEmpty(m.Target) && !string.IsNullOrEmpty(m.Source)); foreach (MappedField map in validMappings) { switch (map.MapType) { case MapType.Content: JToken token = source.SelectToken(map.Source); if (token != null) { outObject.Add(map.Target, token); if (target != null) { if (token.Type == JTokenType.Array && token.First().Type == JTokenType.Object) { var repeater = new NestedDictionary[token.Children().Count()]; var i = 0; foreach (var row in token) { repeater[i] = new NestedDictionary(); foreach (JProperty fieldProp in row.OfType<JProperty>()) { object targetValue = fieldProp.Value.Type == JTokenType.Array ? fieldProp.Value.Values<string>().ToArray() as object : fieldProp.Value.ToString(); if (repeater[i].ContainsKey(fieldProp.Name)) { repeater[i][fieldProp.Name] = targetValue; } else { repeater[i].Add(fieldProp.Name, targetValue); } } i++; } target.SetValue(map.Target, repeater); } else { object targetValue = token.Type == JTokenType.Array ? token.Values<string>().ToArray() as object : token.Value<string>(); target.SetValue(map.Target, targetValue, true); } } } break; case MapType.Property: this.MapPropertyField(response, map, target); break; default: throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidMapType, map.MapType)); } } return outObject; }
/// <summary> /// Creates a new application, and populates it with data, returning the newly created application. /// </summary> /// <param name="sessionData">The session data.</param> /// <param name="parameters">The parameters to populate within application data.</param> /// <returns>The newly created application.</returns> public Application PrePopulateApplication(SessionData sessionData, NameValueCollection parameters) { string formId = parameters["formId"]; if (formId == null) { return null; } RetrieveApplicationResponse applicationResponse = this.CreateApplicationSecure(sessionData, formId, true); Application application = applicationResponse.Application; ProductDefinition product = applicationResponse.Product; if (!product.AllowPrepopulate) { return application; } ApplicationData updateFrom = new ApplicationData(); IEnumerable<ValueControl> prePopulateControls = product.FormDefinition.Pages.AllControls.FindAllRecursive<ValueControl>(x => x.AllowPrepopulate); foreach (ValueControl prePopulateControl in prePopulateControls) { if (parameters[prePopulateControl.Name] != null) { updateFrom.SetValue(prePopulateControl.Name, parameters[prePopulateControl.Name], true); } else if (prePopulateControl.ParentId != null) { RepeaterControl parent = product.FormDefinition.Pages.AllControls.FindRecursive<RepeaterControl>(x => x.Id == prePopulateControl.ParentId); if (parent == null) { continue; } Regex repeaterFormat = new Regex(string.Format(Constants.RepeaterRegexPattern, prePopulateControl.Name)); IEnumerable<string> parentParams = parameters.AllKeys.Where(x => repeaterFormat.IsMatch(x)); foreach (string parentParam in parentParams) { string parentPath = this.DetermineRepeaterPath(parentParam, repeaterFormat); if (parentPath != null) { updateFrom.SetValue(parentPath, parameters[parentParam], true); } } } } if (updateFrom.Count != 0) { application.ApplicationData = updateFrom; this.SaveApplication(sessionData, application); } return application; }